File tree 12 files changed +28
-21
lines changed
app/src/main/java/otus/homework/coroutines
12 files changed +28
-21
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,6 @@ class CatViewModel(
19
19
) : ViewModel() {
20
20
val catModel = MutableLiveData <Result >()
21
21
22
- class CatsViewModelFactory (private val factService : CatsFactService ,
23
- private val imageService : CatsImageService ) : ViewModelProvider.Factory {
24
- @Suppress(" UNCHECKED_CAST" )
25
- override fun <T : ViewModel > create (modelClass : Class <T >): T {
26
- return CatViewModel (factService, imageService) as T
27
- }
28
- }
29
-
30
22
fun onInitComplete () {
31
23
loadData()
32
24
}
Original file line number Diff line number Diff line change @@ -8,4 +8,4 @@ interface CatsFactService {
8
8
9
9
@GET(" fact" )
10
10
suspend fun getCatFact () : Response <Fact >
11
- }
11
+ }
Original file line number Diff line number Diff line change @@ -12,4 +12,4 @@ interface CatsImageService {
12
12
companion object {
13
13
const val BASE_URL = " https://cataas.com/"
14
14
}
15
- }
15
+ }
Original file line number Diff line number Diff line change 1
1
package otus.homework.coroutines
2
2
3
- import android.util.Log
4
3
import kotlinx.coroutines.CancellationException
5
4
import kotlinx.coroutines.Dispatchers
6
5
import kotlinx.coroutines.async
7
6
import kotlinx.coroutines.cancel
8
7
import kotlinx.coroutines.launch
9
8
import kotlinx.coroutines.runBlocking
10
9
import otus.homework.coroutines.model.CatModel
11
- import java.lang.Exception
12
10
import java.net.SocketTimeoutException
13
11
14
12
class CatsPresenter (
@@ -60,4 +58,4 @@ class CatsPresenter(
60
58
fun onStop (){
61
59
catsScope.cancel()
62
60
}
63
- }
61
+ }
Original file line number Diff line number Diff line change @@ -42,4 +42,4 @@ interface ICatsView {
42
42
43
43
fun populate (catModel : CatModel )
44
44
fun showToast (message : String )
45
- }
45
+ }
Original file line number Diff line number Diff line change @@ -13,4 +13,4 @@ object CrashMonitor {
13
13
crashesList.add(message)
14
14
Log .e(" crash_mirror" , message)
15
15
}
16
- }
16
+ }
Original file line number Diff line number Diff line change @@ -45,4 +45,4 @@ class DiContainer {
45
45
.addConverterFactory(GsonConverterFactory .create(gson))
46
46
.build()
47
47
}
48
- }
48
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import android.os.Bundle
4
4
import androidx.appcompat.app.AppCompatActivity
5
5
import androidx.lifecycle.Observer
6
6
import androidx.lifecycle.ViewModelProvider
7
+ import otus.homework.coroutines.model.CatsViewModelFactory
7
8
8
9
9
10
class MainActivity : AppCompatActivity () {
@@ -25,7 +26,7 @@ class MainActivity : AppCompatActivity() {
25
26
26
27
catViewModel = ViewModelProvider (
27
28
this ,
28
- CatViewModel . CatsViewModelFactory (diContainer.serviceFact, diContainer.serviceImage)
29
+ CatsViewModelFactory (diContainer.serviceFact, diContainer.serviceImage)
29
30
)[CatViewModel ::class .java]
30
31
31
32
view.viewModel = catViewModel
@@ -50,4 +51,4 @@ class MainActivity : AppCompatActivity() {
50
51
// catsPresenter.onStop()
51
52
super .onStop()
52
53
}
53
- }
54
+ }
Original file line number Diff line number Diff line change @@ -10,4 +10,4 @@ class PresenterScope : CoroutineScope {
10
10
11
11
override val coroutineContext: CoroutineContext
12
12
get() = Job () + Dispatchers .Main + CoroutineName (" CatsCoroutine" )
13
- }
13
+ }
Original file line number Diff line number Diff line change @@ -5,4 +5,4 @@ import otus.homework.coroutines.model.CatModel
5
5
sealed class Result {
6
6
data class Success (val catData : CatModel ) : Result()
7
7
data class Error (val throwable : Throwable ) : Result()
8
- }
8
+ }
Original file line number Diff line number Diff line change
1
+ package otus.homework.coroutines.model
2
+
3
+ import androidx.lifecycle.ViewModel
4
+ import androidx.lifecycle.ViewModelProvider
5
+ import otus.homework.coroutines.CatViewModel
6
+ import otus.homework.coroutines.CatsFactService
7
+ import otus.homework.coroutines.CatsImageService
8
+
9
+ class CatsViewModelFactory (private val factService : CatsFactService ,
10
+ private val imageService : CatsImageService
11
+ ) : ViewModelProvider.Factory {
12
+ @Suppress(" UNCHECKED_CAST" )
13
+ override fun <T : ViewModel > create (modelClass : Class <T >): T {
14
+ return CatViewModel (factService, imageService) as T
15
+ }
16
+ }
Original file line number Diff line number Diff line change @@ -7,4 +7,4 @@ data class Fact(
7
7
val fact : String ,
8
8
@field:SerializedName("length")
9
9
val length : Int
10
- )
10
+ )
You can’t perform that action at this time.
0 commit comments