From 4d6c01fd6bba647def97e41ada46321f7b3331d7 Mon Sep 17 00:00:00 2001 From: Vandolf Estrellado Date: Mon, 24 Jul 2017 11:45:52 -0400 Subject: [PATCH] Refactored dagger subcomponent setup using ContributesAndroidInjector annotation to generate the injectors. Closes #9 --- .../daggerbutterknifemvp/AppModule.java | 60 ++++++------------- .../ui/example_1/Example1ActivityModule.java | 22 +++---- .../Example1ActivitySubcomponent.java | 40 ------------- .../fragment/Example1FragmentModule.java | 2 +- .../Example1FragmentSubcomponent.java | 39 ------------ .../ui/example_2/Example2ActivityModule.java | 36 ++++------- .../Example2ActivitySubcomponent.java | 40 ------------- .../fragment_a/Example2AFragmentModule.java | 2 +- .../Example2AFragmentSubcomponent.java | 39 ------------ .../fragment_b/Example2BFragmentModule.java | 2 +- .../Example2BFragmentSubcomponent.java | 39 ------------ .../ui/example_3/Example3ActivityModule.java | 22 +++---- .../Example3ActivitySubcomponent.java | 38 ------------ .../Example3ChildFragmentModule.java | 2 +- .../Example3ChildFragmentSubcomponent.java | 39 ------------ .../Example3ParentFragmentModule.java | 23 +++---- .../Example3ParentFragmentSubcomponent.java | 40 ------------- .../ui/main/MainActivityModule.java | 20 +++---- .../ui/main/MainActivitySubcomponent.java | 39 ------------ .../ui/main/MainFragmentSubcomponent.java | 39 ------------ 20 files changed, 66 insertions(+), 517 deletions(-) delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivitySubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentSubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivitySubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentSubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentSubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivitySubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentSubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivitySubcomponent.java delete mode 100644 app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainFragmentSubcomponent.java diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java index 58aa4af..dae5da9 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java @@ -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 - 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 - 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 - 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 - example3ActivityInjectorFactory(Example3ActivitySubcomponent.Builder builder); + @PerActivity + @ContributesAndroidInjector(modules = Example3ActivityModule.class) + abstract Example3Activity example3ActivityInjector(); } \ No newline at end of file diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java index a4bb19c..16879f5 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java @@ -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 - 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 diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivitySubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivitySubcomponent.java deleted file mode 100644 index dff6e71..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivitySubcomponent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_1; - - -import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 1 activity dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerActivity -@Subcomponent(modules = Example1ActivityModule.class) -public interface Example1ActivitySubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentModule.java index e9c0008..e360264 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentModule.java @@ -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 diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentSubcomponent.java deleted file mode 100644 index 2d16bfc..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentSubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment; - -import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 1 fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerFragment -@Subcomponent(modules = Example1FragmentModule.class) -public interface Example1FragmentSubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java index d04b868..d33167b 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java @@ -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 - 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 - 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 diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivitySubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivitySubcomponent.java deleted file mode 100644 index 3a89727..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivitySubcomponent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_2; - - -import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 2 activity dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerActivity -@Subcomponent(modules = Example2ActivityModule.class) -public interface Example2ActivitySubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentModule.java index 253d654..8e08942 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentModule.java @@ -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 diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentSubcomponent.java deleted file mode 100644 index ac31cd2..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentSubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a; - -import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 2 A fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerFragment -@Subcomponent(modules = Example2AFragmentModule.class) -public interface Example2AFragmentSubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentModule.java index 9473430..c4bbad4 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentModule.java @@ -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 diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentSubcomponent.java deleted file mode 100644 index 72e0830..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/Example2BFragmentSubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b; - -import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 2 B fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerFragment -@Subcomponent(modules = Example2BFragmentModule.class) -public interface Example2BFragmentSubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java index a52cfa7..3a26143 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java @@ -17,36 +17,30 @@ package com.vestrel00.daggerbutterknifemvp.ui.example_3; 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_3.parent_fragment.Example3ParentFragment; -import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.Example3ParentFragmentSubcomponent; +import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.Example3ParentFragmentModule; import dagger.Binds; import dagger.Module; -import dagger.android.AndroidInjector; -import dagger.android.FragmentKey; -import dagger.multibindings.IntoMap; +import dagger.android.ContributesAndroidInjector; /** * Provides example 3 activity dependencies. */ -@Module(includes = BaseActivityModule.class, - subcomponents = Example3ParentFragmentSubcomponent.class) -abstract class Example3ActivityModule { +@Module(includes = BaseActivityModule.class) +public abstract class Example3ActivityModule { /** * Provides the injector for the {@link Example3ParentFragment}, 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(Example3ParentFragment.class) - abstract AndroidInjector.Factory - example3ParentFragmentInjectorFactory(Example3ParentFragmentSubcomponent.Builder builder); + @PerFragment + @ContributesAndroidInjector(modules = Example3ParentFragmentModule.class) + abstract Example3ParentFragment example3ParentFragmentInjector(); /** * As per the contract specified in {@link BaseActivityModule}; "This must be included in all diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivitySubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivitySubcomponent.java deleted file mode 100644 index f19e402..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivitySubcomponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_3; - - -import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 3 activity dependencies. - */ -@PerActivity -@Subcomponent(modules = Example3ActivityModule.class) -public interface Example3ActivitySubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentModule.java index b528ea6..c5f169f 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentModule.java @@ -32,7 +32,7 @@ @Module(includes = { BaseChildFragmentModule.class, }) -abstract class Example3ChildFragmentModule { +public abstract class Example3ChildFragmentModule { /** * As per the contract specified in {@link BaseChildFragmentModule}; "This must be included in diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.java deleted file mode 100644 index 69d9380..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment; - -import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 3 child fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerChildFragment -@Subcomponent(modules = Example3ChildFragmentModule.class) -public interface Example3ChildFragmentSubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentModule.java index 2b5264d..21b83db 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentModule.java @@ -18,39 +18,32 @@ import android.app.Fragment; +import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment; import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; import com.vestrel00.daggerbutterknifemvp.ui.common.BaseFragmentModule; import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.Example3ChildFragment; -import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.Example3ChildFragmentSubcomponent; +import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.Example3ChildFragmentModule; import javax.inject.Named; import dagger.Binds; import dagger.Module; -import dagger.android.AndroidInjector; -import dagger.android.FragmentKey; -import dagger.multibindings.IntoMap; +import dagger.android.ContributesAndroidInjector; /** * Provides example 3 parent fragment dependencies. */ -@Module(includes = { - BaseFragmentModule.class -}, - subcomponents = Example3ChildFragmentSubcomponent.class) -abstract class Example3ParentFragmentModule { +@Module(includes = BaseFragmentModule.class) +public abstract class Example3ParentFragmentModule { /** * Provides the injector for the {@link Example3ChildFragment}, which has access to the * dependencies provided by this fragment and activity and application instance * (singleton scoped objects). */ - // TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - @Binds - @IntoMap - @FragmentKey(Example3ChildFragment.class) - abstract AndroidInjector.Factory - example3ChildFragmentInjectorFactory(Example3ChildFragmentSubcomponent.Builder builder); + @PerChildFragment + @ContributesAndroidInjector(modules = Example3ChildFragmentModule.class) + abstract Example3ChildFragment example3ChildFragmentInjector(); /** * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentSubcomponent.java deleted file mode 100644 index d903df0..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/Example3ParentFragmentSubcomponent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment; - -import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects example 3 parent fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerFragment -@Subcomponent(modules = Example3ParentFragmentModule.class) -public interface Example3ParentFragmentSubcomponent - extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java index b97b1e6..bf60241 100644 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java +++ b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java @@ -17,34 +17,28 @@ package com.vestrel00.daggerbutterknifemvp.ui.main; 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 dagger.Binds; import dagger.Module; -import dagger.android.AndroidInjector; -import dagger.android.FragmentKey; -import dagger.multibindings.IntoMap; +import dagger.android.ContributesAndroidInjector; /** * Provides main activity dependencies. */ -@Module(includes = BaseActivityModule.class, - subcomponents = MainFragmentSubcomponent.class) -abstract class MainActivityModule { +@Module(includes = BaseActivityModule.class) +public abstract class MainActivityModule { /** * Provides the injector for the {@link MainFragment}, 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(MainFragment.class) - abstract AndroidInjector.Factory - mainFragmentInjectorFactory(MainFragmentSubcomponent.Builder builder); + @PerFragment + @ContributesAndroidInjector(modules = MainFragmentModule.class) + abstract MainFragment mainFragmentInjector(); /** * As per the contract specified in {@link BaseActivityModule}; "This must be included in all diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivitySubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivitySubcomponent.java deleted file mode 100644 index ec2b44b..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivitySubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.main; - -import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects main activity dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerActivity -@Subcomponent(modules = MainActivityModule.class) -public interface MainActivitySubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -} diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainFragmentSubcomponent.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainFragmentSubcomponent.java deleted file mode 100644 index 9c93fee..0000000 --- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainFragmentSubcomponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 Vandolf Estrellado - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.vestrel00.daggerbutterknifemvp.ui.main; - -import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; - -import dagger.Subcomponent; -import dagger.android.AndroidInjector; - -/** - * Injects main fragment dependencies. - *

- * TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector - */ -@PerFragment -@Subcomponent(modules = MainFragmentModule.class) -public interface MainFragmentSubcomponent extends AndroidInjector { - - /** - * The builder for this subcomponent. - */ - @Subcomponent.Builder - abstract class Builder extends AndroidInjector.Builder { - } -}