-
Notifications
You must be signed in to change notification settings - Fork 36
dagger 2 injection migrated to hilt #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,7 @@ | ||
| package co.icanteach.projectx | ||
|
|
||
| import android.app.Activity | ||
| import android.app.Application | ||
| import co.icanteach.projectx.common.di.component.DaggerAppComponent | ||
| import dagger.android.AndroidInjector | ||
| import dagger.android.DispatchingAndroidInjector | ||
| import dagger.android.HasActivityInjector | ||
| import javax.inject.Inject | ||
| import dagger.hilt.android.HiltAndroidApp | ||
|
|
||
| class InterviewApplication : Application(), HasActivityInjector { | ||
|
|
||
| @Inject | ||
| internal lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity> | ||
|
|
||
| override fun activityInjector(): AndroidInjector<Activity> { | ||
| return dispatchingAndroidInjector | ||
| } | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
|
|
||
| DaggerAppComponent | ||
| .factory() | ||
| .create(this) | ||
| .inject(this) | ||
| } | ||
| } | ||
| @HiltAndroidApp | ||
| class InterviewApplication : Application() |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,12 @@ import co.icanteach.projectx.common.di.key.ViewModelKey | |
| import co.icanteach.projectx.ui.populartvshows.PopularTVShowsViewModel | ||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.components.ApplicationComponent | ||
| import dagger.multibindings.IntoMap | ||
|
|
||
| @Module | ||
| @InstallIn(ApplicationComponent::class) | ||
| interface ViewModelModule { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be nice if ViewModel is also migrated to Hilt? https://developer.android.com/training/dependency-injection/hilt-jetpack |
||
|
|
||
| @get:IntoMap | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ package co.icanteach.projectx.data | |
|
|
||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.components.ApplicationComponent | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.logging.HttpLoggingInterceptor | ||
| import retrofit2.Retrofit | ||
|
|
@@ -11,6 +13,7 @@ import retrofit2.create | |
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(ApplicationComponent::class) | ||
| class NetworkModule { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of class, using object is better for here from the performance point of view. |
||
| @Provides | ||
| @Singleton | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,11 @@ package co.icanteach.projectx.ui.populartvshows | |
| import co.icanteach.projectx.common.di.scope.ActivityScope | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.components.ActivityComponent | ||
|
|
||
| @Module | ||
| @InstallIn(ActivityComponent::class) | ||
| class PopularTvShowActivityModule { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this Module by @ActivityScoped
class PopularTVShowsFeedAdapter @Inject constructor() :
RecyclerView.Adapter<PopularTVShowsFeedAdapter.PopularTVShowsFeedItemViewHolder>() {
|
||
|
|
||
| @ActivityScope | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| object Classpaths { | ||
| val gradleClasspath = "com.android.tools.build:gradle:${Versions.gradleVersion}" | ||
| val kotlinGradleClasspath = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}" | ||
| val gradleVersionPlugin = "com.github.ben-manes:gradle-versions-plugin:${Versions.gradleVersionPluginVersion}" | ||
| val kotlinGradleClasspath = | ||
| "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting of |
||
| val gradleVersionPlugin = | ||
| "com.github.ben-manes:gradle-versions-plugin:${Versions.gradleVersionPluginVersion}" | ||
| val hilt = "com.google.dagger:hilt-android-gradle-plugin:${Versions.hiltVersion}" | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: needless empty space There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also in:
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME | |
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly recommend you to open another PR for that change as it effects all of project. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataModule is not needed and can be deleted.