diff options
| author | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-05-14 14:27:11 +0200 | 
|---|---|---|
| committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-05-14 14:27:11 +0200 | 
| commit | 6484782745a29752cf2a9a5015b34494513eb376 (patch) | |
| tree | c9b4af4deb4acbac4c394e48d3df7874120d24a1 /app/src/main | |
| parent | a4fbe1308bb4cf61358d8169dd32505e2783a9af (diff) | |
| parent | e3104c145727c10ff80cad0fe1e916a0a45239eb (diff) | |
Merge branch 'release/3.1'v3.1.0
Diffstat (limited to 'app/src/main')
10 files changed, 181 insertions, 170 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 new file mode 100644 index 0000000..827c7e3 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/Singletons.kt @@ -0,0 +1,58 @@ +package xyz.adjutor.aniki.presentation + +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 { + +    companion object { +        val gson: Gson = GsonBuilder() +            .setLenient() +            .create()!! +        private const val BASE_URL = "https://api.jikan.moe/" + +        val topMangaApi: TopMangaApi = Retrofit.Builder() +            .baseUrl(BASE_URL) +            .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/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/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") 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 diff --git a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/TopMangaController.kt b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/TopMangaController.kt index 845e750..ea631fd 100644 --- a/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/TopMangaController.kt +++ b/app/src/main/java/xyz/adjutor/aniki/presentation/controller/manga/TopMangaController.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.manga.TopMangaApi +import xyz.adjutor.aniki.presentation.Singletons  import xyz.adjutor.aniki.presentation.model.manga.TopManga  import xyz.adjutor.aniki.presentation.model.manga.TopMangaResponse  import xyz.adjutor.aniki.presentation.view.manga.TopMangaPage @@ -48,25 +46,20 @@ class TopMangaController {      private fun makeApiCall(view: TopMangaPage, BASE_URL: String, page: Int) { -        val retrofit = Retrofit.Builder() -            .baseUrl(BASE_URL) -            .addConverterFactory(GsonConverterFactory.create(gson)) -            .build() - -        val service = retrofit.create(TopMangaApi::class.java) -        val call = service.getTopMangaData(page) - -        call.enqueue(object : Callback<TopMangaResponse> { -            override fun onResponse( -                call: Call<TopMangaResponse>, -                response: Response<TopMangaResponse> -            ) { -                if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty - -                    val mangaList: List<TopManga> = response.body()!! -                        .getResults() //getting the "top" field containing our list of TopMangas -                    saveList(mangaList) -                    view.showList( +        Singletons +            .topMangaApi +            .getTopMangaData(page) +            .enqueue(object : Callback<TopMangaResponse> { +                override fun onResponse( +                    call: Call<TopMangaResponse>, +                    response: Response<TopMangaResponse> +                ) { +                    if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty + +                        val mangaList: List<TopManga> = response.body()!! +                            .getResults() //getting the "top" field containing our list of TopMangas +                        saveList(mangaList) +                        view.showList(                          view.requireView(),                          mangaList                      ) //calling the method in charge of displaying on the recyclerview diff --git a/app/src/main/res/layout/home_page.xml b/app/src/main/res/layout/home_page.xml index 1c547d6..d9677a9 100644 --- a/app/src/main/res/layout/home_page.xml +++ b/app/src/main/res/layout/home_page.xml @@ -7,6 +7,17 @@      android:background="@color/very_dark_purple"      tools:context=".presentation.view.HomePage"> +    <ImageView +        android:id="@+id/logo" +        android:layout_width="wrap_content" +        android:layout_height="wrap_content" +        android:contentDescription="@string/app_name" +        android:src="@mipmap/ic_launcher" +        app:layout_constraintBottom_toTopOf="@id/tv_title" +        app:layout_constraintEnd_toEndOf="parent" +        app:layout_constraintStart_toStartOf="parent" +        app:layout_constraintTop_toTopOf="parent" /> +      <TextView          android:id="@+id/tv_title"          android:layout_width="match_parent" @@ -17,8 +28,8 @@          android:textAlignment="center"          android:textColor="@color/strong_pink"          android:textSize="40sp" -        app:layout_constraintBottom_toBottomOf="@id/button_top_manga" -        app:layout_constraintTop_toTopOf="parent" /> +        app:layout_constraintBottom_toTopOf="@id/button_top_manga" +        app:layout_constraintTop_toTopOf="@id/logo" />      <Button          android:id="@+id/button_top_manga" | 
