Skip to content

Commit f41e840

Browse files
author
Vimalraj Vijay
committed
Dependencies updated
1 parent da546de commit f41e840

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

app/build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ dependencies {
3939
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4040
implementation 'androidx.core:core-ktx:1.3.2'
4141
implementation 'androidx.appcompat:appcompat:1.2.0'
42-
implementation 'com.google.android.material:material:1.2.1'
42+
implementation 'com.google.android.material:material:1.3.0'
4343
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
44-
testImplementation 'junit:junit:4.+'
44+
45+
// Unit testing
46+
testImplementation 'junit:junit:4.12'
47+
testImplementation 'org.mockito:mockito-core:1.10.19'
4548
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4649
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
4750

@@ -63,11 +66,11 @@ dependencies {
6366
implementation "com.squareup.okhttp3:logging-interceptor:3.4.1"
6467

6568
//Gson
66-
implementation 'com.google.code.gson:gson:2.8.5'
69+
implementation 'com.google.code.gson:gson:2.8.6'
6770
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
6871

6972
// Coroutines
70-
def kotlinCoroutineVersion = "1.3.0"
73+
def kotlinCoroutineVersion = "1.3.4"
7174
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutineVersion"
7275
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutineVersion"
7376

@@ -76,7 +79,7 @@ dependencies {
7679
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
7780

7881
// View Model For Hilt
79-
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02'
80-
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'
82+
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
83+
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha03'
8184

8285
}

app/src/main/java/com/vimalvijay/mymodule/main/repository/MainRepository.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class MainRepository @Inject constructor(var apiService: ApiService) : BaseRepos
1212
* Get Hero List from Api
1313
*/
1414
suspend fun getHerosList(): MutableList<Hero.HeroItem>? {
15-
1615
val heroResponse = safeApiRequest(
1716
call = { apiService.getHeroes().await() })
1817
return heroResponse?.toMutableList()
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
package com.vimalvijay.mymodule.main.viewmodel
22

3-
import androidx.hilt.lifecycle.ViewModelInject
4-
import androidx.lifecycle.MutableLiveData
53
import androidx.lifecycle.ViewModel
64
import androidx.lifecycle.liveData
7-
import com.vimalvijay.mymodule.main.model.Hero
85
import com.vimalvijay.mymodule.main.repository.MainRepository
96
import com.vimalvijay.mymodule.network.responsehandler.Resource
10-
import kotlinx.coroutines.CoroutineScope
7+
import dagger.hilt.android.lifecycle.HiltViewModel
118
import kotlinx.coroutines.Dispatchers
129
import kotlinx.coroutines.Job
13-
import kotlinx.coroutines.cancel
10+
import javax.inject.Inject
1411
import kotlin.coroutines.CoroutineContext
1512

16-
class MainViewModel @ViewModelInject constructor(private var mainRepository: MainRepository) :
13+
@HiltViewModel
14+
class MainViewModel @Inject constructor(private var mainRepository: MainRepository) :
1715
ViewModel() {
1816

1917
private val parentJob = Job()
2018

2119
private val coroutineContext: CoroutineContext
2220
get() = parentJob + Dispatchers.IO
2321

24-
private val scope = CoroutineScope(coroutineContext)
25-
26-
val heroListLiveData = MutableLiveData<MutableList<Hero.HeroItem>>()
27-
2822
/**
29-
* Launch API using Coroutines
23+
* Launch API using liveData
3024
*/
3125
fun heroListLiveData() = liveData(coroutineContext) {
3226
emit(Resource.loading(data = null))
@@ -37,8 +31,4 @@ class MainViewModel @ViewModelInject constructor(private var mainRepository: Mai
3731
e.printStackTrace()
3832
}
3933
}
40-
41-
fun cancelAllRequest() {
42-
coroutineContext.cancel()
43-
}
4434
}

0 commit comments

Comments
 (0)