├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_second.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_second.xml │ │ │ │ └── fragment_first.xml │ │ │ ├── navigation │ │ │ │ └── nav_graph.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── aakira │ │ │ │ └── hilt │ │ │ │ ├── App.kt │ │ │ │ ├── data │ │ │ │ └── SampleRepository.kt │ │ │ │ ├── di │ │ │ │ ├── qualifiers │ │ │ │ │ ├── AppHash.kt │ │ │ │ │ ├── ActivityHash.kt │ │ │ │ │ └── FragmentHash.kt │ │ │ │ └── module │ │ │ │ │ ├── ActivityModule.kt │ │ │ │ │ ├── ApplicationModule.kt │ │ │ │ │ └── FragmentModule.kt │ │ │ │ └── ui │ │ │ │ ├── main │ │ │ │ ├── MainViewModel.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── MainSecondFragment.kt │ │ │ │ └── MainFirstFragment.kt │ │ │ │ └── second │ │ │ │ └── SecondActivity.kt │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── github │ │ └── aakira │ │ └── hilt │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── art └── dagger-example-architecture.jpg ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml └── jarRepositories.xml ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "DaggerHiltExample" 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /art/dagger-example-architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/art/dagger-example-architecture.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AAkira/dagger-hilt-example/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/App.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class App : Application() 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/data/SampleRepository.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.data 2 | 3 | import javax.inject.Inject 4 | import javax.inject.Singleton 5 | 6 | @Singleton 7 | class SampleRepository @Inject constructor() { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/qualifiers/AppHash.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.qualifiers 2 | 3 | import javax.inject.Qualifier 4 | 5 | @Qualifier 6 | @Retention(AnnotationRetention.RUNTIME) 7 | internal annotation class AppHash 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/qualifiers/ActivityHash.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.qualifiers 2 | 3 | import javax.inject.Qualifier 4 | 5 | @Qualifier 6 | @Retention(AnnotationRetention.RUNTIME) 7 | internal annotation class ActivityHash 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/qualifiers/FragmentHash.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.qualifiers 2 | 3 | import javax.inject.Qualifier 4 | 5 | @Qualifier 6 | @Retention(AnnotationRetention.RUNTIME) 7 | internal annotation class FragmentHash 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 30 06:06:11 JST 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-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dagger Android Hilt Example 2 | 3 | This repository is an example of the dagger android hilt plugin using an android view model. 4 | 5 | ## Architecture 6 | 7 | This app has two activities and two fragments. 8 | The architecture is below the image. 9 | 10 | ![ExampleArchitecture](/art/dagger-example-architecture.jpg) 11 | 12 | ## Blog post 13 | 14 | I'm sorry for this post being in Japanese only. 15 | 16 | http://aakira.app/blog/2020/05/dagger-hilt/ 17 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DaggerHiltExample 3 | 4 | 5 | First Fragment 6 | Second Fragment 7 | 8 | Hello first fragment 9 | Hello second fragment. Arg: %1$s 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/module/ActivityModule.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.module 2 | 3 | import com.github.aakira.hilt.di.qualifiers.ActivityHash 4 | import dagger.Module 5 | import dagger.Provides 6 | import dagger.hilt.InstallIn 7 | import dagger.hilt.android.components.ActivityComponent 8 | 9 | @Module 10 | @InstallIn(ActivityComponent::class) 11 | class ActivityModule { 12 | @ActivityHash 13 | @Provides 14 | fun provideHash(): String { 15 | return hashCode().toString() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/module/ApplicationModule.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.module 2 | 3 | import com.github.aakira.hilt.di.qualifiers.AppHash 4 | import dagger.Module 5 | import dagger.Provides 6 | import dagger.hilt.InstallIn 7 | import dagger.hilt.android.components.ApplicationComponent 8 | 9 | @Module 10 | @InstallIn(ApplicationComponent::class) 11 | class ApplicationModule { 12 | @AppHash 13 | @Provides 14 | fun provideHash(): String { 15 | return hashCode().toString() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/di/module/FragmentModule.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.di.module 2 | 3 | import com.github.aakira.hilt.di.qualifiers.FragmentHash 4 | import dagger.Module 5 | import dagger.Provides 6 | import dagger.hilt.InstallIn 7 | import dagger.hilt.android.components.FragmentComponent 8 | 9 | @Module 10 | @InstallIn(FragmentComponent::class) 11 | class FragmentModule { 12 | @FragmentHash 13 | @Provides 14 | fun provideHash(): String { 15 | return hashCode().toString() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/aakira/hilt/ui/main/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.github.aakira.hilt.ui.main 2 | 3 | import androidx.hilt.Assisted 4 | import androidx.hilt.lifecycle.ViewModelInject 5 | import androidx.lifecycle.SavedStateHandle 6 | import androidx.lifecycle.ViewModel 7 | import com.github.aakira.hilt.data.SampleRepository 8 | 9 | class MainViewModel @ViewModelInject constructor( 10 | private val repository: SampleRepository, 11 | @Assisted private val savedState: SavedStateHandle 12 | ) : ViewModel() { 13 | 14 | fun getRepositoryHash(): String = repository.toString() 15 | } 16 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 |