Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A: 9 - Refactored dagger subcomponent setup using ContributesAndroidInjector annotation to generate the injectors. Closes #9 #26

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 19 additions & 41 deletions app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,55 @@

package com.vestrel00.daggerbutterknifemvp;

import android.app.Activity;

import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1Activity;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1ActivitySubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1ActivityModule;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2Activity;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2ActivitySubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2ActivityModule;
import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3Activity;
import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3ActivitySubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3ActivityModule;
import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivity;
import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivitySubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivityModule;

import dagger.Binds;
import dagger.Module;
import dagger.android.ActivityKey;
import dagger.android.AndroidInjectionModule;
import dagger.android.AndroidInjector;
import dagger.multibindings.IntoMap;
import dagger.android.ContributesAndroidInjector;

/**
* Provides application-wide dependencies.
*/
@Module(includes = AndroidInjectionModule.class,
subcomponents = {
MainActivitySubcomponent.class,
Example1ActivitySubcomponent.class,
Example2ActivitySubcomponent.class,
Example3ActivitySubcomponent.class
})
@Module(includes = AndroidInjectionModule.class)
abstract class AppModule {

/**
* Provides the injector for the {@link MainActivity}, which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@ActivityKey(MainActivity.class)
abstract AndroidInjector.Factory<? extends Activity>
mainActivityInjectorFactory(MainActivitySubcomponent.Builder builder);
@PerActivity
@ContributesAndroidInjector(modules = MainActivityModule.class)
abstract MainActivity mainActivityInjector();

/**
* Provides the injector for the {@link Example1Activity}, which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@ActivityKey(Example1Activity.class)
abstract AndroidInjector.Factory<? extends Activity>
example1ActivityInjectorFactory(Example1ActivitySubcomponent.Builder builder);
@PerActivity
@ContributesAndroidInjector(modules = Example1ActivityModule.class)
abstract Example1Activity example1ActivityInjector();

/**
* Provides the injector for the {@link Example2Activity}, which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@ActivityKey(Example2Activity.class)
abstract AndroidInjector.Factory<? extends Activity>
example2ActivityInjectorFactory(Example2ActivitySubcomponent.Builder builder);
@PerActivity
@ContributesAndroidInjector(modules = Example2ActivityModule.class)
abstract Example2Activity example2ActivityInjector();

/**
* Provides the injector for the {@link Example3Activity}, which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@ActivityKey(Example3Activity.class)
abstract AndroidInjector.Factory<? extends Activity>
example3ActivityInjectorFactory(Example3ActivitySubcomponent.Builder builder);
@PerActivity
@ContributesAndroidInjector(modules = Example3ActivityModule.class)
abstract Example3Activity example3ActivityInjector();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,30 @@
package com.vestrel00.daggerbutterknifemvp.ui.example_1;

import android.app.Activity;
import android.app.Fragment;

import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.Example1Fragment;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.Example1FragmentSubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.Example1FragmentModule;

import dagger.Binds;
import dagger.Module;
import dagger.android.AndroidInjector;
import dagger.android.FragmentKey;
import dagger.multibindings.IntoMap;
import dagger.android.ContributesAndroidInjector;

/**
* Provides example 1 activity dependencies.
*/
@Module(includes = BaseActivityModule.class,
subcomponents = Example1FragmentSubcomponent.class)
abstract class Example1ActivityModule {
@Module(includes = BaseActivityModule.class)
public abstract class Example1ActivityModule {

/**
* Provides the injector for the {@link Example1Fragment}, which has access to the dependencies
* provided by this activity and application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@FragmentKey(Example1Fragment.class)
abstract AndroidInjector.Factory<? extends Fragment>
example1FragmentInjectorFactory(Example1FragmentSubcomponent.Builder builder);
@PerFragment
@ContributesAndroidInjector(modules = Example1FragmentModule.class)
abstract Example1Fragment example1FragmentInjector();

/**
* As per the contract specified in {@link BaseActivityModule}; "This must be included in all
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Module(includes = {
BaseFragmentModule.class,
})
abstract class Example1FragmentModule {
public abstract class Example1FragmentModule {

/**
* As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,40 @@
package com.vestrel00.daggerbutterknifemvp.ui.example_2;

import android.app.Activity;
import android.app.Fragment;

import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.Example2AFragment;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.Example2AFragmentSubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.Example2AFragmentModule;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragment;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragmentSubcomponent;
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragmentModule;

import dagger.Binds;
import dagger.Module;
import dagger.android.AndroidInjector;
import dagger.android.FragmentKey;
import dagger.multibindings.IntoMap;
import dagger.android.ContributesAndroidInjector;

/**
* Provides example 2 activity dependencies.
*/
@Module(includes = BaseActivityModule.class,
subcomponents = {
Example2AFragmentSubcomponent.class,
Example2BFragmentSubcomponent.class
})
abstract class Example2ActivityModule {
@Module(includes = BaseActivityModule.class)
public abstract class Example2ActivityModule {

/**
* Provides the injector for the {@link Example2AFragment}, which has access to the dependencies
* provided by this activity and application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@FragmentKey(Example2AFragment.class)
abstract AndroidInjector.Factory<? extends Fragment>
example2AFragmentInjectorFactory(Example2AFragmentSubcomponent.Builder builder);
@PerFragment
@ContributesAndroidInjector(modules = Example2AFragmentModule.class)
abstract Example2AFragment example2AFragmentInjector();

/**
* Provides the injector for the {@link Example2BFragment}, which has access to the dependencies
* provided by this activity and application instance (singleton scoped objects).
*/
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector
@Binds
@IntoMap
@FragmentKey(Example2BFragment.class)
abstract AndroidInjector.Factory<? extends Fragment>
example2BFragmentInjectorFactory(Example2BFragmentSubcomponent.Builder builder);
@PerFragment
@ContributesAndroidInjector(modules = Example2BFragmentModule.class)
abstract Example2BFragment example2BFragmentInjector();

/**
* As per the contract specified in {@link BaseActivityModule}; "This must be included in all
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Module(includes = {
BaseFragmentModule.class,
})
abstract class Example2AFragmentModule {
public abstract class Example2AFragmentModule {

/**
* As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Module(includes = {
BaseFragmentModule.class,
})
abstract class Example2BFragmentModule {
public abstract class Example2BFragmentModule {

/**
* As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
Expand Down
Loading