├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── codingwithmitch
│ │ │ └── daggermultifeature
│ │ │ ├── app
│ │ │ ├── BaseApplication.kt
│ │ │ ├── di
│ │ │ │ ├── AppComponent.kt
│ │ │ │ ├── AppModule.kt
│ │ │ │ └── SubComponentsModule.kt
│ │ │ └── ui
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── MainNavController.kt
│ │ │ ├── feature1
│ │ │ ├── data
│ │ │ │ ├── Feature1LocalDataSource.kt
│ │ │ │ └── Feature1LocalDataSourceImpl.kt
│ │ │ ├── di
│ │ │ │ ├── Feature1Component.kt
│ │ │ │ ├── Feature1FragmentBuildersModule.kt
│ │ │ │ ├── Feature1FragmentScope.kt
│ │ │ │ ├── Feature1Module.kt
│ │ │ │ ├── Feature1ViewModelsModule.kt
│ │ │ │ └── keys
│ │ │ │ │ ├── Feature1FragmentKey.kt
│ │ │ │ │ └── Feature1ViewModelKey.kt
│ │ │ ├── fragments
│ │ │ │ ├── Feature1FragmentFactory.kt
│ │ │ │ └── Feature1NavHostFragment.kt
│ │ │ ├── repository
│ │ │ │ ├── Feature1Repository.kt
│ │ │ │ └── Feature1RepositoryImpl.kt
│ │ │ ├── ui
│ │ │ │ ├── Feature1FinalFragment.kt
│ │ │ │ ├── Feature1MainFragment.kt
│ │ │ │ ├── Feature1NextFragment.kt
│ │ │ │ └── Feature1ViewModel.kt
│ │ │ └── viewmodels
│ │ │ │ └── Feature1ViewModelFactory.kt
│ │ │ └── main
│ │ │ ├── data
│ │ │ ├── MainLocalDataSource.kt
│ │ │ └── MainLocalDataSourceImpl.kt
│ │ │ ├── di
│ │ │ ├── MainComponent.kt
│ │ │ ├── MainFragmentBuildersModule.kt
│ │ │ ├── MainFragmentScope.kt
│ │ │ ├── MainModule.kt
│ │ │ ├── ViewModelModule.kt
│ │ │ └── keys
│ │ │ │ ├── MainFragmentKey.kt
│ │ │ │ └── MainViewModelKey.kt
│ │ │ ├── fragments
│ │ │ ├── MainFragmentFactory.kt
│ │ │ └── MainNavHostFragment.kt
│ │ │ ├── repository
│ │ │ ├── MainRepository.kt
│ │ │ └── MainRepositoryImpl.kt
│ │ │ ├── ui
│ │ │ ├── MainFragment.kt
│ │ │ └── MainViewModel.kt
│ │ │ └── viewmodels
│ │ │ └── MainViewModelFactory.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_accessibility_black_24dp.xml
│ │ ├── ic_android_black_24dp.xml
│ │ ├── ic_home_black_24dp.xml
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_feature1_final.xml
│ │ ├── fragment_feature1_main.xml
│ │ ├── fragment_feature1_next.xml
│ │ └── fragment_main.xml
│ │ ├── menu
│ │ └── drawer_menu.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── navigation
│ │ ├── feature1_nav_graph.xml
│ │ └── main_nav_graph.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── codingwithmitch
│ └── daggermultifeature
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | xmlns:android
20 |
21 | ^$
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | xmlns:.*
31 |
32 | ^$
33 |
34 |
35 | BY_NAME
36 |
37 |
38 |
39 |
40 |
41 |
42 | .*:id
43 |
44 | http://schemas.android.com/apk/res/android
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | .*:name
54 |
55 | http://schemas.android.com/apk/res/android
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | name
65 |
66 | ^$
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | style
76 |
77 | ^$
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | .*
87 |
88 | ^$
89 |
90 |
91 | BY_NAME
92 |
93 |
94 |
95 |
96 |
97 |
98 | .*
99 |
100 | http://schemas.android.com/apk/res/android
101 |
102 |
103 | ANDROID_ATTRIBUTE_ORDER
104 |
105 |
106 |
107 |
108 |
109 |
110 | .*
111 |
112 | .*
113 |
114 |
115 | BY_NAME
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Features:
2 | 1. Dagger2 (not dagger-android)
3 | 2. Single activity
4 | 3. FragmentFactory
5 | 4. Multi-feature package structure
6 | 5. Navigation components
7 | - Separate nav graph for each feature
8 |
9 | # Info
10 | Each feature has it's own Subcomponent with it's own:
11 | 1. ViewModelFactory
12 | 2. FragmentFactory
13 | 3. NavHostFragment
14 | - This is needed since each feature has it's own navigation graph
15 |
16 | # Next steps:
17 | Build a dynamic multi-feature sample.
18 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'kotlin-kapt'
8 |
9 | android {
10 | compileSdkVersion 29
11 | buildToolsVersion "29.0.2"
12 | defaultConfig {
13 | applicationId "com.codingwithmitch.daggermultifeature"
14 | minSdkVersion 21
15 | targetSdkVersion 29
16 | versionCode 1
17 | versionName "1.0"
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | compileOptions {
28 | sourceCompatibility = '1.8'
29 | targetCompatibility = '1.8'
30 | }
31 |
32 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
33 | kotlinOptions {
34 | jvmTarget = "1.8"
35 | }
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation fileTree(dir: 'libs', include: ['*.jar'])
41 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
42 | implementation 'androidx.appcompat:appcompat:1.1.0'
43 | implementation 'androidx.core:core-ktx:1.1.0'
44 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
45 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
46 | testImplementation 'junit:junit:4.12'
47 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
49 |
50 | def nav_version = "2.1.0"
51 | implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
52 | implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
53 |
54 | def dagger_version = "2.25.4"
55 | implementation "com.google.dagger:dagger:$dagger_version"
56 | kapt "com.google.dagger:dagger-compiler:$dagger_version"
57 |
58 |
59 | // -- Coroutines
60 | def coroutines_version = "1.2.1"
61 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
62 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
63 | }
64 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/BaseApplication.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app
2 |
3 | import android.app.Application
4 | import com.codingwithmitch.daggermultifeature.app.di.AppComponent
5 | import com.codingwithmitch.daggermultifeature.app.di.DaggerAppComponent
6 |
7 | class BaseApplication : Application() {
8 |
9 | private val TAG: String = "AppDebug"
10 |
11 | private val appComponent = DaggerAppComponent.builder()
12 | .application(this)
13 | .build()
14 |
15 | override fun onCreate() {
16 | super.onCreate()
17 | appComponent.inject(this)
18 | }
19 |
20 |
21 | fun getAppComponent(): AppComponent{
22 | return appComponent
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/di/AppComponent.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app.di
2 |
3 | import android.app.Application
4 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
5 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1Component
6 | import com.codingwithmitch.daggermultifeature.main.di.MainComponent
7 | import dagger.BindsInstance
8 | import dagger.Component
9 | import javax.inject.Singleton
10 |
11 |
12 | @Singleton
13 | @Component(modules = [
14 | AppModule::class,
15 | SubComponentsModule::class
16 | ])
17 | interface AppComponent{
18 |
19 | @Component.Builder
20 | interface Builder{
21 |
22 | @BindsInstance
23 | fun application(application: Application): Builder
24 |
25 | fun build(): AppComponent
26 | }
27 |
28 | fun inject(application: BaseApplication)
29 |
30 | fun feature1Component(): Feature1Component.Factory
31 |
32 | fun mainComponent(): MainComponent.Factory
33 |
34 | }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/di/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app.di
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import javax.inject.Named
6 | import javax.inject.Singleton
7 |
8 | @Module
9 | object AppModule{
10 |
11 | @Singleton
12 | @Provides
13 | @Named("application_name")
14 | @JvmStatic
15 | fun provideApplicationName(): String {
16 | return "Dagger Multi-feature Demo"
17 | }
18 |
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/di/SubComponentsModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app.di
2 |
3 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1Component
4 | import com.codingwithmitch.daggermultifeature.main.di.MainComponent
5 | import dagger.Module
6 |
7 | @Module(
8 | subcomponents = [
9 | Feature1Component::class,
10 | MainComponent::class
11 | ]
12 | )
13 | class SubComponentsModule
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app.ui
2 |
3 | import android.os.Bundle
4 | import android.view.Gravity
5 | import android.view.MenuItem
6 | import androidx.annotation.IdRes
7 | import androidx.annotation.NavigationRes
8 | import androidx.fragment.app.FragmentActivity
9 | import androidx.navigation.NavController
10 | import androidx.navigation.fragment.NavHostFragment
11 | import androidx.navigation.ui.setupWithNavController
12 | import com.codingwithmitch.daggermultifeature.R
13 | import com.codingwithmitch.daggermultifeature.feature1.fragments.Feature1FragmentFactory
14 | import com.codingwithmitch.daggermultifeature.feature1.fragments.Feature1NavHostFragment
15 | import com.codingwithmitch.daggermultifeature.main.fragments.MainFragmentFactory
16 | import com.codingwithmitch.daggermultifeature.main.fragments.MainNavHostFragment
17 | import com.codingwithmitch.daggermultifeature.main.ui.MainFragment
18 | import com.google.android.material.navigation.NavigationView
19 |
20 | import kotlinx.android.synthetic.main.activity_main.*
21 |
22 | class MainActivity : FragmentActivity(),
23 | MainNavController,
24 | NavigationView.OnNavigationItemSelectedListener
25 | {
26 |
27 | private val TAG: String = "AppDebug"
28 |
29 | private val navigationView: NavigationView by lazy {
30 | findViewById(R.id.nav_view)
31 | }
32 |
33 | private lateinit var navController: NavController
34 |
35 | private fun createNavHost(@NavigationRes graphId: Int, fragmentFactoryName: String){
36 |
37 | val newNavHostFragment = when(fragmentFactoryName){
38 |
39 | MainFragmentFactory.FRAGMENT_FACTORY_NAME -> {
40 | MainNavHostFragment.create(
41 | graphId
42 | )
43 | }
44 |
45 | Feature1FragmentFactory.FRAGMENT_FACTORY_NAME ->{
46 | Feature1NavHostFragment.create(
47 | graphId
48 | )
49 | }
50 |
51 | else ->{
52 | MainNavHostFragment.create(
53 | graphId
54 | )
55 | }
56 | }
57 |
58 | supportFragmentManager.beginTransaction()
59 | .replace(
60 | R.id.main_nav_host_container,
61 | newNavHostFragment,
62 | getString(R.string.NavHostFragmentTag)
63 | )
64 | .setPrimaryNavigationFragment(newNavHostFragment)
65 | .commit()
66 | }
67 |
68 | override fun onCreate(savedInstanceState: Bundle?) {
69 | super.onCreate(savedInstanceState)
70 | setContentView(R.layout.activity_main)
71 | navMain()
72 | }
73 |
74 | override fun navFeature1() {
75 | createNavHost(
76 | R.navigation.feature1_nav_graph,
77 | Feature1FragmentFactory.FRAGMENT_FACTORY_NAME
78 | )
79 | setDrawerItemChecked(R.id.nav_feature1)
80 | }
81 |
82 | override fun navMain() {
83 | createNavHost(
84 | R.navigation.main_nav_graph,
85 | MainFragmentFactory.FRAGMENT_FACTORY_NAME
86 | )
87 | setDrawerItemChecked(R.id.nav_main)
88 | }
89 |
90 | override fun onBackPressed() {
91 | if(drawer_layout.isDrawerOpen(Gravity.LEFT)){
92 | drawer_layout.closeDrawer(Gravity.LEFT)
93 | }
94 | else{
95 | // must exit from MainFragment
96 | if(getBackStackCount() < 1){
97 | if(!isMainFragmentInView()){
98 | navMain()
99 | return
100 | }
101 | }
102 | super.onBackPressed()
103 | }
104 | }
105 |
106 | private fun isMainFragmentInView(): Boolean {
107 | val navHostFragment = supportFragmentManager
108 | .findFragmentByTag(getString(R.string.NavHostFragmentTag)) as NavHostFragment
109 | val topFragment = navHostFragment.childFragmentManager.fragments[0]
110 | if(topFragment is MainFragment){
111 | return true
112 | }
113 | return false
114 | }
115 |
116 | private fun getBackStackCount(): Int{
117 | val navHostFragment = supportFragmentManager
118 | .findFragmentById(R.id.main_nav_host_container)
119 | navHostFragment?.let { host ->
120 | host.childFragmentManager.let { fm ->
121 | return fm.backStackEntryCount
122 | }
123 | }
124 | return 0
125 | }
126 |
127 | override fun setDrawerItemChecked(@IdRes menuItemId: Int) {
128 | when(menuItemId){
129 |
130 | R.id.nav_main -> navigationView.menu.getItem(0).isChecked = true
131 |
132 | R.id.nav_feature1 -> navigationView.menu.getItem(1).isChecked = true
133 | }
134 | }
135 |
136 | override fun onNavigationItemSelected(item: MenuItem): Boolean {
137 | when(item.itemId){
138 |
139 | R.id.nav_main -> {
140 | navMain()
141 | }
142 |
143 | R.id.nav_feature1 -> {
144 | navFeature1()
145 | }
146 |
147 | }
148 | drawer_layout.closeDrawer(Gravity.LEFT)
149 | return true
150 | }
151 |
152 | override fun navController() = navController
153 |
154 | override fun setNavController(navController: NavController){
155 | this.navController = navController
156 | }
157 |
158 | override fun setupNavDrawer(){
159 | navigationView.setupWithNavController(navController)
160 | navigationView.setNavigationItemSelectedListener(this)
161 | }
162 | }
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/app/ui/MainNavController.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.app.ui
2 |
3 | import androidx.annotation.IdRes
4 | import androidx.navigation.NavController
5 | import androidx.navigation.fragment.NavHostFragment
6 |
7 | interface MainNavController {
8 |
9 | fun navController(): NavController
10 |
11 | fun setNavController(navController: NavController)
12 |
13 | fun setupNavDrawer()
14 |
15 | fun navFeature1()
16 |
17 | fun navMain()
18 |
19 | fun setDrawerItemChecked(@IdRes menuItemId: Int)
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/data/Feature1LocalDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.data
2 |
3 | interface Feature1LocalDataSource {
4 |
5 | suspend fun getFeature1MainString(): String
6 |
7 | suspend fun getFeature1NextString(): String
8 |
9 | suspend fun getFeature1FinalString(): String
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/data/Feature1LocalDataSourceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.data
2 |
3 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
4 | import javax.inject.Inject
5 |
6 | @Feature1FragmentScope
7 | class Feature1LocalDataSourceImpl
8 | @Inject
9 | constructor(): Feature1LocalDataSource{
10 |
11 | override suspend fun getFeature1MainString(): String {
12 | return "Feature1MainFragment"
13 | }
14 |
15 | override suspend fun getFeature1NextString(): String {
16 | return "Feature1NextFragment"
17 | }
18 |
19 | override suspend fun getFeature1FinalString(): String {
20 | return "Feature1FinalFragment"
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/Feature1Component.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di
2 |
3 | import com.codingwithmitch.daggermultifeature.feature1.fragments.Feature1NavHostFragment
4 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1FinalFragment
5 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1MainFragment
6 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1NextFragment
7 | import dagger.Subcomponent
8 |
9 |
10 | @Feature1FragmentScope
11 | @Subcomponent(
12 | modules = [
13 | Feature1Module::class,
14 | Feature1ViewModelsModule::class,
15 | Feature1FragmentBuildersModule::class
16 | ]
17 | )
18 | interface Feature1Component {
19 |
20 | @Subcomponent.Factory
21 | interface Factory{
22 |
23 | fun create(): Feature1Component
24 | }
25 |
26 | fun inject(feature1NavHostFragment: Feature1NavHostFragment)
27 |
28 | }
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/Feature1FragmentBuildersModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di
2 |
3 | import androidx.fragment.app.Fragment
4 | import androidx.fragment.app.FragmentFactory
5 | import androidx.navigation.fragment.NavHostFragment
6 | import com.codingwithmitch.daggermultifeature.feature1.di.keys.Feature1FragmentKey
7 | import com.codingwithmitch.daggermultifeature.feature1.fragments.Feature1FragmentFactory
8 | import com.codingwithmitch.daggermultifeature.feature1.fragments.Feature1NavHostFragment
9 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1FinalFragment
10 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1MainFragment
11 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1NextFragment
12 | import com.codingwithmitch.daggermultifeature.main.di.keys.MainFragmentKey
13 | import com.codingwithmitch.daggermultifeature.main.fragments.MainFragmentFactory
14 | import com.codingwithmitch.daggermultifeature.main.fragments.MainNavHostFragment
15 | import dagger.Binds
16 | import dagger.Module
17 | import dagger.multibindings.IntoMap
18 |
19 | @Module
20 | abstract class Feature1FragmentBuildersModule {
21 |
22 | @Binds
23 | abstract fun bindFragmentFactory(feature1FragmentFactory: Feature1FragmentFactory): FragmentFactory
24 |
25 | @Binds
26 | @IntoMap
27 | @Feature1FragmentKey(Feature1MainFragment::class)
28 | abstract fun bindMainFragment(feature1MainFragment: Feature1MainFragment): Fragment
29 |
30 | @Binds
31 | @IntoMap
32 | @Feature1FragmentKey(Feature1NextFragment::class)
33 | abstract fun bindNextFragment(feature1NextFragment: Feature1NextFragment): Fragment
34 |
35 | @Binds
36 | @IntoMap
37 | @Feature1FragmentKey(Feature1FinalFragment::class)
38 | abstract fun bindFinalFragment(feature1FinalFragment: Feature1FinalFragment): Fragment
39 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/Feature1FragmentScope.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di
2 |
3 | import javax.inject.Scope
4 |
5 | @Scope
6 | @Retention(value = AnnotationRetention.RUNTIME)
7 | annotation class Feature1FragmentScope
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/Feature1Module.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di
2 |
3 | import com.codingwithmitch.daggermultifeature.feature1.data.Feature1LocalDataSource
4 | import com.codingwithmitch.daggermultifeature.feature1.data.Feature1LocalDataSourceImpl
5 | import com.codingwithmitch.daggermultifeature.feature1.repository.Feature1Repository
6 | import com.codingwithmitch.daggermultifeature.feature1.repository.Feature1RepositoryImpl
7 | import dagger.Module
8 | import dagger.Provides
9 |
10 | @Module
11 | object Feature1Module {
12 |
13 |
14 | @Feature1FragmentScope
15 | @Provides
16 | @JvmStatic
17 | fun provideFeature1LocalDataSource(): Feature1LocalDataSource {
18 | return Feature1LocalDataSourceImpl()
19 | }
20 |
21 | @Feature1FragmentScope
22 | @Provides
23 | @JvmStatic
24 | fun provideFeature1Repository(
25 | feature1LocalDataSource: Feature1LocalDataSource
26 | ): Feature1Repository {
27 | return Feature1RepositoryImpl(feature1LocalDataSource)
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/Feature1ViewModelsModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import com.codingwithmitch.daggermultifeature.feature1.di.keys.Feature1ViewModelKey
6 | import com.codingwithmitch.daggermultifeature.feature1.ui.Feature1ViewModel
7 | import com.codingwithmitch.daggermultifeature.feature1.viewmodels.Feature1ViewModelFactory
8 | import dagger.Binds
9 | import dagger.Module
10 | import dagger.multibindings.IntoMap
11 |
12 | @Module
13 | abstract class Feature1ViewModelsModule{
14 |
15 | @Binds
16 | abstract fun bindFeature1VMFactory(factory: Feature1ViewModelFactory): ViewModelProvider.Factory
17 |
18 | @Binds
19 | @IntoMap
20 | @Feature1ViewModelKey(Feature1ViewModel::class)
21 | abstract fun bindFeature1ViewModel(feature1ViewModel: Feature1ViewModel): ViewModel
22 |
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/keys/Feature1FragmentKey.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di.keys
2 |
3 | import androidx.fragment.app.Fragment
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @MapKey
8 | @Target(AnnotationTarget.FUNCTION)
9 | annotation class Feature1FragmentKey(val value: KClass)
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/di/keys/Feature1ViewModelKey.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.di.keys
2 |
3 | import androidx.lifecycle.ViewModel
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @MapKey
8 | @Target(AnnotationTarget.FUNCTION)
9 | annotation class Feature1ViewModelKey(val value: KClass)
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/fragments/Feature1FragmentFactory.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.fragments
2 |
3 | import android.util.Log
4 | import androidx.fragment.app.Fragment
5 | import androidx.fragment.app.FragmentFactory
6 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
7 | import javax.inject.Inject
8 | import javax.inject.Provider
9 |
10 | @Feature1FragmentScope
11 | class Feature1FragmentFactory
12 | @Inject
13 | constructor(
14 | private val creators: Map, @JvmSuppressWildcards Provider>
15 | ) : FragmentFactory() {
16 |
17 | private val TAG: String = "AppDebug"
18 |
19 | override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
20 | val fragmentClass = loadFragmentClass(classLoader, className)
21 | val creator = creators[fragmentClass]
22 | ?: return createFragmentAsFallback(classLoader, className)
23 |
24 | try {
25 | return creator.get()
26 | } catch (e: Exception) {
27 | throw RuntimeException(e)
28 | }
29 | }
30 |
31 | private fun createFragmentAsFallback(classLoader: ClassLoader, className: String): Fragment {
32 | Log.d(TAG, "No creator found for class: $className. Using default constructor")
33 | return super.instantiate(classLoader, className)
34 | }
35 |
36 | companion object{
37 |
38 | const val FRAGMENT_FACTORY_NAME = "Feature1FragmentFactory"
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/fragments/Feature1NavHostFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.fragments
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.util.Log
6 | import androidx.annotation.NavigationRes
7 | import androidx.navigation.fragment.NavHostFragment
8 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
9 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
10 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
11 | import java.lang.ClassCastException
12 | import javax.inject.Inject
13 |
14 | @Feature1FragmentScope
15 | class Feature1NavHostFragment : NavHostFragment(){
16 |
17 | private val TAG: String = "AppDebug"
18 |
19 | lateinit var mainNavController: MainNavController
20 |
21 | @Inject
22 | lateinit var feature1FragmentFactory: Feature1FragmentFactory
23 |
24 | override fun onAttach(context: Context) {
25 | ((activity?.application) as BaseApplication)
26 | .getAppComponent()
27 | .feature1Component()
28 | .create()
29 | .inject(this)
30 | childFragmentManager.fragmentFactory = feature1FragmentFactory
31 | try{
32 | mainNavController = context as MainNavController
33 | }catch (e: ClassCastException){
34 | Log.e(TAG, "$context must implement MainNavController" )
35 | }
36 | super.onAttach(context)
37 | }
38 |
39 | override fun onCreate(savedInstanceState: Bundle?) {
40 | super.onCreate(savedInstanceState)
41 | mainNavController.setNavController(this.navController)
42 | mainNavController.setupNavDrawer()
43 | }
44 |
45 | companion object{
46 |
47 | const val KEY_GRAPH_ID = "android-support-nav:fragment:graphId"
48 |
49 | @JvmStatic
50 | fun create(
51 | @NavigationRes graphId: Int = 0
52 | ): Feature1NavHostFragment{
53 | var bundle: Bundle? = null
54 | if(graphId != 0){
55 | bundle = Bundle()
56 | bundle.putInt(KEY_GRAPH_ID, graphId)
57 | }
58 | val result = Feature1NavHostFragment()
59 | if(bundle != null){
60 | result.arguments = bundle
61 | }
62 | return result
63 | }
64 | }
65 |
66 | }
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/repository/Feature1Repository.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.repository
2 |
3 | interface Feature1Repository {
4 |
5 | suspend fun getFeature1MainString(): String
6 |
7 | suspend fun getFeature1NextString(): String
8 |
9 | suspend fun getFeature1FinalString(): String
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/repository/Feature1RepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.repository
2 |
3 | import com.codingwithmitch.daggermultifeature.feature1.data.Feature1LocalDataSource
4 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
5 | import javax.inject.Inject
6 |
7 | @Feature1FragmentScope
8 | class Feature1RepositoryImpl
9 | @Inject
10 | constructor(
11 | private val feature1LocalDataSource: Feature1LocalDataSource
12 | ): Feature1Repository{
13 |
14 | override suspend fun getFeature1MainString(): String {
15 | return feature1LocalDataSource.getFeature1MainString()
16 | }
17 |
18 | override suspend fun getFeature1NextString(): String {
19 | return feature1LocalDataSource.getFeature1NextString()
20 | }
21 |
22 | override suspend fun getFeature1FinalString(): String {
23 | return feature1LocalDataSource.getFeature1FinalString()
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/ui/Feature1FinalFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.ui
2 |
3 |
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.util.Log
7 | import android.view.View
8 | import androidx.fragment.app.Fragment
9 | import androidx.fragment.app.viewModels
10 | import androidx.lifecycle.Observer
11 |
12 | import com.codingwithmitch.daggermultifeature.R
13 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
14 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
15 | import com.codingwithmitch.daggermultifeature.feature1.viewmodels.Feature1ViewModelFactory
16 | import kotlinx.android.synthetic.main.fragment_feature1_next.fragment_name
17 | import javax.inject.Inject
18 |
19 | class Feature1FinalFragment
20 | @Inject
21 | constructor(
22 | private val viewModelFactory: Feature1ViewModelFactory
23 | ): Fragment(R.layout.fragment_feature1_final) {
24 |
25 | private val TAG: String = "AppDebug"
26 |
27 | val viewModel: Feature1ViewModel by viewModels {
28 | viewModelFactory
29 | }
30 |
31 | lateinit var mainNavController: MainNavController
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 | subscribeObservers()
36 | initUI()
37 | }
38 |
39 | private fun subscribeObservers(){
40 | viewModel.feature1FinalString.observe(viewLifecycleOwner, Observer { finalString ->
41 | fragment_name.text = finalString
42 | })
43 | }
44 |
45 | private fun initUI(){
46 | mainNavController.setDrawerItemChecked(R.id.nav_feature1)
47 | viewModel.retrieveFinalString()
48 | }
49 |
50 | override fun onAttach(context: Context) {
51 | try{
52 | mainNavController = context as MainNavController
53 | }catch(e: ClassCastException){
54 | Log.e(TAG, "$context must implement MainNavController" )
55 | }
56 | super.onAttach(context)
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/ui/Feature1MainFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.ui
2 |
3 |
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.util.Log
7 | import androidx.fragment.app.Fragment
8 | import android.view.View
9 | import androidx.fragment.app.viewModels
10 | import androidx.lifecycle.Observer
11 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
12 |
13 | import com.codingwithmitch.daggermultifeature.R
14 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
15 | import com.codingwithmitch.daggermultifeature.feature1.viewmodels.Feature1ViewModelFactory
16 | import kotlinx.android.synthetic.main.fragment_feature1_main.*
17 | import javax.inject.Inject
18 |
19 | class Feature1MainFragment
20 | @Inject
21 | constructor(
22 | private val viewModelFactory: Feature1ViewModelFactory
23 | ): Fragment(R.layout.fragment_feature1_main) {
24 |
25 | private val TAG: String = "AppDebug"
26 |
27 | val viewModel: Feature1ViewModel by viewModels {
28 | viewModelFactory
29 | }
30 |
31 | lateinit var mainNavController: MainNavController
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 |
36 | btn_go_next.setOnClickListener {
37 | mainNavController.navController().navigate(R.id.action_feature1MainFragment_to_feature1NextFragment)
38 | }
39 |
40 | subscribeObservers()
41 | initUI()
42 | }
43 |
44 | private fun subscribeObservers(){
45 | viewModel.feature1MainString.observe(viewLifecycleOwner, Observer { mainString ->
46 | fragment_name.text = mainString
47 | })
48 | }
49 |
50 | private fun initUI(){
51 | mainNavController.setDrawerItemChecked(R.id.nav_feature1)
52 | viewModel.retrieveMainString()
53 | }
54 |
55 | override fun onAttach(context: Context) {
56 | try{
57 | mainNavController = context as MainNavController
58 | }catch(e: ClassCastException){
59 | Log.e(TAG, "$context must implement MainNavController" )
60 | }
61 | super.onAttach(context)
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/ui/Feature1NextFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.ui
2 |
3 |
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.util.Log
7 | import androidx.fragment.app.Fragment
8 | import android.view.View
9 | import androidx.fragment.app.viewModels
10 | import androidx.lifecycle.Observer
11 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
12 |
13 | import com.codingwithmitch.daggermultifeature.R
14 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
15 | import com.codingwithmitch.daggermultifeature.feature1.viewmodels.Feature1ViewModelFactory
16 | import kotlinx.android.synthetic.main.fragment_feature1_main.fragment_name
17 | import kotlinx.android.synthetic.main.fragment_feature1_next.*
18 | import javax.inject.Inject
19 |
20 | class Feature1NextFragment
21 | @Inject
22 | constructor(
23 | private val viewModelFactory: Feature1ViewModelFactory
24 | ): Fragment(R.layout.fragment_feature1_next) {
25 |
26 | private val TAG: String = "AppDebug"
27 |
28 | val viewModel: Feature1ViewModel by viewModels {
29 | viewModelFactory
30 | }
31 |
32 | lateinit var mainNavController: MainNavController
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 | subscribeObservers()
37 | initUI()
38 |
39 | btn_go_final.setOnClickListener {
40 | mainNavController.navController().navigate(R.id.action_feature1NextFragment_to_feature1FinalFragment)
41 | }
42 | }
43 |
44 | private fun subscribeObservers(){
45 | viewModel.feature1NextString.observe(viewLifecycleOwner, Observer { nextString ->
46 | fragment_name.text = nextString
47 | })
48 | }
49 |
50 | private fun initUI(){
51 | mainNavController.setDrawerItemChecked(R.id.nav_feature1)
52 | viewModel.retrieveNextString()
53 | }
54 |
55 | override fun onAttach(context: Context) {
56 | super.onAttach(context)
57 | try{
58 | mainNavController = context as MainNavController
59 | }catch(e: ClassCastException){
60 | Log.e(TAG, "$context must implement MainNavController" )
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/ui/Feature1ViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.ui
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
8 | import com.codingwithmitch.daggermultifeature.feature1.repository.Feature1Repository
9 | import kotlinx.coroutines.cancel
10 | import kotlinx.coroutines.launch
11 | import javax.inject.Inject
12 |
13 | @Feature1FragmentScope
14 | class Feature1ViewModel
15 | @Inject
16 | constructor(
17 | private val feature1Repository: Feature1Repository
18 | ) : ViewModel(){
19 |
20 |
21 | private val _feature1MainString: MutableLiveData = MutableLiveData()
22 | private val _feature1NextString: MutableLiveData = MutableLiveData()
23 | private val _feature1FinalString: MutableLiveData = MutableLiveData()
24 |
25 | val feature1MainString: LiveData get() = _feature1MainString
26 | val feature1NextString: LiveData get() = _feature1NextString
27 | val feature1FinalString: LiveData get() = _feature1FinalString
28 |
29 | fun retrieveMainString(){
30 | viewModelScope.launch {
31 | val mainString = feature1Repository.getFeature1MainString()
32 | _feature1MainString.value = mainString
33 | }
34 | }
35 |
36 | fun retrieveNextString(){
37 | viewModelScope.launch {
38 | val nextString = feature1Repository.getFeature1NextString()
39 | _feature1NextString.value = nextString
40 | }
41 | }
42 |
43 | fun retrieveFinalString(){
44 | viewModelScope.launch {
45 | val finalString = feature1Repository.getFeature1FinalString()
46 | _feature1FinalString.value = finalString
47 | }
48 | }
49 |
50 | override fun onCleared() {
51 | super.onCleared()
52 | viewModelScope.cancel()
53 | }
54 | }
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/feature1/viewmodels/Feature1ViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.feature1.viewmodels
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import com.codingwithmitch.daggermultifeature.feature1.di.Feature1FragmentScope
6 | import javax.inject.Inject
7 | import javax.inject.Provider
8 |
9 | @Feature1FragmentScope
10 | class Feature1ViewModelFactory
11 | @Inject
12 | constructor(
13 | private val creators: Map, @JvmSuppressWildcards Provider>
14 | ) : ViewModelProvider.Factory {
15 |
16 | override fun create(modelClass: Class): T {
17 | val creator = creators[modelClass] ?: creators.entries.firstOrNull {
18 | modelClass.isAssignableFrom(it.key)
19 | }?.value ?: throw IllegalArgumentException("unknown model class $modelClass")
20 | try {
21 | @Suppress("UNCHECKED_CAST")
22 | return creator.get() as T
23 | } catch (e: Exception) {
24 | throw RuntimeException(e)
25 | }
26 |
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/data/MainLocalDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.data
2 |
3 | interface MainLocalDataSource {
4 |
5 | suspend fun getMainString(): String
6 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/data/MainLocalDataSourceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.data
2 |
3 | import javax.inject.Inject
4 |
5 | class MainLocalDataSourceImpl
6 | @Inject
7 | constructor():
8 | MainLocalDataSource {
9 |
10 | override suspend fun getMainString(): String {
11 | return "MainFragment"
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/MainComponent.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di
2 |
3 | import com.codingwithmitch.daggermultifeature.main.fragments.MainNavHostFragment
4 | import com.codingwithmitch.daggermultifeature.main.ui.MainFragment
5 | import dagger.Subcomponent
6 |
7 |
8 | @MainFragmentScope
9 | @Subcomponent(
10 | modules = [
11 | MainModule::class,
12 | ViewModelModule::class,
13 | MainFragmentBuildersModule::class
14 | ]
15 | )
16 | interface MainComponent {
17 |
18 | @Subcomponent.Factory
19 | interface Factory{
20 |
21 | fun create(): MainComponent
22 | }
23 |
24 | fun inject(mainNavHostFragment: MainNavHostFragment)
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/MainFragmentBuildersModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di
2 |
3 | import androidx.fragment.app.Fragment
4 | import androidx.fragment.app.FragmentFactory
5 | import com.codingwithmitch.daggermultifeature.main.di.keys.MainFragmentKey
6 | import com.codingwithmitch.daggermultifeature.main.fragments.MainFragmentFactory
7 | import com.codingwithmitch.daggermultifeature.main.fragments.MainNavHostFragment
8 | import com.codingwithmitch.daggermultifeature.main.ui.MainFragment
9 | import dagger.Binds
10 | import dagger.Module
11 | import dagger.multibindings.IntoMap
12 |
13 | @Module
14 | abstract class MainFragmentBuildersModule {
15 |
16 | @Binds
17 | abstract fun bindFragmentFactory(mainFragmentFactory: MainFragmentFactory): FragmentFactory
18 |
19 | @Binds
20 | @IntoMap
21 | @MainFragmentKey(MainFragment::class)
22 | abstract fun bindMainFragment(mainFragment: MainFragment): Fragment
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/MainFragmentScope.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di
2 |
3 | import javax.inject.Scope
4 |
5 | @Scope
6 | @Retention(value = AnnotationRetention.RUNTIME)
7 | annotation class MainFragmentScope
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/MainModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di
2 |
3 | import com.codingwithmitch.daggermultifeature.main.data.MainLocalDataSource
4 | import com.codingwithmitch.daggermultifeature.main.data.MainLocalDataSourceImpl
5 | import com.codingwithmitch.daggermultifeature.main.repository.MainRepository
6 | import com.codingwithmitch.daggermultifeature.main.repository.MainRepositoryImpl
7 | import dagger.Module
8 | import dagger.Provides
9 |
10 | @Module
11 | object MainModule {
12 |
13 | @MainFragmentScope
14 | @Provides
15 | @JvmStatic
16 | fun provideMainLocalDataSource(): MainLocalDataSource {
17 | return MainLocalDataSourceImpl()
18 | }
19 |
20 | @MainFragmentScope
21 | @Provides
22 | @JvmStatic
23 | fun provideMainRepository(localDataSource: MainLocalDataSource): MainRepository {
24 | return MainRepositoryImpl(
25 | localDataSource
26 | )
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/ViewModelModule.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import com.codingwithmitch.daggermultifeature.main.di.keys.MainViewModelKey
6 | import com.codingwithmitch.daggermultifeature.main.ui.MainViewModel
7 | import com.codingwithmitch.daggermultifeature.main.viewmodels.MainViewModelFactory
8 | import dagger.Binds
9 | import dagger.Module
10 | import dagger.multibindings.IntoMap
11 |
12 | @Module
13 | abstract class ViewModelModule{
14 |
15 | @Binds
16 | abstract fun bindViewModelFactory(factory: MainViewModelFactory): ViewModelProvider.Factory
17 |
18 | @Binds
19 | @IntoMap
20 | @MainViewModelKey(MainViewModel::class)
21 | abstract fun bindMainViewModel(viewModel: MainViewModel): ViewModel
22 |
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/keys/MainFragmentKey.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di.keys
2 |
3 | import androidx.fragment.app.Fragment
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @MapKey
8 | @Target(AnnotationTarget.FUNCTION)
9 | annotation class MainFragmentKey(val value: KClass)
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/di/keys/MainViewModelKey.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.di.keys
2 |
3 | import androidx.lifecycle.ViewModel
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @MapKey
8 | @Target(AnnotationTarget.FUNCTION)
9 | annotation class MainViewModelKey(val value: KClass)
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/fragments/MainFragmentFactory.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.fragments
2 |
3 | import android.util.Log
4 | import androidx.fragment.app.Fragment
5 | import androidx.fragment.app.FragmentFactory
6 | import com.codingwithmitch.daggermultifeature.main.di.MainFragmentScope
7 | import javax.inject.Inject
8 | import javax.inject.Provider
9 |
10 | @MainFragmentScope
11 | class MainFragmentFactory
12 | @Inject
13 | constructor(
14 | private val creators: Map, @JvmSuppressWildcards Provider>
15 | ) : FragmentFactory() {
16 |
17 | private val TAG: String = "AppDebug"
18 |
19 | override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
20 | val fragmentClass = loadFragmentClass(classLoader, className)
21 | val creator = creators[fragmentClass]
22 | ?: return createFragmentAsFallback(classLoader, className)
23 |
24 | try {
25 | return creator.get()
26 | } catch (e: Exception) {
27 | throw RuntimeException(e)
28 | }
29 | }
30 |
31 | private fun createFragmentAsFallback(classLoader: ClassLoader, className: String): Fragment {
32 | Log.d(TAG, "No creator found for class: $className. Using default constructor")
33 | return super.instantiate(classLoader, className)
34 | }
35 |
36 | companion object{
37 |
38 | const val FRAGMENT_FACTORY_NAME = "MainFragmentFactory"
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/fragments/MainNavHostFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.fragments
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.util.Log
6 | import androidx.annotation.NavigationRes
7 | import androidx.navigation.fragment.NavHostFragment
8 | import com.codingwithmitch.daggermultifeature.app.BaseApplication
9 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
10 | import com.codingwithmitch.daggermultifeature.main.di.MainFragmentScope
11 | import java.lang.ClassCastException
12 | import javax.inject.Inject
13 |
14 | @MainFragmentScope
15 | class MainNavHostFragment : NavHostFragment(){
16 |
17 | private val TAG: String = "AppDebug"
18 |
19 | lateinit var mainNavController: MainNavController
20 |
21 | @Inject
22 | lateinit var mainFragmentFactory: MainFragmentFactory
23 |
24 | override fun onAttach(context: Context) {
25 | ((activity?.application) as BaseApplication)
26 | .getAppComponent()
27 | .mainComponent()
28 | .create()
29 | .inject(this)
30 |
31 | childFragmentManager.fragmentFactory = mainFragmentFactory
32 | try{
33 | mainNavController = context as MainNavController
34 | }catch (e: ClassCastException){
35 | Log.e(TAG, "$context must implement MainNavController" )
36 | }
37 | super.onAttach(context)
38 | }
39 |
40 | override fun onCreate(savedInstanceState: Bundle?) {
41 | super.onCreate(savedInstanceState)
42 | mainNavController.setNavController(this.navController)
43 | mainNavController.setupNavDrawer()
44 | }
45 |
46 | companion object{
47 |
48 | const val KEY_GRAPH_ID = "android-support-nav:fragment:graphId"
49 |
50 | @JvmStatic
51 | fun create(
52 | @NavigationRes graphId: Int = 0
53 | ): MainNavHostFragment {
54 | var bundle: Bundle? = null
55 | if(graphId != 0){
56 | bundle = Bundle()
57 | bundle.putInt(KEY_GRAPH_ID, graphId)
58 | }
59 | val result = MainNavHostFragment()
60 | if(bundle != null){
61 | result.arguments = bundle
62 | }
63 | return result
64 | }
65 | }
66 | }
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/repository/MainRepository.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.repository
2 |
3 | interface MainRepository {
4 |
5 | suspend fun getHomeString(): String
6 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/repository/MainRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.repository
2 |
3 | import com.codingwithmitch.daggermultifeature.main.data.MainLocalDataSource
4 | import javax.inject.Inject
5 |
6 |
7 | class MainRepositoryImpl
8 | @Inject
9 | constructor(
10 | private val localDataSource: MainLocalDataSource
11 | ) : MainRepository {
12 |
13 | override suspend fun getHomeString(): String {
14 | return localDataSource.getMainString()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/ui/MainFragment.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.ui
2 |
3 |
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.util.Log
7 | import androidx.fragment.app.Fragment
8 | import android.view.View
9 | import androidx.fragment.app.viewModels
10 | import androidx.lifecycle.Observer
11 |
12 | import com.codingwithmitch.daggermultifeature.R
13 | import com.codingwithmitch.daggermultifeature.app.ui.MainNavController
14 | import com.codingwithmitch.daggermultifeature.main.viewmodels.MainViewModelFactory
15 | import kotlinx.android.synthetic.main.fragment_main.*
16 | import javax.inject.Inject
17 | import javax.inject.Named
18 |
19 | class MainFragment
20 | @Inject
21 | constructor(
22 | private val viewModelFactory: MainViewModelFactory,
23 | private @Named("application_name") val applicationName: String
24 | ): Fragment(R.layout.fragment_main){
25 |
26 | private val TAG: String = "AppDebug"
27 |
28 | val viewModel: MainViewModel by viewModels {
29 | viewModelFactory
30 | }
31 |
32 | lateinit var mainNavController: MainNavController
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | btn_go_feature1.setOnClickListener {
38 | mainNavController.navFeature1()
39 | }
40 |
41 | subscribeObservers()
42 | initUI()
43 | }
44 |
45 | private fun subscribeObservers(){
46 | viewModel.homeString.observe(viewLifecycleOwner, Observer { homeString ->
47 | fragment_name.text = homeString
48 | })
49 | }
50 |
51 | private fun initUI(){
52 | mainNavController.setDrawerItemChecked(R.id.nav_main)
53 | main_header.text = applicationName
54 | viewModel.retrieveHomeString()
55 | }
56 |
57 | override fun onAttach(context: Context) {
58 | super.onAttach(context)
59 | try{
60 | mainNavController = context as MainNavController
61 | }catch(e: ClassCastException){
62 | Log.e(TAG, "$context must implement MainNavController" )
63 | }
64 | }
65 |
66 | }
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/ui/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.ui
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.codingwithmitch.daggermultifeature.main.di.MainFragmentScope
8 | import com.codingwithmitch.daggermultifeature.main.repository.MainRepository
9 | import kotlinx.coroutines.cancel
10 | import kotlinx.coroutines.launch
11 | import javax.inject.Inject
12 |
13 | @MainFragmentScope
14 | class MainViewModel
15 | @Inject
16 | constructor(
17 | private val homeRepository: MainRepository
18 | ) : ViewModel(){
19 |
20 | private val _homeString: MutableLiveData = MutableLiveData()
21 |
22 | val homeString: LiveData get() = _homeString
23 |
24 | fun retrieveHomeString(){
25 | viewModelScope.launch {
26 | val homeString = homeRepository.getHomeString()
27 | _homeString.value = homeString
28 | }
29 | }
30 |
31 | override fun onCleared() {
32 | super.onCleared()
33 | viewModelScope.cancel()
34 | }
35 | }
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingwithmitch/daggermultifeature/main/viewmodels/MainViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature.main.viewmodels
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import javax.inject.Inject
6 | import javax.inject.Provider
7 | import javax.inject.Singleton
8 |
9 | class MainViewModelFactory
10 | @Inject
11 | constructor(
12 | private val creators: Map, @JvmSuppressWildcards Provider>
13 | ) : ViewModelProvider.Factory{
14 |
15 | override fun create(modelClass: Class): T {
16 | val creator = creators[modelClass] ?: creators.entries.firstOrNull {
17 | modelClass.isAssignableFrom(it.key)
18 | }?.value ?: throw IllegalArgumentException("unknown model class $modelClass")
19 | try {
20 | @Suppress("UNCHECKED_CAST")
21 | return creator.get() as T
22 | } catch (e: Exception) {
23 | throw RuntimeException(e)
24 | }
25 |
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_accessibility_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_android_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_feature1_final.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_feature1_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_feature1_next.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
33 |
34 |
44 |
45 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/drawer_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/navigation/feature1_nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
22 |
27 |
30 |
31 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/main_nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DaggerMultiFeature
3 |
4 | fragment_factory
5 |
6 | NavHostFragment
7 |
8 |
9 | Hello blank fragment
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/codingwithmitch/daggermultifeature/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.codingwithmitch.daggermultifeature
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.61'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.3'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 |
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | #org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | # AndroidX package structure to make it clearer which packages are bundled with the
20 | # Android operating system, and which are packaged with your app's APK
21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
22 | android.useAndroidX=true
23 | # Automatically convert third-party libraries to use AndroidX
24 | android.enableJetifier=true
25 |
26 | # Kotlin code style for this project: "official" or "obsolete":
27 | kotlin.code.style=official
28 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchtabian/DaggerMultiFeature/9c27df0ab6e091ce52193685425a9dd9161fd779/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 08 10:16:08 PST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='DaggerMultiFeature'
3 |
--------------------------------------------------------------------------------