Skip to content

Instantly share code, notes, and snippets.

View vestrel00's full-sized avatar
👨‍💻
Working, life, and the universe!

Vandolf Estrellado vestrel00

👨‍💻
Working, life, and the universe!
View GitHub Profile
@vestrel00
vestrel00 / MVPView.java
Created July 28, 2017 14:59
C: 1 - ui/common/view/MVPView.java
public interface MVPView {
}
@vestrel00
vestrel00 / Dagger2SimpleExample.java
Last active October 7, 2021 19:59
A: Dagger.android 2.11 simple example with support for Singleton, PerActivity, PerFragment, and PerChildFragment scopes
// 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.
@vestrel00
vestrel00 / BaseFragment.java
Last active August 14, 2017 17:54
B: 2 - ui/common/BaseFragment.java
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
@vestrel00
vestrel00 / build.gradle
Last active August 3, 2017 20:35
B: 2 - app/build.gradle
dependencies {
def butterKnifeVersion = '8.7.0'
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
compile "com.jakewharton:butterknife:$butterKnifeVersion"
}
@vestrel00
vestrel00 / build.grade
Last active August 2, 2017 15:33
B: 1 - root build.gradle
dependencies {
...
classpath "com.jakewharton:butterknife-gradle-plugin:8.7.0"
}
@vestrel00
vestrel00 / AppModule.java
Created July 27, 2017 12:24
A: 8 - AppModule.java
@Module(includes = AndroidInjectionModule.class,
subcomponents = {
MainActivitySubcomponent.class,
Example1ActivitySubcomponent.class,
Example2ActivitySubcomponent.class,
Example3ActivitySubcomponent.class
})
abstract class AppModule {
...
@vestrel00
vestrel00 / Example3ActivityModule.java
Created July 27, 2017 12:22
A: 8 - ui/example_3/Example3ActivityModule.java
@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);
@vestrel00
vestrel00 / Example3ChildFragmentSubcomponent.java
Created July 27, 2017 12:20
A: 8 - ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.java
// 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> {
}
}
@vestrel00
vestrel00 / Example3ChildFragmentModule.java
Created July 27, 2017 12:19
A: 8 - ui/example_3/child_fragment/Example3ChildFragmentModule.java
@Module(includes = {
BaseChildFragmentModule.class,
})
abstract class Example3ChildFragmentModule {
@Binds
@Named(BaseChildFragmentModule.CHILD_FRAGMENT)
@PerChildFragment
abstract Fragment fragment(Example3ChildFragment example3ChildFragment);
}
@vestrel00
vestrel00 / Example3ChildFragment.java
Created July 27, 2017 12:17
A: 8 - ui/example_3/child_fragment/Example3ChildFragment.java
public final class Example3ChildFragment extends BaseFragment implements View.OnClickListener {
...
@Inject
PerChildFragmentUtil perChildFragmentUtil;
...
private void onDoSomethingClicked() {