BundleArgs


Source link: https://github.com/MFlisar/BundleArgs

BundleArgs

Let your IDE create your bundles/intents for you. This library is:

  • reflection free
  • typesafe
  • fast
  • very small - just the annotation interfaces are added to your akp (4 methods, 6 fields)
  • supports any class: Activities, Fragments and any other class => use one processor for all your needs
  • creates nice helper functions if appropriate

How to add it to your project - Gradle (via JitPack.io)

  1. add jitpack to your project's build.gradle:
repositories {

  maven {
 url "https://jitpack.io" 
}
 
}
  1. add the compile statement to your module's build.gradle and apply the apt plugin:
dependencies {

  compile 'com.github.MFlisar.BundleArgs:bundleargs-annotation:1.0'
  annotationProcessor 'com.github.MFlisar.BundleArgs:bundleargs-processor:1.0' 
}

Usage - Definitions

Here's a simple example that demonstrates the use in ANY class that needs a Bundle argument:

@BundleBuilder public class Test {

  @Arg
  Long id;
  @Arg
  String value;
  @Arg @Nullable
  String optionalValue;

 // define a constructor with Bundle args and the processor will create a build method that directly creates an object of this class
  public Test(Bundle args)
  {

TestBundleBuilder.inject(args, this);

  
}
 
}

And this is how you define it in an activity:

@BundleBuilder public class MyActivity extends Activity {
  @Arg  String stringArg;
@Override  public void onCreate(Bundle savedInstanceState)  {

super.onCreate(savedInstanceState);

MyActivityBundleBuilder.inject(getIntent().getExtras(), this);
  
}
 
}

Usage - Builder

  1. If you have defined the default costructor with a bundle as args in it, you can directly create a class like this:
Test test = new TestBundleBuilder()  .id(1L)  .value("Test")  .optionalValue("optionalValue")  .create();
  1. You can always just create a Bundle with the builder like following:
Bundle bundle = new TestBundleBuilder()  .id(1L)  .value("Test")  .optionalValue("optionalValue")  .build();
  1. You can always just create an Intent with the builder like following (if the annotated class is an Activity or if the boolean flag alwaysAddIntentBuilder of the BundleBuilder is set to true:
Intent intent = new TestBundleBuilder()  .id(1L)  .value("Test")  .optionalValue("optionalValue")  .buildIntent(context);
  1. If the annotated class extends Activity, following method will be added to start the activity directly;
new MyActivityBundleBuilder()  .stringArg("Test")  .startActivity(context);
  1. if the enable useConstructorForMandatoryArgs in the @BundleBuilder annotation, the generated builder will force you to set mandatory fields via the constructor like following:
Bundle b = new TestBundleBuilder(1L, "Test") // you MUST supply mandatory fields  .optionalValue("optionalValue") // optional fields can be set via builder functions  .build();

Customisation

@BundleBuilder

You can define some setup variables like following (each one is optional):

@BundleBuilder(useConstructorForMandatoryArgs = true, setterPrefix = "with", generateGetters = false, generateIntentBuilder = false) 
  • boolean useConstructorForMandatoryArgs(): default: false... if true, all mandatory fields will be part of the constructor, otherwise all mandatory fields need to be set with the builder style
  • String setterPrefix(): default ""... if not empty, all setters for the builder will be prefixed with this String. I.e. the field customField will be settable via a function builder.withCustomField(...) if the setterPrefix == "with"...
  • boolean generateGetters(): default: false... defines, if the builder offers getter functions for each field to retrieve fields from a bundle directly
  • boolean generateIntentBuilder(): default: false... defines, if the buildIntent method is generated for non activity classes as well

@Arg

 @Arg(value = "", optional = false) 
  • String name(): default: ""... if set, the builder setter will get the custom name instead of the one derived from the field name
  • boolean optional(): default: false... if true, fields are optional, if not, they must be set via constructor or via setter

Demo

For an example with activities, check out the demo: Demo

Credits

This project is generally based on https://github.com/emilsjolander/IntentBuilder but was improved and restructured heavily in the meantime.

TODO

  • conductor/fragment/class demo?
  • ???

Resources

FastHub is yet another open source GitHub client app but unlike any other app, FastHub built from ground up.

CircleMenu is a simple, elegant menu with a circular layout.

A fast, light-weight and powerful Play Store information fetcher for Android.

This library allows you to fetch various live information from Play Store of your app or any other app of your choice. With just a few lines of code, you can get access to a lot of useful app data fetched fresh from the Play Store.

An Android Library to load your GIF files directly

PermissionsManager library that has base activity and fragment that extend from AppCompatActivity to ease with the handling of runtime permissions.

It's a simple MVP implementation. With this library every developer can integration pattern MVP in him project. To add presenter to Activity or Fragment, the developer need write only one row - setPreseter(ExamplePresenter.class);

This library does support MVP pattern for Activities, Fragments and RecyclerViewAdapter.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes