π¨βπ»
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 interface MVPView { | |
} |
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
// This is a super simplified example of how to use the new dagger.android framework | |
// introduced in Dagger 2.10. For a more complete, in-depth guide to dagger.android | |
// read https://proandroiddev.com/how-to-android-dagger-2-10-2-11-butterknife-mvp-part-1-eb0f6b970fd | |
// For a complete codebase using dagger.android 2.11-2.17, butterknife 8.7-8.8, and MVP, | |
// see https://github.com/vestrel00/android-dagger-butterknife-mvp | |
// This example works with Dagger 2.11-2.17. Starting with Dagger 2.11, | |
// @ContributesAndroidInjector was introduced removing the need to define @Subcomponent classes. |
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 abstract class BaseFragment extends Fragment implements HasFragmentInjector { | |
... | |
@Nullable | |
private Unbinder viewUnbinder; | |
@SuppressWarnings("ConstantConditions") | |
@Override | |
public void onViewStateRestored(Bundle savedInstanceState) { | |
super.onViewStateRestored(savedInstanceState); | |
// No need to check if getView() is null because this lifecycle method will |
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
dependencies { | |
def butterKnifeVersion = '8.7.0' | |
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion" | |
compile "com.jakewharton:butterknife:$butterKnifeVersion" | |
} |
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
dependencies { | |
... | |
classpath "com.jakewharton:butterknife-gradle-plugin:8.7.0" | |
} |
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(includes = AndroidInjectionModule.class, | |
subcomponents = { | |
MainActivitySubcomponent.class, | |
Example1ActivitySubcomponent.class, | |
Example2ActivitySubcomponent.class, | |
Example3ActivitySubcomponent.class | |
}) | |
abstract class AppModule { | |
... | |
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(includes = BaseActivityModule.class, | |
subcomponents = Example3ParentFragmentSubcomponent.class) | |
abstract class Example3ActivityModule { | |
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | |
@Binds | |
@IntoMap | |
@FragmentKey(Example3ParentFragment.class) | |
abstract AndroidInjector.Factory<? extends Fragment> | |
example3ParentFragmentInjectorFactory(Example3ParentFragmentSubcomponent.Builder builder); |
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
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | |
@PerChildFragment | |
@Subcomponent(modules = Example3ChildFragmentModule.class) | |
public interface Example3ChildFragmentSubcomponent extends AndroidInjector<Example3ChildFragment> { | |
@Subcomponent.Builder | |
abstract class Builder extends AndroidInjector.Builder<Example3ChildFragment> { | |
} | |
} |
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(includes = { | |
BaseChildFragmentModule.class, | |
}) | |
abstract class Example3ChildFragmentModule { | |
@Binds | |
@Named(BaseChildFragmentModule.CHILD_FRAGMENT) | |
@PerChildFragment | |
abstract Fragment fragment(Example3ChildFragment example3ChildFragment); | |
} |
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 final class Example3ChildFragment extends BaseFragment implements View.OnClickListener { | |
... | |
@Inject | |
PerChildFragmentUtil perChildFragmentUtil; | |
... | |
private void onDoSomethingClicked() { |