Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: Plugins.androidApplication
apply plugin: Plugins.kotlinAndroid
apply plugin: Plugins.kotlinKapt
apply plugin: Plugins.kotlinAndroidExtensions
apply plugin: Plugins.hilt

android {
compileSdkVersion Configs.compileSdkVersion
Expand Down Expand Up @@ -34,10 +35,8 @@ dependencies {
implementation Dependencies.material

// dagger
implementation Dependencies.dagger
implementation Dependencies.daggerAndroid
kapt Dependencies.daggerCompiler
kapt Dependencies.daggerProcessor
implementation Dependencies.hiltAndroid
kapt Dependencies.hiltAndroidCompiler

// Retrofit & Gson.
implementation Dependencies.retrofit
Expand Down
27 changes: 3 additions & 24 deletions app/src/main/java/co/icanteach/projectx/InterviewApplication.kt
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()
5 changes: 2 additions & 3 deletions app/src/main/java/co/icanteach/projectx/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import co.icanteach.projectx.ui.populartvshows.PopularTVShowsFeedAdapter
import co.icanteach.projectx.ui.populartvshows.PopularTVShowsStatusViewState
import co.icanteach.projectx.ui.populartvshows.PopularTVShowsViewModel
import co.icanteach.projectx.ui.populartvshows.model.PopularTvShowItem
import dagger.android.AndroidInjection
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject


@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

@Inject
Expand All @@ -29,7 +29,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)

binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package co.icanteach.projectx.common.di.module

import co.icanteach.projectx.data.NetworkModule
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent

@Module(
includes = [NetworkModule::class]
)
class DataModule {
}

@InstallIn(ApplicationComponent::class)
class DataModule
Copy link
Copy Markdown

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.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/co/icanteach/projectx/data/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,6 +13,7 @@ import retrofit2.create
import javax.inject.Singleton

@Module
@InstallIn(ApplicationComponent::class)
class NetworkModule {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
classpath Classpaths.gradleClasspath
classpath Classpaths.kotlinGradleClasspath
classpath Classpaths.gradleVersionPlugin
classpath Classpaths.hilt
}
}

Expand Down
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}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of kotlinGradleClasspath and gradleVersionPlugin is different from previous commits. These may be fit 1 line as other dependencies.

val gradleVersionPlugin =
"com.github.ben-manes:gradle-versions-plugin:${Versions.gradleVersionPluginVersion}"
val hilt = "com.google.dagger:hilt-android-gradle-plugin:${Versions.hiltVersion}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: needless empty space

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in:

  • buildSrc/src/main/java/co/icanteach/projectx/buildsrc/Plugins.kt
  • buildSrc/src/main/java/co/icanteach/projectx/buildsrc/Versions.kt

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ object Dependencies {
val mockK = "io.mockk:mockk:${Versions.mockKVersion}"
val coreTesting = "androidx.arch.core:core-testing:${Versions.coreTestingVersion}"
val material = "com.google.android.material:material:${Versions.materialVersion}"
val hiltAndroid = "com.google.dagger:hilt-android:${Versions.hiltVersion}"
val hiltAndroidCompiler = "com.google.dagger:hilt-android-compiler:${Versions.hiltVersion}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ object Plugins {
val kotlinKapt = "kotlin-kapt"
val kotlinAndroidExtensions = "kotlin-android-extensions"
val gradleVersionPlugin = "com.github.ben-manes.versions"
val hilt = "dagger.hilt.android.plugin"

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ object Versions {
val coreTestingVersion = "2.0.0"
val materialVersion = "1.2.0-alpha01"
val gradleVersionPluginVersion = "0.27.0"
val hiltVersion = "2.28.1-alpha"

}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.