summaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-05-14 13:48:39 +0200
committerClyhtsuriva <aimeric@adjutor.xyz>2021-05-14 13:48:39 +0200
commit315c8932950c003f373de601eb3f9e678c073663 (patch)
tree2ef24c0a1b54d18cc5764ab836e38a76a69cf7c2 /app/src/main/java/xyz/adjutor
parent5d4d65293a667f9d4807b3599f13ce36af2d1060 (diff)
Singletons on all pages : OK
Diffstat (limited to 'app/src/main/java/xyz/adjutor')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailSearchAnimeController.kt33
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/DetailTopAnimeController.kt35
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/SearchAnimeController.kt34
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/anime/TopAnimeController.kt37
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/DetailSearchMangaController.kt33
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/SearchMangaController.kt34
6 files changed, 81 insertions, 125 deletions
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<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 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<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
- 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<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")
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<SearchAnimeResponse> {
+ override fun onResponse(
+ call: Call<SearchAnimeResponse>,
+ response: Response<SearchAnimeResponse>
+ ) {
+ 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<SearchAnime> = response.body()!!
+ .getResults() //getting the "search" field containing our list of SearchAnimes
- call.enqueue(object : Callback<SearchAnimeResponse> {
- override fun onResponse(
- call: Call<SearchAnimeResponse>,
- response: Response<SearchAnimeResponse>
- ) {
- if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty
-
- val animeList: List<SearchAnime> = 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<TopAnimeResponse> {
- override fun onResponse(
- call: Call<TopAnimeResponse>,
- response: Response<TopAnimeResponse>
- ) {
- if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty
-
- val animeList: List<TopAnime> = response.body()!!
- .getResults() //getting the "top" field containing our list of TopAnimes
- saveList(animeList)
- view.showList(
+ Singletons
+ .topAnimeApi
+ .getTopAnimeData(page)
+ .enqueue(object : Callback<TopAnimeResponse> {
+ override fun onResponse(
+ call: Call<TopAnimeResponse>,
+ response: Response<TopAnimeResponse>
+ ) {
+ if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty
+
+ val animeList: List<TopAnime> = 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<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 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<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
- 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<SearchMangaResponse> {
+ override fun onResponse(
+ call: Call<SearchMangaResponse>,
+ response: Response<SearchMangaResponse>
+ ) {
+ 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<SearchManga> = response.body()!!
+ .getResults() //getting the "search" field containing our list of SearchMangas
- call.enqueue(object : Callback<SearchMangaResponse> {
- override fun onResponse(
- call: Call<SearchMangaResponse>,
- response: Response<SearchMangaResponse>
- ) {
- if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty
-
- val mangaList: List<SearchManga> = 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