Skip to content

Commit 9199592

Browse files
Kishan Kumar MauryaKishan Kumar Maurya
Kishan Kumar Maurya
authored and
Kishan Kumar Maurya
committed
Android Dagger Hild migration & basic setup, some libary version update
1 parent 78fa6be commit 9199592

25 files changed

+142
-237
lines changed

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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-
apply plugin: 'de.mannodermaus.android-junit5'
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
id 'kotlin-android-extensions'
5+
id 'kotlin-kapt'
6+
id 'de.mannodermaus.android-junit5'
7+
id 'dagger.hilt.android.plugin'
8+
}
99

1010
android {
11-
compileSdkVersion 29
12-
buildToolsVersion "29.0.2"
11+
compileSdkVersion 30
12+
buildToolsVersion "29.0.3"
1313
defaultConfig {
1414
applicationId "com.example.githubfirebaseissue"
1515
minSdkVersion 21
16-
targetSdkVersion 29
16+
targetSdkVersion 30
1717
versionCode 1
1818
versionName "1.0"
1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -49,7 +49,7 @@ android {
4949
dependencies {
5050
implementation fileTree(dir: 'libs', include: ['*.jar'])
5151
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
52-
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
52+
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
5353

5454
api "androidx.appcompat:appcompat:$appcompat_version"
5555
api "androidx.constraintlayout:constraintlayout:$androidx_constraint_layout_version"
@@ -66,7 +66,7 @@ dependencies {
6666
api "com.squareup.retrofit2:converter-gson:$retrofit_version"
6767
api "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
6868
api 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
69-
api "com.squareup.okhttp3:okhttp:4.3.1"
69+
api "com.squareup.okhttp3:okhttp:4.6.0"
7070
api "com.squareup.okhttp3:logging-interceptor:$logging_interceptor_version"
7171

7272
api "com.github.bumptech.glide:glide:$glide_version"
@@ -87,7 +87,7 @@ dependencies {
8787
api "com.google.code.gson:gson:$gson_version"
8888

8989
//shimmer
90-
api 'com.facebook.shimmer:shimmer:0.1.0@aar'
90+
api 'com.facebook.shimmer:shimmer:0.5.0@aar'
9191

9292
// dagger
9393
implementation "com.google.dagger:dagger:$dagger_version"
@@ -102,11 +102,15 @@ dependencies {
102102
testImplementation "com.jraska.livedata:testing-ktx:$jraska_version"
103103
testImplementation "junit:junit:$junit_version"
104104
testImplementation "org.mockito:mockito-inline:$mockito_version"
105-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
105+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.1'
106106
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
107107
testImplementation "org.hamcrest:hamcrest-library:$hamcrest_version"
108108
testImplementation "com.google.truth:truth:1.0"
109109

110+
//hilt
111+
implementation "com.google.dagger:hilt-android:$hilt_version"
112+
kapt "com.google.dagger:hilt-compiler:$hilt_version"
113+
110114
//Spek
111115
testImplementation 'org.junit.platform:junit-platform-engine:1.6.2'
112116
testImplementation 'org.jetbrains.spek:spek-api:1.1.5'
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.example.githubfirebaseissue
22

3-
import com.example.githubfirebaseissue.di.component.DaggerApplicationComponent
4-
import dagger.android.AndroidInjector
5-
import dagger.android.DaggerApplication
3+
import android.app.Application
4+
import dagger.hilt.android.HiltAndroidApp
65

76

8-
class GithubApplication : DaggerApplication() {
9-
10-
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
11-
return DaggerApplicationComponent.factory().create(this)
12-
}
13-
}
7+
@HiltAndroidApp
8+
class GithubApplication : Application()

app/src/main/java/com/example/githubfirebaseissue/base/BaseActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.example.githubfirebaseissue.base
22

33
import android.os.Bundle
4-
import dagger.android.AndroidInjection
4+
import androidx.appcompat.app.AppCompatActivity
55
import androidx.fragment.app.Fragment
6-
import dagger.android.support.DaggerAppCompatActivity
6+
import dagger.hilt.android.AndroidEntryPoint
77

88

9-
abstract class BaseActivity : DaggerAppCompatActivity() {
9+
abstract class BaseActivity : AppCompatActivity() {
1010

1111
override fun onCreate(savedInstanceState: Bundle?) {
12-
AndroidInjection.inject(this)
1312
super.onCreate(savedInstanceState)
1413
setContentView(getLayoutRes())
1514
}

app/src/main/java/com/example/githubfirebaseissue/base/BaseFragment.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import android.widget.TextView
1010
import android.widget.Toast
1111
import androidx.fragment.app.Fragment
1212
import com.example.githubfirebaseissue.R
13-
import dagger.android.support.AndroidSupportInjection
1413
import okio.IOException
1514
import retrofit2.HttpException
1615

1716

1817
abstract class BaseFragment : Fragment() {
1918

2019
override fun onCreate(savedInstanceState: Bundle?) {
21-
AndroidSupportInjection.inject(this)
2220
super.onCreate(savedInstanceState)
2321
}
2422

app/src/main/java/com/example/githubfirebaseissue/base/CustomViewModelFactory.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/src/main/java/com/example/githubfirebaseissue/common/BaseSchedulerProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.example.githubfirebaseissue.common
33
import io.reactivex.Scheduler
44
import io.reactivex.android.schedulers.AndroidSchedulers
55
import io.reactivex.schedulers.Schedulers
6+
import javax.inject.Inject
67

78
interface RxScheduler {
89
val io: Scheduler
910
val main: Scheduler
1011
}
1112

12-
class BaseSchedulerProvider: RxScheduler {
13+
class BaseSchedulerProvider @Inject constructor() : RxScheduler {
1314
override val io: Scheduler
1415
get() = Schedulers.io()
1516
override val main: Scheduler
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
package com.example.githubfirebaseissue.di.component
22

3-
import com.example.githubfirebaseissue.GithubApplication
43
import com.example.githubfirebaseissue.di.module.ApiModule
5-
import com.example.githubfirebaseissue.di.module.ActivityBindingModule
6-
import com.example.githubfirebaseissue.di.module.ViewModelModule
7-
import com.example.githubfirebaseissue.di.scope.AppScope
84
import dagger.Component
9-
import dagger.android.AndroidInjector
10-
import dagger.android.support.AndroidSupportInjectionModule
5+
import javax.inject.Singleton
116

12-
@AppScope
13-
@Component(
14-
modules = [
15-
AndroidSupportInjectionModule::class,
16-
ActivityBindingModule::class,
17-
ViewModelModule::class,
18-
ApiModule::class]
19-
)
20-
interface ApplicationComponent : AndroidInjector<GithubApplication> {
21-
22-
@Component.Factory
23-
abstract class Builder: AndroidInjector.Factory<GithubApplication>
24-
}
7+
@Singleton
8+
@Component(modules = [ApiModule::class])
9+
interface ApplicationComponent

app/src/main/java/com/example/githubfirebaseissue/di/module/ActivityBindingModule.kt

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/src/main/java/com/example/githubfirebaseissue/di/module/ApiModule.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@ import com.example.githubfirebaseissue.api.ApiConstant
44
import com.example.githubfirebaseissue.api.GithubApi
55
import com.example.githubfirebaseissue.common.BaseSchedulerProvider
66
import com.example.githubfirebaseissue.common.RxScheduler
7+
import dagger.Binds
78
import dagger.Module
89
import dagger.Provides
10+
import dagger.hilt.InstallIn
11+
import dagger.hilt.components.SingletonComponent
912
import okhttp3.OkHttpClient
1013
import retrofit2.Retrofit
1114
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
1215
import retrofit2.converter.gson.GsonConverterFactory
1316

14-
17+
@InstallIn(SingletonComponent::class)
1518
@Module(includes = [InterceptorModule::class, RepositoryModule::class])
16-
class ApiModule {
19+
abstract class ApiModule {
1720

18-
@Provides
19-
fun provideRetrofit(client: OkHttpClient): Retrofit {
20-
return Retrofit.Builder()
21-
.baseUrl(ApiConstant.GITHUB_BASE_URL)
22-
.addConverterFactory(GsonConverterFactory.create())
23-
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
24-
.client(client)
25-
.build()
26-
}
21+
companion object {
22+
@Provides
23+
fun provideRetrofit(client: OkHttpClient): Retrofit {
24+
return Retrofit.Builder()
25+
.baseUrl(ApiConstant.GITHUB_BASE_URL)
26+
.addConverterFactory(GsonConverterFactory.create())
27+
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
28+
.client(client)
29+
.build()
30+
}
2731

28-
@Provides
29-
fun provideApiInterface(retrofit: Retrofit): GithubApi {
30-
return retrofit.create(GithubApi::class.java)
32+
@Provides
33+
fun provideApiInterface(retrofit: Retrofit): GithubApi {
34+
return retrofit.create(GithubApi::class.java)
35+
}
3136
}
3237

33-
@Provides
34-
fun provideRxScheduler(): RxScheduler {
35-
return BaseSchedulerProvider()
36-
}
38+
@Binds
39+
abstract fun provideRxScheduler(scheduler: BaseSchedulerProvider): RxScheduler
3740
}

app/src/main/java/com/example/githubfirebaseissue/di/module/FragmentProviderModule.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)