π¨βπ»
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 daggerVersion = '2.11' | |
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" | |
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion" | |
compile "com.google.dagger:dagger:$daggerVersion" | |
compile "com.google.dagger:dagger-android:$daggerVersion" | |
} |
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
@Scope | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface PerActivity { | |
} |
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
@Scope | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface PerFragment { | |
} |
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
@Scope | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface PerChildFragment { | |
} |
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 class App extends Application implements HasActivityInjector { | |
@Inject | |
DispatchingAndroidInjector<Activity> activityInjector; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
DaggerAppComponent.create().inject(this); | |
} |
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) | |
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
@Singleton | |
@Component(modules = AppModule.class) | |
interface AppComponent { | |
void inject(App 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
public abstract class BaseActivity extends Activity implements HasFragmentInjector { | |
@Inject | |
@Named(BaseActivityModule.ACTIVITY_FRAGMENT_MANAGER) | |
protected FragmentManager fragmentManager; | |
@Inject | |
DispatchingAndroidInjector<Fragment> fragmentInjector; | |
@Override |
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 abstract class BaseActivityModule { | |
static final String ACTIVITY_FRAGMENT_MANAGER = "BaseActivityModule.activityFragmentManager"; | |
@Binds | |
@PerActivity | |
abstract Context activityContext(Activity activity); | |
@Provides |
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 { | |
@Inject | |
protected Context activityContext; | |
// Note that this should not be used within a child fragment. | |
@Inject | |
@Named(BaseFragmentModule.CHILD_FRAGMENT_MANAGER) | |
protected FragmentManager childFragmentManager; |
OlderNewer