summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt35
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailTopMangaController.kt35
2 files changed, 49 insertions, 21 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt
index 430f73b..827c7e3 100644
--- a/app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt
@@ -4,6 +4,11 @@ import com.google.gson.Gson
import com.google.gson.GsonBuilder
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
+import xyz.adjutor.aniki.data.anime.AnimeApi
+import xyz.adjutor.aniki.data.anime.SearchAnimeApi
+import xyz.adjutor.aniki.data.anime.TopAnimeApi
+import xyz.adjutor.aniki.data.manga.MangaApi
+import xyz.adjutor.aniki.data.manga.SearchMangaApi
import xyz.adjutor.aniki.data.manga.TopMangaApi
class Singletons {
@@ -19,5 +24,35 @@ class Singletons {
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
.create(TopMangaApi::class.java)
+
+ val searchMangaApi: SearchMangaApi = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+ .create(SearchMangaApi::class.java)
+
+ val mangaApi: MangaApi = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+ .create(MangaApi::class.java)
+
+ val topAnimeApi: TopAnimeApi = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+ .create(TopAnimeApi::class.java)
+
+ val searchAnimeApi: SearchAnimeApi = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+ .create(SearchAnimeApi::class.java)
+
+ val animeApi: AnimeApi = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+ .create(AnimeApi::class.java)
}
}
diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailTopMangaController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailTopMangaController.kt
index 807421c..9789d0c 100644
--- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailTopMangaController.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailTopMangaController.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.manga.MangaApi
+import xyz.adjutor.aniki.presentation.Singletons
import xyz.adjutor.aniki.presentation.model.manga.MangaResponse
import xyz.adjutor.aniki.presentation.view.manga.DetailTopMangaActivity
import java.lang.reflect.Type
@@ -54,24 +52,19 @@ class DetailTopMangaController {
private fun makeApiCall(BASE_URL: String, mangaId: String) {
- val retrofit = Retrofit.Builder()
- .baseUrl(BASE_URL)
- .addConverterFactory(GsonConverterFactory.create(gson))
- .build()
-
- val service = retrofit.create(MangaApi::class.java)
- val call = service.getMangaData(mangaId) //based on the id
-
- call.enqueue(object : Callback<MangaResponse> {
- override fun onResponse(
- call: Call<MangaResponse>,
- response: Response<MangaResponse>
- ) {
- 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
- saveList(manga)
- view.showDetail(manga!!)
+ Singletons
+ .mangaApi
+ .getMangaData(mangaId) //based on the id
+ .enqueue(object : Callback<MangaResponse> {
+ override fun onResponse(
+ call: Call<MangaResponse>,
+ response: Response<MangaResponse>
+ ) {
+ 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
+ saveList(manga)
+ view.showDetail(manga!!)
} else {
view.showError("API ERROR : is not successful")