diff options
Diffstat (limited to 'app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt index 6f3cedb..3fb13b4 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt @@ -8,9 +8,7 @@ import com.google.gson.reflect.TypeToken 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.DetailTopAnimeActivity import java.lang.reflect.Type @@ -54,24 +52,19 @@ class DetailTopAnimeController { private fun makeApiCall(BASE_URL: String, animeId: String) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() - - val service = retrofit.create(AnimeApi::class.java) - val call = service.getAnimeData(animeId) //based on the id - - call.enqueue(object : Callback<AnimeResponse> { - override fun onResponse( - call: Call<AnimeResponse>, - response: Response<AnimeResponse> - ) { - 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 - saveList(anime) - view.showDetail(anime!!) + Singletons + .animeApi + .getAnimeData(animeId) //based on the id + .enqueue(object : Callback<AnimeResponse> { + override fun onResponse( + call: Call<AnimeResponse>, + response: Response<AnimeResponse> + ) { + 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 + saveList(anime) + view.showDetail(anime!!) } else { view.showError("API ERROR : is not successful") |