Last active
April 5, 2019 20:48
-
-
Save mitchtabian/de403c0611b0961f30c801705ebce83c to your computer and use it in GitHub Desktop.
Example of NOT making use of @Component.Builder and @BindsInstance (this is the old way)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component( | |
modules = { | |
AndroidInjectionModule.class, | |
AppModule.class, | |
ActivityBuildersModule.class | |
}) | |
public interface AppComponent extends AndroidInjector<BaseApplication> { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void init(BaseApplication app){ | |
appComponent = DaggerAppComponent.builder().appModule(new AppModule(app)).build(); | |
appComponent.inject(app); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class AppModule { | |
Application application; | |
public AppModule(Application application) { | |
this.application = application; | |
} | |
@Provides | |
Application provideApplicationContext(){ | |
return application; | |
} | |
@Singleton | |
@Provides | |
Drawable getDrawable(Application application){ // application is available here | |
return ContextCompat.getDrawable(application, R.drawable.ic_launcher_background); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject | |
Drawable getDrawable; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if(getDrawable == null){ | |
Log.d(TAG, "onCreate: drawable is null."); | |
} | |
else { | |
Log.d(TAG, "onCreate: drawable is NOT null."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment