File tree Expand file tree Collapse file tree 5 files changed +32
-8
lines changed
app/src/main/java/otus/homework/coroutines Expand file tree Collapse file tree 5 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ class CatsPresenter(
17
17
fun onInitComplete () {
18
18
_job = presenterScope.launch {
19
19
try {
20
+ // imageService.getCatImage().also {
21
+ // println("image url ${it.url}")
22
+ // }
20
23
catsService.getCatFact().also { fact ->
21
24
_catsView ?.populate(fact)
22
25
}
Original file line number Diff line number Diff line change @@ -8,14 +8,14 @@ import retrofit2.converter.gson.GsonConverterFactory
8
8
9
9
class DiContainer {
10
10
11
- private val retrofit by lazy {
12
- Retrofit .Builder ()
13
- .baseUrl(" https://catfact.ninja/" )
14
- .addConverterFactory(GsonConverterFactory .create())
15
- .build()
16
- }
11
+ private fun buildRetrofit (baseUrl : String ) = Retrofit .Builder ()
12
+ .baseUrl(baseUrl)
13
+ .addConverterFactory(GsonConverterFactory .create())
14
+ .build()
17
15
18
- val service by lazy { retrofit.create(CatsService ::class .java) }
16
+ val catsService by lazy { buildRetrofit(" https://catfact.ninja/" ).create(CatsService ::class .java) }
17
+
18
+ val imageService by lazy { buildRetrofit(" https://api.thecatapi.com/v1/images/" ).create(ImageService ::class .java) }
19
19
20
20
val presenterScope get() = CoroutineScope (CoroutineName (" CatsCoroutine" ) + Dispatchers .Main )
21
21
}
Original file line number Diff line number Diff line change
1
+ package otus.homework.coroutines
2
+
3
+ import com.google.gson.annotations.SerializedName
4
+
5
+ data class Image (
6
+ @field:SerializedName("id")
7
+ val id : String ,
8
+ @field:SerializedName("url")
9
+ val url : String
10
+ )
Original file line number Diff line number Diff line change
1
+ package otus.homework.coroutines
2
+
3
+ import retrofit2.http.GET
4
+
5
+ interface ImageService {
6
+ @GET(" search" )
7
+ suspend fun getCatImage (): Image
8
+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ class MainActivity : AppCompatActivity() {
15
15
val view = layoutInflater.inflate(R .layout.activity_main, null ) as CatsView
16
16
setContentView(view)
17
17
18
- catsPresenter = CatsPresenter (diContainer.service, diContainer.presenterScope)
18
+ catsPresenter = CatsPresenter (
19
+ diContainer.catsService,
20
+ diContainer.presenterScope
21
+ )
19
22
view.presenter = catsPresenter
20
23
catsPresenter.attachView(view)
21
24
catsPresenter.onInitComplete()
You can’t perform that action at this time.
0 commit comments