Dagger Play


Source link: https://github.com/fernandodev/daggerplay

Dagger Play

Dagger Play is a small set of reusable classes for Dagger injection. There many ways to implement Dagger into your project. Unfortunately memory leaks can occur easily if you implement it without attention.

Dagger Play just do the "step by step" for you and provides a minimum and necessary interface to inject and install Dagger into your project. So forget those tutorials and a lot of poor code snippets and start injecting!

Installation

It's very simple with gradle ;)

Add mavenCentral as repository source:

repositories {

mavenCentral() 
}

And finnaly add this line inside dependencies { } section:

compile 'com.github.fernandodev.daggerplay:daggerplay:+'

The + symbol indicates to gradle to get the latest version.

  • See the sample if there are any doubts.
  • DaggerPlay uses compile 'dagger:1.2.+' and 'dagger-compiler:1.2.+'

Using

Like Dagger, you need to create a Module for your Android Project. Generally Module. See the sample below:

@Module(
  injects = {

MainActivity.class
 //THE INJECTABLE CLASSES
  
}
,
  library = true,
  complete = false,
  overrides = false ) public class SampleModule {

 @Provides UsefulHelper provideUsefulHelper(@WithActivity Context context) {

  return new UsefulHelper(context);

}
 
}

Now, you have your main module (you can create how many modules as you want), so you need to register it and finally install Dagger into your application.

Extends android.app.Application and in onCreate just register your module and install Dagger.

public class Samplepplication extends Application {

 @Override
public void onCreate() {

  super.onCreate();

  DaggerPlay.registerModules(new SampleModule());

  DaggerPlay.install(this);

}
 
}
  • Call install after register all your modules.

Now you are ready to use your injections!

There are special methods in DaggerPlay class for Activity, Fragment, Support Fragment and IntentService injections.

public static void injectActivity(Activity activity);
  public static void injectFragment(Activity activity, Fragment fragment);
  public static void injectSupportFragment(Activity activity, android.support.v4.app.Fragment fragment);
  public static void injectService(IntentService service);

So, in onCreate callback, just call DaggerPlay.injectActivity(this); and everything will work like a charm.

Important Details

@WithActivity & @WithApplication

This is a especial annotation to distinguish Context provided by Application or Activity. So, if you want a Context from Activity use this annotation.

Default Injections

With DaggerPlay you get default injections for your application

  1. @Inject @WithActivity Context
  2. @Inject Resources
  3. @Inject Application
  4. @Inject Activity
  5. @Inject @WithApplication Context

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

Gorgeous Android Time and Date picker library inspired by the Timely app.

The ExpandableConstraintLayout presents itself as a wrapper around Google's ConstraintLayout with the small feature of toggling (expansion/collapse).

ChartProgressBar is an android library to build a bar chart with progress bar style.

Country gives a list of countries with all their flags.

A circular seekbar for Android, with a control knob! (for the lack of a better word).

A customizable number picker based on Material guidelines.

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