Created
June 12, 2017 08:33
-
-
Save anonymous/45446b3bf2100d1c22520ebf82f0bff3 to your computer and use it in GitHub Desktop.
dagger2 subcomponent
This file contains hidden or 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 abstract class ActivitiesModule { | |
@ActivityScope @ContributesAndroidInjector(modules = { MainActivityModule.class }) | |
abstract MainActivity mainActivity(); | |
} |
This file contains hidden or 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 = { | |
RepositoryModule.class, AndroidSupportInjectionModule.class, ActivitiesModule.class | |
}) public interface MyApplicationComponent extends AndroidInjector<MyApplication> { | |
@Component.Builder abstract class Builder extends AndroidInjector.Builder<MyApplication> { | |
} | |
} |
This file contains hidden or 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 abstract class BaseActivity extends RxAppCompatActivity { | |
... | |
@CallSuper @Override protected void onCreate(@Nullable Bundle savedInstanceState) { | |
AndroidInjection.inject(this); | |
super.onCreate(savedInstanceState); | |
} | |
... | |
} |
This file contains hidden or 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 abstract class BaseFragment extends RxFragment { | |
... | |
@CallSuper @Override public void onAttach(Activity activity) { | |
AndroidSupportInjection.inject(this); | |
super.onAttach(activity); | |
} | |
... | |
} |
This file contains hidden or 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 class HomeFragment extends BaseFragment { | |
@Inject HomePresenter presenter; | |
} |
This file contains hidden or 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
@ActivityScope public class MainActivity extends BaseActivity implements HasSupportFragmentInjector { | |
@Inject DispatchingAndroidInjector<Fragment> fragmentInjector; | |
... | |
@Override public AndroidInjector<Fragment> supportFragmentInjector() { | |
return fragmentInjector; | |
} | |
} |
This file contains hidden or 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 abstract class MainActivityModule { | |
@Provides @Reusable static RxPermissions provideRxPermissions(MainActivity mainActivity) { | |
return new RxPermissions(mainActivity); | |
} | |
@ContributesAndroidInjector abstract HomeFragment homeFragment(); | |
} |
This file contains hidden or 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 RepositoryModule { | |
@Provides @Singleton | |
public SharedPreferences provideSharedPreferences(MyApplication app) { | |
return app.getSharedPreferences("default", Context.MODE_PRIVATE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment