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 ++++++++----------- .../controller/anime/DetailTopAnimeController.kt | 35 ++++++++------------ .../controller/anime/SearchAnimeController.kt | 34 ++++++++------------ .../controller/anime/TopAnimeController.kt | 37 +++++++++------------- .../manga/DetailSearchMangaController.kt | 33 ++++++++----------- .../controller/manga/SearchMangaController.kt | 34 ++++++++------------ 6 files changed, 81 insertions(+), 125 deletions(-) (limited to 'app/src/main/java/xyz') 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") } } 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 { - 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 - saveList(anime) - view.showDetail(anime!!) + 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 anime = response.body() //getting the AnimeResponse fields + saveList(anime) + view.showDetail(anime!!) } else { view.showError("API ERROR : is not successful") diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/SearchAnimeController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/SearchAnimeController.kt index aa8487e..5951f1b 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/SearchAnimeController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/SearchAnimeController.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.SearchAnimeApi +import xyz.adjutor.aniki.presentation.Singletons import xyz.adjutor.aniki.presentation.model.anime.SearchAnime import xyz.adjutor.aniki.presentation.model.anime.SearchAnimeResponse import xyz.adjutor.aniki.presentation.view.anime.SearchAnimePage @@ -30,26 +28,20 @@ class SearchAnimeController { //call the API and show the list private fun makeApiCall(view: SearchAnimePage, BASE_URL: String, query: String) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() + Singletons + .searchAnimeApi + .getSearchAnimeData(q = query) + .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(SearchAnimeApi::class.java) - val call = - service.getSearchAnimeData(q = query) //fate is an exemple, we'll have to replace it by the user input. + val animeList: List = response.body()!! + .getResults() //getting the "search" field containing our list of SearchAnimes - 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 animeList: List = response.body()!! - .getResults() //getting the "search" field containing our list of SearchAnimes - - view.showList( + view.showList( view.requireView(), animeList ) //calling the method in charge of displaying on the recyclerview diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/TopAnimeController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/TopAnimeController.kt index 7105af5..57dc10b 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/TopAnimeController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/TopAnimeController.kt @@ -9,9 +9,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.TopAnimeApi +import xyz.adjutor.aniki.presentation.Singletons import xyz.adjutor.aniki.presentation.model.anime.TopAnime import xyz.adjutor.aniki.presentation.model.anime.TopAnimeResponse import xyz.adjutor.aniki.presentation.view.anime.TopAnimePage @@ -48,25 +46,20 @@ class TopAnimeController { fun makeApiCall(view: TopAnimePage, BASE_URL: String, page: Int) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() - - val service = retrofit.create(TopAnimeApi::class.java) - val call = service.getTopAnimeData(page) - - 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 animeList: List = response.body()!! - .getResults() //getting the "top" field containing our list of TopAnimes - saveList(animeList) - view.showList( + Singletons + .topAnimeApi + .getTopAnimeData(page) + .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 animeList: List = response.body()!! + .getResults() //getting the "top" field containing our list of TopAnimes + saveList(animeList) + view.showList( view.requireView(), animeList ) //calling the method in charge of displaying on the recyclerview diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailSearchMangaController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailSearchMangaController.kt index a874976..080e4ed 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailSearchMangaController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailSearchMangaController.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.manga.MangaApi +import xyz.adjutor.aniki.presentation.Singletons import xyz.adjutor.aniki.presentation.model.manga.MangaResponse import xyz.adjutor.aniki.presentation.view.manga.DetailSearchMangaActivity @@ -30,25 +28,20 @@ class DetailSearchMangaController { private fun makeApiCall(BASE_URL: String, mangaId: String) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() + Singletons + .mangaApi + .getMangaData(mangaId) //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(MangaApi::class.java) - val call = service.getMangaData(mangaId) //based on the id + val manga = response.body() //getting the MangaResponse fields + view.showDetail(manga!!) - 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 manga = response.body() //getting the MangaResponse fields - view.showDetail(manga!!) - - } else { + } else { view.showError("API ERROR : is not successful") } } diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/SearchMangaController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/SearchMangaController.kt index 32e46eb..de1edad 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/SearchMangaController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/SearchMangaController.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.manga.SearchMangaApi +import xyz.adjutor.aniki.presentation.Singletons import xyz.adjutor.aniki.presentation.model.manga.SearchManga import xyz.adjutor.aniki.presentation.model.manga.SearchMangaResponse import xyz.adjutor.aniki.presentation.view.manga.SearchMangaPage @@ -30,26 +28,20 @@ class SearchMangaController { //call the API and show the list private fun makeApiCall(view: SearchMangaPage, BASE_URL: String, query: String) { - val retrofit = Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(gson)) - .build() + Singletons + .searchMangaApi + .getSearchMangaData(q = query) + .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(SearchMangaApi::class.java) - val call = - service.getSearchMangaData(q = query) //fate is an exemple, we'll have to replace it by the user input. + val mangaList: List = response.body()!! + .getResults() //getting the "search" field containing our list of SearchMangas - 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 mangaList: List = response.body()!! - .getResults() //getting the "search" field containing our list of SearchMangas - - view.showList( + view.showList( view.requireView(), mangaList ) //calling the method in charge of displaying on the recyclerview -- cgit v1.2.3