From 315c8932950c003f373de601eb3f9e678c073663 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Fri, 14 May 2021 13:48:39 +0200 Subject: Singletons on all pages : OK --- .../anime/DetailSearchAnimeController.kt | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt') diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt index 3114d01..e12de3a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt @@ -5,9 +5,7 @@ import com.google.gson.GsonBuilder import retrofit2.Call import retrofit2.Callback import retrofit2.Response -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory -import xyz.adjutor.aniki.data.anime.AnimeApi +import xyz.adjutor.aniki.presentation.Singletons import xyz.adjutor.aniki.presentation.model.anime.AnimeResponse import xyz.adjutor.aniki.presentation.view.anime.DetailSearchAnimeActivity @@ -30,25 +28,20 @@ class DetailSearchAnimeController { private fun makeApiCall(BASE_URL: String, animeId: String) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() + Singletons + .animeApi + .getAnimeData(animeId) //based on the id + .enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty - val service = retrofit.create(AnimeApi::class.java) - val call = service.getAnimeData(animeId) //based on the id + val anime = response.body() //getting the AnimeResponse fields + view.showDetail(anime!!) - call.enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty - - val anime = response.body() //getting the AnimeResponse fields - view.showDetail(anime!!) - - } else { + } else { view.showError("API ERROR : is not successful") } } -- cgit v1.2.3