From 1eb274dcaaf1ee5f79505da935afcd89856e21fd Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 20 Feb 2021 16:43:50 +0100 Subject: Implementation of Glide. Replace the current way by Glide for more stability. Also allows to keep the images with sharedpreferences. --- app/build.gradle | 7 +++-- .../main/java/xyz/adjutor/aniki/MainActivity.kt | 4 +-- .../xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt | 36 +++++----------------- .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 35 +++++---------------- app/src/main/res/layout/item_layout.xml | 30 ++++++++---------- 5 files changed, 35 insertions(+), 77 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4a23638..4dd9f20 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,8 +48,8 @@ dependencies { //Recycleview implementation "androidx.recyclerview:recyclerview:1.1.0" //Retrofit - implementation 'com.squareup.retrofit2:retrofit:2.6.0' - implementation 'com.squareup.retrofit2:converter-gson:2.6.0' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.squareup.retrofit2:converter-gson:2.9.0' // Required for local unit tests (JUnit 4 framework) testImplementation 'junit:junit:4.13.2' @@ -58,5 +58,8 @@ dependencies { androidTestImplementation 'com.android.support:support-annotations:28.0.0' androidTestImplementation 'com.android.support.test:runner:1.0.2' + //to display images + implementation 'com.github.bumptech.glide:glide:4.12.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt index 50cd24f..a195f97 100644 --- a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt @@ -1,11 +1,9 @@ package xyz.adjutor.aniki import android.os.Bundle -import com.google.android.material.floatingactionbutton.FloatingActionButton -import com.google.android.material.snackbar.Snackbar -import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt index 68a2c7b..4953939 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt @@ -2,20 +2,15 @@ package xyz.adjutor.aniki.topanime -import android.annotation.SuppressLint -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.os.AsyncTask -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R -import xyz.adjutor.aniki.topanime.TopAnime -import xyz.adjutor.aniki.topanime.TopAnimeAdapter class TopAnimeAdapter(val animeList: List) : RecyclerView.Adapter() { @@ -26,7 +21,6 @@ class TopAnimeAdapter(val animeList: List) : val animeRank: TextView = itemView.findViewById(R.id.tv_rank) val animeScore: TextView = itemView.findViewById(R.id.tv_score) val animeImage: ImageView = itemView.findViewById(R.id.iv_image) - } // Returns a new ViewHolder @@ -48,27 +42,13 @@ class TopAnimeAdapter(val animeList: List) : holder.animeTitle.text = currentAnime.title holder.animeRank.text = currentAnime.rank.toString() holder.animeScore.text = currentAnime.score.toString() - DownloadImageFromInternet(holder.animeImage).execute(currentAnime.image_url) + val image : String = currentAnime.image_url.toString() + Glide + .with(holder.itemView.context) + .load(image) + .apply(RequestOptions().override(400)) + .into(holder.animeImage) } - @SuppressLint("StaticFieldLeak") - private inner class DownloadImageFromInternet(var imageView: ImageView) : AsyncTask() { - override fun doInBackground(vararg urls: String): Bitmap? { - val imageURL = urls[0] - var image: Bitmap? = null - try { - val `in` = java.net.URL(imageURL).openStream() - image = BitmapFactory.decodeStream(`in`) - } - catch (e: Exception) { - Log.e("Error Message", e.message.toString()) - e.printStackTrace() - } - return image - } - override fun onPostExecute(result: Bitmap?) { - imageView.setImageBitmap(result) - } - } } diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index 22872b2..f5a2bd2 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -2,17 +2,14 @@ package xyz.adjutor.aniki.topmanga -import android.annotation.SuppressLint -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.os.AsyncTask -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R class TopMangaAdapter(val mangaList: List) : @@ -24,7 +21,6 @@ class TopMangaAdapter(val mangaList: List) : val mangaRank: TextView = itemView.findViewById(R.id.tv_rank) val mangaScore: TextView = itemView.findViewById(R.id.tv_score) val mangaImage: ImageView = itemView.findViewById(R.id.iv_image) - } // Returns a new ViewHolder @@ -46,27 +42,12 @@ class TopMangaAdapter(val mangaList: List) : holder.mangaTitle.text = currentManga.title holder.mangaRank.text = currentManga.rank.toString() holder.mangaScore.text = currentManga.score.toString() - DownloadImageFromInternet(holder.mangaImage).execute(currentManga.image_url) - } - - @SuppressLint("StaticFieldLeak") - private inner class DownloadImageFromInternet(var imageView: ImageView) : AsyncTask() { - override fun doInBackground(vararg urls: String): Bitmap? { - val imageURL = urls[0] - var image: Bitmap? = null - try { - val `in` = java.net.URL(imageURL).openStream() - image = BitmapFactory.decodeStream(`in`) - } - catch (e: Exception) { - Log.e("Error Message", e.message.toString()) - e.printStackTrace() - } - return image - } - override fun onPostExecute(result: Bitmap?) { - imageView.setImageBitmap(result) - } + val image : String = currentManga.image_url.toString() + Glide + .with(holder.itemView.context) + .load(image) + .apply(RequestOptions().override(400)) + .into(holder.mangaImage) } } diff --git a/app/src/main/res/layout/item_layout.xml b/app/src/main/res/layout/item_layout.xml index 8d7a792..5ef1c19 100644 --- a/app/src/main/res/layout/item_layout.xml +++ b/app/src/main/res/layout/item_layout.xml @@ -1,6 +1,5 @@ - + app:cardCornerRadius="13dp"> + + android:padding="10dp"> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@id/tv_title" /> \ No newline at end of file -- cgit v1.2.3 From 496eff5e9bf0380253594ddf37a5743f6d250562 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 20 Feb 2021 18:10:38 +0100 Subject: Intents now working for top mangas --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 11 ++++- .../aniki/topmanga/DetailTopMangaActivity.kt | 36 +++++++++++++++ .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 22 ++++++++- .../main/res/layout/activity_detail_top_manga.xml | 54 ++++++++++++++++++++++ app/src/main/res/layout/item_layout.xml | 9 ++-- app/src/main/res/values/strings.xml | 8 ++-- 7 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt create mode 100644 app/src/main/res/layout/activity_detail_top_manga.xml diff --git a/app/build.gradle b/app/build.gradle index 4dd9f20..fb76368 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ android { dependencies { + //noinspection GradleDependency implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 105fdfd..5316b25 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,9 @@ - + + android:theme="@style/Theme.Aniki" + tools:ignore="AllowBackup"> + + diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt new file mode 100644 index 0000000..61c5b14 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -0,0 +1,36 @@ +package xyz.adjutor.aniki.topmanga + +import android.os.Bundle +import android.widget.Button +import android.widget.ImageView +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.navigation.fragment.NavHostFragment.findNavController +import androidx.navigation.fragment.findNavController +import com.bumptech.glide.Glide +import xyz.adjutor.aniki.R + +class DetailTopMangaActivity : AppCompatActivity() { + + private val currentMangaTitle: String = "themangatitle" + val currentMangaRank: String = "themangarank" + val currentMangaScore: String = "themangascore" + val currentMangaImageUrl: String = "themangaimageurl" + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_detail_top_manga) + + val mangaTitle = intent.getStringExtra(currentMangaTitle) + val mangaRank = intent.getStringExtra(currentMangaRank) + val mangaScore = intent.getStringExtra(currentMangaScore) + + val tvTitle: TextView = findViewById(R.id.tv_detail_title) + val tvRank: TextView = findViewById(R.id.tv_detail_rank) + val tvScore: TextView = findViewById(R.id.tv_detail_score) + + tvTitle.text = mangaTitle + tvRank.text = mangaRank + tvScore.text = mangaScore + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index f5a2bd2..2eaf958 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -2,11 +2,13 @@ package xyz.adjutor.aniki.topmanga +import android.content.Intent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions @@ -21,6 +23,8 @@ class TopMangaAdapter(val mangaList: List) : val mangaRank: TextView = itemView.findViewById(R.id.tv_rank) val mangaScore: TextView = itemView.findViewById(R.id.tv_score) val mangaImage: ImageView = itemView.findViewById(R.id.iv_image) + val cardview: CardView = itemView.findViewById(R.id.cv_cardView) + } // Returns a new ViewHolder @@ -42,12 +46,28 @@ class TopMangaAdapter(val mangaList: List) : holder.mangaTitle.text = currentManga.title holder.mangaRank.text = currentManga.rank.toString() holder.mangaScore.text = currentManga.score.toString() - val image : String = currentManga.image_url.toString() + val image: String = currentManga.image_url.toString() Glide .with(holder.itemView.context) .load(image) .apply(RequestOptions().override(400)) .into(holder.mangaImage) + + //to go to a detail page of the selected manga + holder.cardview.setOnClickListener { + val currentMangaTitle = "themangatitle" + val currentMangaRank = "themangarank" + val currentMangaScore = "themangascore" + val currentMangaImageUrl = "themangaimageurl" + + val intent: Intent = Intent(holder.itemView.context, DetailTopMangaActivity::class.java).apply { + putExtra(currentMangaTitle, currentManga.title) + putExtra(currentMangaRank, currentManga.rank.toString()) + putExtra(currentMangaScore, currentManga.score.toString()) + putExtra(currentMangaImageUrl, currentManga.image_url.toString()) + } + holder.itemView.context.startActivity(intent) + } } } diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml new file mode 100644 index 0000000..3e74697 --- /dev/null +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_layout.xml b/app/src/main/res/layout/item_layout.xml index 5ef1c19..f904109 100644 --- a/app/src/main/res/layout/item_layout.xml +++ b/app/src/main/res/layout/item_layout.xml @@ -10,7 +10,6 @@ android:foreground="?selectableItemBackground" app:cardBackgroundColor="@color/black" app:cardCornerRadius="13dp"> - News Page Article Page Top Manga Page - Title - 0 - image + Title + 0 + image Image of manga Top Anime Page Top Anime - 00.00 + 00.00 \ No newline at end of file -- cgit v1.2.3 From 3703ade7bae26dd223e71aa098f8ea0d50ca2a00 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 20 Feb 2021 18:15:47 +0100 Subject: Added image support --- .../java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 61c5b14..b01e3f3 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -8,6 +8,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.navigation.fragment.NavHostFragment.findNavController import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R class DetailTopMangaActivity : AppCompatActivity() { @@ -24,13 +25,20 @@ class DetailTopMangaActivity : AppCompatActivity() { val mangaTitle = intent.getStringExtra(currentMangaTitle) val mangaRank = intent.getStringExtra(currentMangaRank) val mangaScore = intent.getStringExtra(currentMangaScore) + val mangaImage = intent.getStringExtra(currentMangaImageUrl) val tvTitle: TextView = findViewById(R.id.tv_detail_title) val tvRank: TextView = findViewById(R.id.tv_detail_rank) val tvScore: TextView = findViewById(R.id.tv_detail_score) + val ivImage: ImageView = findViewById(R.id.iv_detail_image) tvTitle.text = mangaTitle tvRank.text = mangaRank tvScore.text = mangaScore + Glide + .with(this) + .load(mangaImage) + .apply(RequestOptions().override(400)) + .into(ivImage) } } \ No newline at end of file -- cgit v1.2.3 From 7bc4fe28dd31176c50495b2f3b0ba5a51eca6d9e Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 20 Feb 2021 18:20:01 +0100 Subject: "Optimizing" imports --- .../androidTest/java/xyz/adjutor/aniki/ExampleInstrumentedTest.kt | 6 ++---- app/src/main/java/xyz/adjutor/aniki/HomePage.kt | 2 +- app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt | 2 +- app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt | 1 - .../main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 3 --- app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt | 2 +- app/src/test/java/xyz/adjutor/aniki/ExampleUnitTest.kt | 3 +-- 7 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/androidTest/java/xyz/adjutor/aniki/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/adjutor/aniki/ExampleInstrumentedTest.kt index 517647e..9100bf0 100644 --- a/app/src/androidTest/java/xyz/adjutor/aniki/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/xyz/adjutor/aniki/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package xyz.adjutor.aniki -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/xyz/adjutor/aniki/HomePage.kt b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt index 59d7c62..734e917 100644 --- a/app/src/main/java/xyz/adjutor/aniki/HomePage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt @@ -1,11 +1,11 @@ package xyz.adjutor.aniki import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button +import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController class HomePage : Fragment() { diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt index 6d8669c..bea4c63 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt @@ -1,7 +1,7 @@ package xyz.adjutor.aniki.topanime -import retrofit2.http.GET import retrofit2.Call +import retrofit2.http.GET interface TopAnimeApi { diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt index b1fe2e2..a333aae 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt @@ -20,7 +20,6 @@ import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import xyz.adjutor.aniki.R -import xyz.adjutor.aniki.topmanga.TopManga import java.lang.reflect.Type class TopAnimePage : Fragment() { diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index b01e3f3..e97ee39 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -1,12 +1,9 @@ package xyz.adjutor.aniki.topmanga import android.os.Bundle -import android.widget.Button import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity -import androidx.navigation.fragment.NavHostFragment.findNavController -import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt index 69c4cdd..e8231b0 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt @@ -1,7 +1,7 @@ package xyz.adjutor.aniki.topmanga -import retrofit2.http.GET import retrofit2.Call +import retrofit2.http.GET interface TopMangaApi { diff --git a/app/src/test/java/xyz/adjutor/aniki/ExampleUnitTest.kt b/app/src/test/java/xyz/adjutor/aniki/ExampleUnitTest.kt index 7aacf1c..6e6f0ae 100644 --- a/app/src/test/java/xyz/adjutor/aniki/ExampleUnitTest.kt +++ b/app/src/test/java/xyz/adjutor/aniki/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package xyz.adjutor.aniki +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * -- cgit v1.2.3 From 7c8476a2128f6c4494eaa2d0a363d8cbe3261ba6 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 20 Feb 2021 18:56:42 +0100 Subject: Beginning the manga api part. --- app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt | 31 ++++++++++++ .../java/xyz/adjutor/aniki/manga/MangaAdapter.kt | 58 ++++++++++++++++++++++ .../main/java/xyz/adjutor/aniki/manga/MangaApi.kt | 11 ++++ .../java/xyz/adjutor/aniki/topanime/TopAnime.kt | 2 +- .../aniki/topmanga/DetailTopMangaActivity.kt | 13 +++-- .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 4 +- .../main/res/layout/activity_detail_top_manga.xml | 22 ++++++++ app/src/main/res/values/strings.xml | 2 + 8 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt create mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt create mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt b/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt new file mode 100644 index 0000000..43944c3 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt @@ -0,0 +1,31 @@ +package xyz.adjutor.aniki.manga + +import com.google.gson.annotations.SerializedName + +//Content of the top field from the api of manga +class Manga{ + + @SerializedName("url") + var url: String? = null + @SerializedName("title") + var title: String? = null + @SerializedName("rank") + var rank: Int? = null + @SerializedName("volumes") + var volumes: Int? = null + @SerializedName("chapters") + var chapters: Int? = null + @SerializedName("start_date") + var start_date: String? = null + @SerializedName("end_date") + var end_date: String? = null + @SerializedName("score") + var score: Float? = null + @SerializedName("image_url") + var image_url: String? = null + @SerializedName("synopsis") + var synopsis: String? = null + @SerializedName("background") + var background: String? = null + +} diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt new file mode 100644 index 0000000..ad753e2 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt @@ -0,0 +1,58 @@ +@file:Suppress("DEPRECATION") + +package xyz.adjutor.aniki.manga + +import android.content.Intent +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.cardview.widget.CardView +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import xyz.adjutor.aniki.R +import xyz.adjutor.aniki.topmanga.DetailTopMangaActivity + +class MangaAdapter(val mangaList: List) : + RecyclerView.Adapter() { + + // Describes an item view and its place within the RecyclerView + class MangaViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val mangaTitle: TextView = itemView.findViewById(R.id.tv_title) + val mangaRank: TextView = itemView.findViewById(R.id.tv_rank) + val mangaScore: TextView = itemView.findViewById(R.id.tv_score) + val mangaImage: ImageView = itemView.findViewById(R.id.iv_image) + val cardview: CardView = itemView.findViewById(R.id.cv_cardView) + + } + + // Returns a new ViewHolder + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.item_layout, parent, false) + + return MangaViewHolder(view) + } + + // Returns size of data list + override fun getItemCount(): Int { + return mangaList.size + } + + // Displays data at a certain position + override fun onBindViewHolder(holder: MangaViewHolder, position: Int) { + val currentManga: Manga = mangaList[position] + holder.mangaTitle.text = currentManga.title + holder.mangaRank.text = currentManga.rank.toString() + holder.mangaScore.text = currentManga.score.toString() + val image: String = currentManga.image_url.toString() + Glide + .with(holder.itemView.context) + .load(image) + .apply(RequestOptions().override(400)) + .into(holder.mangaImage) + } +} + diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt new file mode 100644 index 0000000..7692836 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt @@ -0,0 +1,11 @@ +package xyz.adjutor.aniki.manga + +import retrofit2.Call +import retrofit2.http.GET + +interface MangaApi { + + @GET("v3/manga") + fun getMangaData(): Call + +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt index a428841..3576e7b 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt @@ -2,7 +2,7 @@ package xyz.adjutor.aniki.topanime import com.google.gson.annotations.SerializedName -//Content of the top field from the api of top manga +//Content of the top field from the api of top anime class TopAnime{ @SerializedName("mal_id") diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index e97ee39..2f0d2c3 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -9,26 +9,29 @@ import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R class DetailTopMangaActivity : AppCompatActivity() { - - private val currentMangaTitle: String = "themangatitle" - val currentMangaRank: String = "themangarank" - val currentMangaScore: String = "themangascore" - val currentMangaImageUrl: String = "themangaimageurl" + private val currentMangaId = "themangaid" + private val currentMangaTitle = "themangatitle" + private val currentMangaRank = "themangarank" + private val currentMangaScore = "themangascore" + private val currentMangaImageUrl = "themangaimageurl" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) + val mangaId = intent.getStringExtra(currentMangaId) val mangaTitle = intent.getStringExtra(currentMangaTitle) val mangaRank = intent.getStringExtra(currentMangaRank) val mangaScore = intent.getStringExtra(currentMangaScore) val mangaImage = intent.getStringExtra(currentMangaImageUrl) + val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) val tvRank: TextView = findViewById(R.id.tv_detail_rank) val tvScore: TextView = findViewById(R.id.tv_detail_score) val ivImage: ImageView = findViewById(R.id.iv_detail_image) + tvId.text = mangaId tvTitle.text = mangaTitle tvRank.text = mangaRank tvScore.text = mangaScore diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index 2eaf958..e46fc79 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -53,14 +53,16 @@ class TopMangaAdapter(val mangaList: List) : .apply(RequestOptions().override(400)) .into(holder.mangaImage) - //to go to a detail page of the selected manga + //to go to the detail page of the selected manga holder.cardview.setOnClickListener { + val currentMangaId = "themangaid" val currentMangaTitle = "themangatitle" val currentMangaRank = "themangarank" val currentMangaScore = "themangascore" val currentMangaImageUrl = "themangaimageurl" val intent: Intent = Intent(holder.itemView.context, DetailTopMangaActivity::class.java).apply { + putExtra(currentMangaId, currentManga.mal_id.toString()) putExtra(currentMangaTitle, currentManga.title) putExtra(currentMangaRank, currentManga.rank.toString()) putExtra(currentMangaScore, currentManga.score.toString()) diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index 3e74697..42018ef 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -7,6 +7,16 @@ tools:context=".topmanga.DetailTopMangaActivity" android:background="@color/very_dark_purple"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3bcd30b..03d4a0e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,5 +15,7 @@ Top Anime Page Top Anime 00.00 + 000000 + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \ No newline at end of file -- cgit v1.2.3 From 8201603b4f6a7216f466d4a839421415d3e0f6dc Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 21 Feb 2021 18:05:34 +0100 Subject: Only keeping useful infos from api responses --- app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt | 21 ++------------------- .../adjutor/aniki/topanime/RestTopAnimeResponse.kt | 6 ------ .../java/xyz/adjutor/aniki/topanime/TopAnime.kt | 6 ------ .../adjutor/aniki/topmanga/RestTopMangaResponse.kt | 6 ------ .../java/xyz/adjutor/aniki/topmanga/TopManga.kt | 6 ------ 5 files changed, 2 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt b/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt index 43944c3..baba9f5 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt @@ -2,30 +2,13 @@ package xyz.adjutor.aniki.manga import com.google.gson.annotations.SerializedName -//Content of the top field from the api of manga -class Manga{ +class Manga{ //only kept the infos I didnt have and that were interresting to me. - @SerializedName("url") - var url: String? = null - @SerializedName("title") - var title: String? = null - @SerializedName("rank") - var rank: Int? = null - @SerializedName("volumes") - var volumes: Int? = null @SerializedName("chapters") var chapters: Int? = null - @SerializedName("start_date") - var start_date: String? = null - @SerializedName("end_date") - var end_date: String? = null - @SerializedName("score") - var score: Float? = null - @SerializedName("image_url") - var image_url: String? = null @SerializedName("synopsis") var synopsis: String? = null @SerializedName("background") - var background: String? = null + var background: String? = null //a bit of background story about the manga } diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt index c711631..0bd1354 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt @@ -4,12 +4,6 @@ import com.google.gson.annotations.SerializedName class RestTopAnimeResponse { - @SerializedName("request_hash") - var request_hash: String? = null - @SerializedName("request_cached") - var request_cached: Boolean? = null - @SerializedName("request_cached_expiry") - var request_cached_expiry: Int? = null @SerializedName("top") var top: List? = null diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt index 3576e7b..e063ad1 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt @@ -11,18 +11,12 @@ class TopAnime{ var rank: Int? = null @SerializedName("title") var title: String? = null - @SerializedName("url") - var url: String? = null - @SerializedName("type") - var type: String? = null @SerializedName("episodes") var volumes: Int? = null @SerializedName("start_date") var start_date: String? = null @SerializedName("end_date") var end_date: String? = null - @SerializedName("members") - var members: Int? = null @SerializedName("score") var score: Float? = null @SerializedName("image_url") diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt index 897e8a2..dc7827a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt @@ -4,12 +4,6 @@ import com.google.gson.annotations.SerializedName class RestTopMangaResponse { - @SerializedName("request_hash") - var request_hash: String? = null - @SerializedName("request_cached") - var request_cached: Boolean? = null - @SerializedName("request_cached_expiry") - var request_cached_expiry: Int? = null @SerializedName("top") var top: List? = null diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt index edf561d..0f73dd4 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt @@ -11,18 +11,12 @@ class TopManga{ var rank: Int? = null @SerializedName("title") var title: String? = null - @SerializedName("url") - var url: String? = null - @SerializedName("type") - var type: String? = null @SerializedName("volumes") var volumes: Int? = null @SerializedName("start_date") var start_date: String? = null @SerializedName("end_date") var end_date: String? = null - @SerializedName("members") - var members: Int? = null @SerializedName("score") var score: Float? = null @SerializedName("image_url") -- cgit v1.2.3 From 6caf50512e0d5ec54493037ad5662229d8836eca Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 21 Feb 2021 18:07:27 +0100 Subject: Making activity_detail_top_manga.xml beautiful! --- .../aniki/topmanga/DetailTopMangaActivity.kt | 27 ++- .../main/res/layout/activity_detail_top_manga.xml | 205 +++++++++++++++++++-- app/src/main/res/values/strings.xml | 24 ++- 3 files changed, 221 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 2f0d2c3..9347f2c 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -6,24 +6,26 @@ import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions +import com.google.android.material.snackbar.Snackbar import xyz.adjutor.aniki.R class DetailTopMangaActivity : AppCompatActivity() { - private val currentMangaId = "themangaid" - private val currentMangaTitle = "themangatitle" - private val currentMangaRank = "themangarank" - private val currentMangaScore = "themangascore" - private val currentMangaImageUrl = "themangaimageurl" + + private val mangaId = "themangaid" + private val mangaTitle = "themangatitle" + private val mangaRank = "themangarank" + private val mangaScore = "themangascore" + private val mangaImageUrl = "themangaimageurl" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) - val mangaId = intent.getStringExtra(currentMangaId) - val mangaTitle = intent.getStringExtra(currentMangaTitle) - val mangaRank = intent.getStringExtra(currentMangaRank) - val mangaScore = intent.getStringExtra(currentMangaScore) - val mangaImage = intent.getStringExtra(currentMangaImageUrl) + val mangaId = intent.getStringExtra(mangaId) + val mangaTitle = intent.getStringExtra(mangaTitle) + val mangaRank = intent.getStringExtra(mangaRank) + val mangaScore = intent.getStringExtra(mangaScore) + val mangaImage = intent.getStringExtra(mangaImageUrl) val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) @@ -31,6 +33,11 @@ class DetailTopMangaActivity : AppCompatActivity() { val tvScore: TextView = findViewById(R.id.tv_detail_score) val ivImage: ImageView = findViewById(R.id.iv_detail_image) + //elements from Manga + val tvChapters: TextView = findViewById(R.id.tv_chapters) + val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) + val tvBackground: TextView = findViewById(R.id.tv_background) + tvId.text = mangaId tvTitle.text = mangaTitle tvRank.text = mangaRank diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index 42018ef..b9a5dd7 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -6,7 +6,24 @@ android:layout_height="match_parent" tools:context=".topmanga.DetailTopMangaActivity" android:background="@color/very_dark_purple"> + + + + app:layout_constraintTop_toTopOf="parent" /> + + android:textColor="@color/slightly_desaturated_magenta" + android:textSize="20sp" + app:layout_constraintBottom_toTopOf="@id/tv_detail_title" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@id/tv_detail_title" /> + + + + + + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toTopOf="parent"/> + + + + + + + + + - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 03d4a0e..100335d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,19 +3,31 @@ Settings Top Manga + Top Anime Home + Home Page - News Page - Article Page Top Manga Page + Top Anime Page + + 000000 Title 0 image - Image of manga - Top Anime Page - Top Anime 00.00 - 000000 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + "MAL ID : " + "Rank : " + "Score : " + 000 + "Volumes : " + "Chapters: " + 0000 + "Start date : " + "End date : " + Jan 0000 + Dec 0000 + Cras molestie turpis at lorem rutrum vehicula. Fusce rutrum, enim sed laoreet semper, tortor quam semper dui, id bibendum lacus quam vitae neque. + \ No newline at end of file -- cgit v1.2.3 From 94ab3bbeb21049ac1be128ee00dbae1570346123 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 21 Feb 2021 18:24:25 +0100 Subject: Displaying the other infos from the TopManga API. --- .../main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt | 2 +- .../xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 16 ++++++++++++++++ .../java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 6 ++++++ .../main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt index a333aae..53dca8a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt @@ -120,7 +120,7 @@ class TopAnimePage : Fragment() { } private fun showError() { - Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN API !? BUT IT WAS I, ERROR !", Snackbar.LENGTH_LONG) + Snackbar.make(requireView(), "API ERROR", Snackbar.LENGTH_LONG) .setAction("Action", null).show() } diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 9347f2c..27f602a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -17,6 +17,10 @@ class DetailTopMangaActivity : AppCompatActivity() { private val mangaScore = "themangascore" private val mangaImageUrl = "themangaimageurl" + private val mangaVolumes = "themangavolumes" + private val mangaStartDate = "themangastartdate" + private val mangaEndDate = "themangaenddate" + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) @@ -27,12 +31,20 @@ class DetailTopMangaActivity : AppCompatActivity() { val mangaScore = intent.getStringExtra(mangaScore) val mangaImage = intent.getStringExtra(mangaImageUrl) + val mangaVolumes = intent.getStringExtra(mangaVolumes) + val mangaStartDate = intent.getStringExtra(mangaStartDate) + val mangaEndDate = intent.getStringExtra(mangaEndDate) + val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) val tvRank: TextView = findViewById(R.id.tv_detail_rank) val tvScore: TextView = findViewById(R.id.tv_detail_score) val ivImage: ImageView = findViewById(R.id.iv_detail_image) + val tvVolumes: TextView = findViewById(R.id.tv_volumes) + val tvStartDate: TextView = findViewById(R.id.tv_start_date) + val tvEndDate: TextView = findViewById(R.id.tv_end_date) + //elements from Manga val tvChapters: TextView = findViewById(R.id.tv_chapters) val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) @@ -47,5 +59,9 @@ class DetailTopMangaActivity : AppCompatActivity() { .load(mangaImage) .apply(RequestOptions().override(400)) .into(ivImage) + + tvVolumes.text = mangaVolumes + tvStartDate.text = mangaStartDate + tvEndDate.text = mangaEndDate } } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index e46fc79..7a32dd5 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -60,6 +60,9 @@ class TopMangaAdapter(val mangaList: List) : val currentMangaRank = "themangarank" val currentMangaScore = "themangascore" val currentMangaImageUrl = "themangaimageurl" + val currentMangaVolumes = "themangavolumes" + val currentMangaStartDate = "themangastartdate" + val currentMangaEndDate = "themangaenddate" val intent: Intent = Intent(holder.itemView.context, DetailTopMangaActivity::class.java).apply { putExtra(currentMangaId, currentManga.mal_id.toString()) @@ -67,6 +70,9 @@ class TopMangaAdapter(val mangaList: List) : putExtra(currentMangaRank, currentManga.rank.toString()) putExtra(currentMangaScore, currentManga.score.toString()) putExtra(currentMangaImageUrl, currentManga.image_url.toString()) + putExtra(currentMangaVolumes, currentManga.volumes.toString()) + putExtra(currentMangaStartDate, currentManga.start_date) + putExtra(currentMangaEndDate, currentManga.end_date) } holder.itemView.context.startActivity(intent) } diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt index 697ba6f..c560ffd 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt @@ -96,7 +96,7 @@ class TopMangaPage : Fragment() { val mangaList: List = response.body()!!.getResults() //getting the "top" field containing our list of TopMangas saveList(mangaList) - showList(view, mangaList) // calling the method in charge of displaying on the recyclerview + showList(view, mangaList) //calling the method in charge of displaying on the recyclerview } else { showError() //a snackbar @@ -120,7 +120,7 @@ class TopMangaPage : Fragment() { } private fun showError() { - Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN API !? BUT IT WAS I, ERROR !", Snackbar.LENGTH_LONG) + Snackbar.make(requireView(), "API ERROR", Snackbar.LENGTH_LONG) .setAction("Action", null).show() } -- cgit v1.2.3 From 56f69f774bc2a7ef645169f85b89934255c29cf9 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 00:00:12 +0100 Subject: API call and display on DetailTopMangaActivity.kt Still need to find a way to call with the right ID. Rn, using the id 1 of monster as a "placeholder" --- app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt | 14 ----- .../java/xyz/adjutor/aniki/manga/MangaAdapter.kt | 58 ----------------- .../main/java/xyz/adjutor/aniki/manga/MangaApi.kt | 4 +- .../xyz/adjutor/aniki/manga/RestMangaResponse.kt | 14 +++++ .../xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt | 2 - .../aniki/topmanga/DetailTopMangaActivity.kt | 72 ++++++++++++++++++++-- .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 4 +- .../main/res/layout/activity_detail_top_manga.xml | 34 ++++++++-- app/src/main/res/values/strings.xml | 16 ++--- 9 files changed, 120 insertions(+), 98 deletions(-) delete mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt delete mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt create mode 100644 app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt b/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt deleted file mode 100644 index baba9f5..0000000 --- a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt +++ /dev/null @@ -1,14 +0,0 @@ -package xyz.adjutor.aniki.manga - -import com.google.gson.annotations.SerializedName - -class Manga{ //only kept the infos I didnt have and that were interresting to me. - - @SerializedName("chapters") - var chapters: Int? = null - @SerializedName("synopsis") - var synopsis: String? = null - @SerializedName("background") - var background: String? = null //a bit of background story about the manga - -} diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt deleted file mode 100644 index ad753e2..0000000 --- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt +++ /dev/null @@ -1,58 +0,0 @@ -@file:Suppress("DEPRECATION") - -package xyz.adjutor.aniki.manga - -import android.content.Intent -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import androidx.cardview.widget.CardView -import androidx.recyclerview.widget.RecyclerView -import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions -import xyz.adjutor.aniki.R -import xyz.adjutor.aniki.topmanga.DetailTopMangaActivity - -class MangaAdapter(val mangaList: List) : - RecyclerView.Adapter() { - - // Describes an item view and its place within the RecyclerView - class MangaViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val mangaTitle: TextView = itemView.findViewById(R.id.tv_title) - val mangaRank: TextView = itemView.findViewById(R.id.tv_rank) - val mangaScore: TextView = itemView.findViewById(R.id.tv_score) - val mangaImage: ImageView = itemView.findViewById(R.id.iv_image) - val cardview: CardView = itemView.findViewById(R.id.cv_cardView) - - } - - // Returns a new ViewHolder - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.item_layout, parent, false) - - return MangaViewHolder(view) - } - - // Returns size of data list - override fun getItemCount(): Int { - return mangaList.size - } - - // Displays data at a certain position - override fun onBindViewHolder(holder: MangaViewHolder, position: Int) { - val currentManga: Manga = mangaList[position] - holder.mangaTitle.text = currentManga.title - holder.mangaRank.text = currentManga.rank.toString() - holder.mangaScore.text = currentManga.score.toString() - val image: String = currentManga.image_url.toString() - Glide - .with(holder.itemView.context) - .load(image) - .apply(RequestOptions().override(400)) - .into(holder.mangaImage) - } -} - diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt index 7692836..77304bb 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt @@ -5,7 +5,7 @@ import retrofit2.http.GET interface MangaApi { - @GET("v3/manga") - fun getMangaData(): Call + @GET("v3/manga/1") + fun getMangaData(): Call } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt new file mode 100644 index 0000000..7a4aff9 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt @@ -0,0 +1,14 @@ +package xyz.adjutor.aniki.manga + +import com.google.gson.annotations.SerializedName + +class RestMangaResponse{ //only kept the infos I didnt have and that were interresting to me. + + @SerializedName("chapters") + var chapters: Int? = null + @SerializedName("synopsis") + var synopsis: String? = null + @SerializedName("background") + var background: String? = null //a bit of background story about the manga + +} diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt index 4953939..d38adb2 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package xyz.adjutor.aniki.topanime import android.view.LayoutInflater diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 27f602a..152fe4a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -1,16 +1,34 @@ package xyz.adjutor.aniki.topmanga +import android.content.Context import android.os.Bundle +import android.view.View import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.google.android.material.snackbar.Snackbar +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.R +import xyz.adjutor.aniki.manga.MangaApi +import xyz.adjutor.aniki.manga.RestMangaResponse class DetailTopMangaActivity : AppCompatActivity() { + var base_url = "https://api.jikan.moe/" + val gson = GsonBuilder() + .setLenient() + .create() + var manga: RestMangaResponse? = null + private val mangaId = "themangaid" private val mangaTitle = "themangatitle" private val mangaRank = "themangarank" @@ -45,11 +63,6 @@ class DetailTopMangaActivity : AppCompatActivity() { val tvStartDate: TextView = findViewById(R.id.tv_start_date) val tvEndDate: TextView = findViewById(R.id.tv_end_date) - //elements from Manga - val tvChapters: TextView = findViewById(R.id.tv_chapters) - val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) - val tvBackground: TextView = findViewById(R.id.tv_background) - tvId.text = mangaId tvTitle.text = mangaTitle tvRank.text = mangaRank @@ -63,5 +76,52 @@ class DetailTopMangaActivity : AppCompatActivity() { tvVolumes.text = mangaVolumes tvStartDate.text = mangaStartDate tvEndDate.text = mangaEndDate + + makeApiCall(base_url) + } + + private fun makeApiCall(BASE_URL: String) { + + val retrofit = Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create(gson)) + .build() + + val service = retrofit.create(MangaApi::class.java) + val call = service.getMangaData() + + 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 + + manga = response.body() //getting the RestMangaResponse fields + showDetail(manga!!) + + } else { + showError("API ERROR : is not successful") + } + } + + override fun onFailure(call: Call, t: Throwable) { + showError("API ERROR : onFailure") + } + + }) + } + + private fun showDetail(manga: RestMangaResponse) { + //elements from RestMangaResponse + val tvChapters: TextView = findViewById(R.id.tv_chapters) + val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) + val tvBackground: TextView = findViewById(R.id.tv_background) + + tvChapters.text = manga.chapters.toString() + tvSynopsis.text = manga.synopsis.toString() + tvBackground.text = manga.background.toString() + + } + + fun showError(text: String) { + Toast.makeText(this, text, Toast.LENGTH_LONG).show() } } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index 7a32dd5..c2b3567 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package xyz.adjutor.aniki.topmanga import android.content.Intent @@ -53,7 +51,7 @@ class TopMangaAdapter(val mangaList: List) : .apply(RequestOptions().override(400)) .into(holder.mangaImage) - //to go to the detail page of the selected manga + //when you click on a selected cardview, some datas are sent to the other activity holder.cardview.setOnClickListener { val currentMangaId = "themangaid" val currentMangaTitle = "themangatitle" diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index b9a5dd7..ffb9791 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -104,9 +104,10 @@ android:id="@+id/cv_more_infos" android:layout_width="match_parent" android:layout_height="wrap_content" - app:layout_constraintTop_toBottomOf="@id/cv_header" android:layout_margin="4sp" - app:cardBackgroundColor="@color/black"> + app:cardBackgroundColor="@color/black" + app:layout_constraintTop_toBottomOf="@id/cv_header"> + + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/tv_volumes" /> + + + + + + app:layout_constraintTop_toBottomOf="@id/tv_text_synopsis"/> @@ -226,6 +239,15 @@ android:layout_height="match_parent" android:padding="10dp"> + + + app:layout_constraintTop_toBottomOf="@id/tv_text_background"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 100335d..311e39b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,17 +17,19 @@ 00.00 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - "MAL ID : " - "Rank : " - "Score : " + "MAL ID " + "Rank " + "Score " 000 - "Volumes : " - "Chapters: " + "Volumes " + "Chapters " 0000 - "Start date : " - "End date : " + "Start date " + "End date " Jan 0000 Dec 0000 Cras molestie turpis at lorem rutrum vehicula. Fusce rutrum, enim sed laoreet semper, tortor quam semper dui, id bibendum lacus quam vitae neque. + Synopsis + Background \ No newline at end of file -- cgit v1.2.3 From a079577ca21e16dd4b424eea28498f7b56a297df Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 00:47:34 +0100 Subject: API's now being called with an ID as a parameter. --- .../main/java/xyz/adjutor/aniki/manga/MangaApi.kt | 5 ++- .../aniki/topmanga/DetailTopMangaActivity.kt | 47 +++++++++++----------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt index 77304bb..419d510 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt @@ -2,10 +2,11 @@ package xyz.adjutor.aniki.manga import retrofit2.Call import retrofit2.http.GET +import retrofit2.http.Path interface MangaApi { - @GET("v3/manga/1") - fun getMangaData(): Call + @GET("v3/manga/{id}") + fun getMangaData(@Path("id") id: String): Call } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 152fe4a..b222a99 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -23,35 +23,34 @@ import xyz.adjutor.aniki.manga.RestMangaResponse class DetailTopMangaActivity : AppCompatActivity() { - var base_url = "https://api.jikan.moe/" - val gson = GsonBuilder() + private var baseUrl = "https://api.jikan.moe/" + private val gson = GsonBuilder() .setLenient() .create() - var manga: RestMangaResponse? = null - private val mangaId = "themangaid" - private val mangaTitle = "themangatitle" - private val mangaRank = "themangarank" - private val mangaScore = "themangascore" - private val mangaImageUrl = "themangaimageurl" + private val intentMangaId = "themangaid" + private val intentMangaTitle = "themangatitle" + private val intentMangaRank = "themangarank" + private val intentMangaScore = "themangascore" + private val intentMangaImageUrl = "themangaimageurl" - private val mangaVolumes = "themangavolumes" - private val mangaStartDate = "themangastartdate" - private val mangaEndDate = "themangaenddate" + private val intentMangaVolumes = "themangavolumes" + private val intentMangaStartDate = "themangastartdate" + private val intentMangaEndDate = "themangaenddate" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) - val mangaId = intent.getStringExtra(mangaId) - val mangaTitle = intent.getStringExtra(mangaTitle) - val mangaRank = intent.getStringExtra(mangaRank) - val mangaScore = intent.getStringExtra(mangaScore) - val mangaImage = intent.getStringExtra(mangaImageUrl) + val mangaId = intent.getStringExtra(intentMangaId) + val mangaTitle = intent.getStringExtra(intentMangaTitle) + val mangaRank = intent.getStringExtra(intentMangaRank) + val mangaScore = intent.getStringExtra(intentMangaScore) + val mangaImage = intent.getStringExtra(intentMangaImageUrl) - val mangaVolumes = intent.getStringExtra(mangaVolumes) - val mangaStartDate = intent.getStringExtra(mangaStartDate) - val mangaEndDate = intent.getStringExtra(mangaEndDate) + val mangaVolumes = intent.getStringExtra(intentMangaVolumes) + val mangaStartDate = intent.getStringExtra(intentMangaStartDate) + val mangaEndDate = intent.getStringExtra(intentMangaEndDate) val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) @@ -73,14 +72,16 @@ class DetailTopMangaActivity : AppCompatActivity() { .apply(RequestOptions().override(400)) .into(ivImage) + //not used in the recyclerview tvVolumes.text = mangaVolumes tvStartDate.text = mangaStartDate tvEndDate.text = mangaEndDate - makeApiCall(base_url) + //taking the API's fields I want and displaying them + makeApiCall(baseUrl, mangaId.toString()) } - private fun makeApiCall(BASE_URL: String) { + private fun makeApiCall(BASE_URL: String, mangaId: String) { val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) @@ -88,13 +89,13 @@ class DetailTopMangaActivity : AppCompatActivity() { .build() val service = retrofit.create(MangaApi::class.java) - val call = service.getMangaData() + val call = service.getMangaData(mangaId) 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 - manga = response.body() //getting the RestMangaResponse fields + val manga = response.body() //getting the RestMangaResponse fields showDetail(manga!!) } else { -- cgit v1.2.3 From 3265956c1a74f2346c5f7fedaf938d71b69261ba Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 01:02:53 +0100 Subject: Replacing null values by an "Unknown" string. --- .../aniki/topmanga/DetailTopMangaActivity.kt | 33 ++++++++++++++++++---- .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index b222a99..5749071 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -72,10 +72,20 @@ class DetailTopMangaActivity : AppCompatActivity() { .apply(RequestOptions().override(400)) .into(ivImage) - //not used in the recyclerview - tvVolumes.text = mangaVolumes + //using null as a string because it has been converted to a string before + tvVolumes.text = if (mangaVolumes != "null"){ + mangaVolumes + } else { + fieldIsNull() + } + tvStartDate.text = mangaStartDate - tvEndDate.text = mangaEndDate + + tvEndDate.text = if (mangaEndDate != "null"){ + mangaEndDate + } else { + fieldIsNull() + } //taking the API's fields I want and displaying them makeApiCall(baseUrl, mangaId.toString()) @@ -116,13 +126,26 @@ class DetailTopMangaActivity : AppCompatActivity() { val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) val tvBackground: TextView = findViewById(R.id.tv_background) - tvChapters.text = manga.chapters.toString() + tvChapters.text = if (manga.chapters != null){ + manga.chapters.toString() + } else { + fieldIsNull() + } + tvSynopsis.text = manga.synopsis.toString() - tvBackground.text = manga.background.toString() + + tvBackground.text = if (manga.background != null){ + manga.background.toString() + } else { + fieldIsNull() + } } fun showError(text: String) { Toast.makeText(this, text, Toast.LENGTH_LONG).show() } + fun fieldIsNull(): String{ + return "Unknown" + } } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index c2b3567..c6fde13 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -70,7 +70,7 @@ class TopMangaAdapter(val mangaList: List) : putExtra(currentMangaImageUrl, currentManga.image_url.toString()) putExtra(currentMangaVolumes, currentManga.volumes.toString()) putExtra(currentMangaStartDate, currentManga.start_date) - putExtra(currentMangaEndDate, currentManga.end_date) + putExtra(currentMangaEndDate, currentManga.end_date.toString()) } holder.itemView.context.startActivity(intent) } -- cgit v1.2.3 From 8e2f9e71a8b5ca3c978007da5c6db59491349d84 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 01:25:50 +0100 Subject: Text justified and constrained better. --- app/build.gradle | 7 ++++--- .../xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 4 ---- app/src/main/res/layout/activity_detail_top_manga.xml | 13 +++++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fb76368..1e612ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,9 +46,10 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - //Recycleview + //Recycleview for lists implementation "androidx.recyclerview:recyclerview:1.1.0" - //Retrofit + + //Retrofit for REST APIs implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' @@ -59,7 +60,7 @@ dependencies { androidTestImplementation 'com.android.support:support-annotations:28.0.0' androidTestImplementation 'com.android.support.test:runner:1.0.2' - //to display images + //Glide to display images properly implementation 'com.github.bumptech.glide:glide:4.12.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 5749071..1863815 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -1,14 +1,10 @@ package xyz.adjutor.aniki.topmanga -import android.content.Context import android.os.Bundle -import android.view.View import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.google.gson.GsonBuilder diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index ffb9791..f5ce8b9 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -218,12 +218,12 @@ android:id="@+id/tv_synopsis" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:justificationMode="inter_word" android:text="@string/synopsis" android:textColor="@color/slightly_desaturated_magenta" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tv_text_synopsis"/> + app:layout_constraintTop_toBottomOf="@id/tv_text_synopsis" + tools:targetApi="o" /> @@ -248,16 +248,17 @@ android:textColor="@color/strong_pink" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"/> + + app:layout_constraintTop_toBottomOf="@id/tv_text_background" + tools:targetApi="o" /> -- cgit v1.2.3 From 9ee5918fa86da6c160145498b1a95f4f4a083fdc Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 14:25:15 +0100 Subject: Sharedpreference now working for the DetailTopMangaActivity.kt --- app/build.gradle | 1 - .../xyz/adjutor/aniki/manga/RestMangaResponse.kt | 4 ++- .../aniki/topmanga/DetailTopMangaActivity.kt | 41 ++++++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e612ce..d1d101c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,7 +34,6 @@ android { dependencies { - //noinspection GradleDependency implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt index 7a4aff9..00b0dce 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt @@ -2,8 +2,10 @@ package xyz.adjutor.aniki.manga import com.google.gson.annotations.SerializedName -class RestMangaResponse{ //only kept the infos I didnt have and that were interresting to me. +class RestMangaResponse{ //only kept the infos I didn't have and that were interesting to me. + @SerializedName("mal_id") + var mal_id: Int? = null @SerializedName("chapters") var chapters: Int? = null @SerializedName("synopsis") diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 1863815..32e3457 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -1,5 +1,7 @@ package xyz.adjutor.aniki.topmanga +import android.content.Context +import android.content.SharedPreferences import android.os.Bundle import android.widget.ImageView import android.widget.TextView @@ -8,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.google.gson.GsonBuilder +import com.google.gson.reflect.TypeToken import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -16,10 +19,12 @@ import retrofit2.converter.gson.GsonConverterFactory import xyz.adjutor.aniki.R import xyz.adjutor.aniki.manga.MangaApi import xyz.adjutor.aniki.manga.RestMangaResponse +import java.lang.reflect.Type class DetailTopMangaActivity : AppCompatActivity() { private var baseUrl = "https://api.jikan.moe/" + var sharedPreferences: SharedPreferences? = null private val gson = GsonBuilder() .setLenient() .create() @@ -38,6 +43,8 @@ class DetailTopMangaActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) + sharedPreferences = this.getSharedPreferences("app_aniki", Context.MODE_PRIVATE) + val mangaId = intent.getStringExtra(intentMangaId) val mangaTitle = intent.getStringExtra(intentMangaTitle) val mangaRank = intent.getStringExtra(intentMangaRank) @@ -83,8 +90,26 @@ class DetailTopMangaActivity : AppCompatActivity() { fieldIsNull() } - //taking the API's fields I want and displaying them - makeApiCall(baseUrl, mangaId.toString()) + val manga: RestMangaResponse? = getDataFromCache(mangaId.toString()) + if(manga != null ){ + showDetail(manga) + } else { + //taking the API's fields I want and displaying them + makeApiCall(baseUrl, mangaId.toString()) + } + + + } + + private fun getDataFromCache(mangaId: String): RestMangaResponse? { + val jsonManga: String?= sharedPreferences?.getString(mangaId, null) + + if(jsonManga == null) { + return null + } else { + val type: Type = object : TypeToken() {}.type + return gson.fromJson(jsonManga, type) + } } private fun makeApiCall(BASE_URL: String, mangaId: String) { @@ -95,13 +120,14 @@ class DetailTopMangaActivity : AppCompatActivity() { .build() val service = retrofit.create(MangaApi::class.java) - val call = service.getMangaData(mangaId) + val call = service.getMangaData(mangaId) //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 manga = response.body() //getting the RestMangaResponse fields + saveList(manga) showDetail(manga!!) } else { @@ -144,4 +170,13 @@ class DetailTopMangaActivity : AppCompatActivity() { fun fieldIsNull(): String{ return "Unknown" } + + fun saveList(manga: RestMangaResponse?) { + val jsonString: String = gson.toJson(manga) + + sharedPreferences + ?.edit() + ?.putString(manga?.mal_id.toString(), jsonString) + ?.apply() + } } \ No newline at end of file -- cgit v1.2.3 From 5e3f808975f32b5c3e2bd1fdf2fbe57de094b0b6 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 15:09:55 +0100 Subject: Scrollview added. Some mangas had too long background ans synopsis to fit. Scrollview resolve the issue. --- .../xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 13 ++++++------- app/src/main/res/layout/activity_detail_top_manga.xml | 15 +++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 32e3457..5950352 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -49,7 +49,7 @@ class DetailTopMangaActivity : AppCompatActivity() { val mangaTitle = intent.getStringExtra(intentMangaTitle) val mangaRank = intent.getStringExtra(intentMangaRank) val mangaScore = intent.getStringExtra(intentMangaScore) - val mangaImage = intent.getStringExtra(intentMangaImageUrl) + val mangaImageUrl = intent.getStringExtra(intentMangaImageUrl) val mangaVolumes = intent.getStringExtra(intentMangaVolumes) val mangaStartDate = intent.getStringExtra(intentMangaStartDate) @@ -71,7 +71,7 @@ class DetailTopMangaActivity : AppCompatActivity() { tvScore.text = mangaScore Glide .with(this) - .load(mangaImage) + .load(mangaImageUrl) .apply(RequestOptions().override(400)) .into(ivImage) @@ -98,17 +98,16 @@ class DetailTopMangaActivity : AppCompatActivity() { makeApiCall(baseUrl, mangaId.toString()) } - } private fun getDataFromCache(mangaId: String): RestMangaResponse? { val jsonManga: String?= sharedPreferences?.getString(mangaId, null) - if(jsonManga == null) { - return null + return if(jsonManga == null) { + null } else { val type: Type = object : TypeToken() {}.type - return gson.fromJson(jsonManga, type) + gson.fromJson(jsonManga, type) } } @@ -167,7 +166,7 @@ class DetailTopMangaActivity : AppCompatActivity() { fun showError(text: String) { Toast.makeText(this, text, Toast.LENGTH_LONG).show() } - fun fieldIsNull(): String{ + private fun fieldIsNull(): String{ return "Unknown" } diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index f5ce8b9..655b687 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -1,11 +1,14 @@ - + + > - + \ No newline at end of file -- cgit v1.2.3 From c3bc5b63aac55a9820a092889c42ef87bde90fff Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 15:21:40 +0100 Subject: Made some texviews selectable. --- app/src/main/res/layout/activity_detail_top_manga.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index 655b687..0364f99 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -35,7 +35,8 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/iv_detail_image" - android:textColor="@color/slightly_desaturated_magenta"/> + android:textColor="@color/slightly_desaturated_magenta" + android:textIsSelectable="true"/> + tools:targetApi="o" + android:textIsSelectable="true"/> @@ -261,7 +263,8 @@ android:textColor="@color/slightly_desaturated_magenta" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_text_background" - tools:targetApi="o" /> + tools:targetApi="o" + android:textIsSelectable="true"/> -- cgit v1.2.3 From 2f9de2df29150d092bfaa46ea93e3aad5496a219 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 17:55:34 +0100 Subject: Added selectable attribute to titles --- .../main/res/layout/activity_detail_top_manga.xml | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index 0364f99..dfeb8ba 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -1,14 +1,13 @@ - + tools:context=".topmanga.DetailTopMangaActivity"> + android:textColor="@color/strong_pink" + app:layout_constraintEnd_toStartOf="@id/tv_detail_id" /> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintEnd_toStartOf="@id/tv_detail_rank" + app:layout_constraintTop_toTopOf="@id/tv_detail_rank" /> + app:layout_constraintEnd_toStartOf="@id/tv_detail_score" + app:layout_constraintTop_toTopOf="@id/tv_detail_score" /> + app:cardBackgroundColor="@color/black" + app:layout_constraintTop_toBottomOf="@id/cv_more_infos"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + tools:targetApi="o" /> @@ -236,9 +236,9 @@ + app:cardBackgroundColor="@color/black" + app:layout_constraintTop_toBottomOf="@id/cv_synopsis"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + tools:targetApi="o" /> -- cgit v1.2.3 From b54b731b3333e3e7936a15ccff925ff8a203dd53 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 18:47:30 +0100 Subject: Removed justification and added links. Justification cropped the text, decided to get rid of it. Added a url to MAL, it's clickable. --- .../aniki/topmanga/DetailTopMangaActivity.kt | 5 +++ .../java/xyz/adjutor/aniki/topmanga/TopManga.kt | 2 + .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 2 + .../main/res/layout/activity_detail_top_manga.xml | 44 +++++++++++++++++++--- app/src/main/res/values/strings.xml | 2 + 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 5950352..70e1422 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -38,6 +38,7 @@ class DetailTopMangaActivity : AppCompatActivity() { private val intentMangaVolumes = "themangavolumes" private val intentMangaStartDate = "themangastartdate" private val intentMangaEndDate = "themangaenddate" + private val intentMangaUrl = "themangaurl" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -54,6 +55,7 @@ class DetailTopMangaActivity : AppCompatActivity() { val mangaVolumes = intent.getStringExtra(intentMangaVolumes) val mangaStartDate = intent.getStringExtra(intentMangaStartDate) val mangaEndDate = intent.getStringExtra(intentMangaEndDate) + val mangaUrl = intent.getStringExtra(intentMangaUrl) val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) @@ -64,6 +66,7 @@ class DetailTopMangaActivity : AppCompatActivity() { val tvVolumes: TextView = findViewById(R.id.tv_volumes) val tvStartDate: TextView = findViewById(R.id.tv_start_date) val tvEndDate: TextView = findViewById(R.id.tv_end_date) + val tvUrl: TextView = findViewById(R.id.tv_url) tvId.text = mangaId tvTitle.text = mangaTitle @@ -90,6 +93,8 @@ class DetailTopMangaActivity : AppCompatActivity() { fieldIsNull() } + tvUrl.text = mangaUrl + val manga: RestMangaResponse? = getDataFromCache(mangaId.toString()) if(manga != null ){ showDetail(manga) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt index 0f73dd4..05f4692 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt @@ -11,6 +11,8 @@ class TopManga{ var rank: Int? = null @SerializedName("title") var title: String? = null + @SerializedName("url") + var url: String? = null @SerializedName("volumes") var volumes: Int? = null @SerializedName("start_date") diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index c6fde13..d64a744 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -61,6 +61,7 @@ class TopMangaAdapter(val mangaList: List) : val currentMangaVolumes = "themangavolumes" val currentMangaStartDate = "themangastartdate" val currentMangaEndDate = "themangaenddate" + val currentMangaUrl = "themangaurl" val intent: Intent = Intent(holder.itemView.context, DetailTopMangaActivity::class.java).apply { putExtra(currentMangaId, currentManga.mal_id.toString()) @@ -71,6 +72,7 @@ class TopMangaAdapter(val mangaList: List) : putExtra(currentMangaVolumes, currentManga.volumes.toString()) putExtra(currentMangaStartDate, currentManga.start_date) putExtra(currentMangaEndDate, currentManga.end_date.toString()) + putExtra(currentMangaUrl, currentManga.url.toString()) } holder.itemView.context.startActivity(intent) } diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index dfeb8ba..6d069c9 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -222,18 +222,18 @@ android:id="@+id/tv_synopsis" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:justificationMode="inter_word" android:text="@string/synopsis" android:textColor="@color/slightly_desaturated_magenta" android:textIsSelectable="true" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_text_synopsis" - tools:targetApi="o" /> + /> + app:layout_constraintTop_toBottomOf="@id/tv_text_background" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 311e39b..a730c17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,5 +31,7 @@ Cras molestie turpis at lorem rutrum vehicula. Fusce rutrum, enim sed laoreet semper, tortor quam semper dui, id bibendum lacus quam vitae neque. Synopsis Background + "More info at" + https://myanimelist.net/media/id/name \ No newline at end of file -- cgit v1.2.3 From 965a5d66b4268e9e2f5bb5abb0af8d1500085517 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 18:59:54 +0100 Subject: starting the anime part Reusing what I did with mangas --- app/src/main/java/xyz/adjutor/aniki/anime/AnimeApi.kt | 12 ++++++++++++ .../main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/src/main/java/xyz/adjutor/aniki/anime/AnimeApi.kt create mode 100644 app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/AnimeApi.kt b/app/src/main/java/xyz/adjutor/aniki/anime/AnimeApi.kt new file mode 100644 index 0000000..ceb72b7 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/anime/AnimeApi.kt @@ -0,0 +1,12 @@ +package xyz.adjutor.aniki.anime + +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Path + +interface AnimeApi { + + @GET("v3/anime/{id}") + fun getMangaData(@Path("id") id: String): Call + +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt b/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt new file mode 100644 index 0000000..747ddaf --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt @@ -0,0 +1,14 @@ +package xyz.adjutor.aniki.anime + +import com.google.gson.annotations.SerializedName + +class RestAnimeResponse{ //only kept the infos I didn't have and that were interesting to me. + + @SerializedName("mal_id") + var mal_id: Int? = null + @SerializedName("synopsis") + var synopsis: String? = null + @SerializedName("background") + var background: String? = null + +} -- cgit v1.2.3 From e79bf68553676c9be09f4616aadcd522149c506e Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 19:51:27 +0100 Subject: Detail is now working for animes --- app/src/main/AndroidManifest.xml | 4 + .../main/java/xyz/adjutor/aniki/anime/AnimeApi.kt | 2 +- .../aniki/topanime/DetailTopAnimeActivity.kt | 179 +++++++++++++ .../java/xyz/adjutor/aniki/topanime/TopAnime.kt | 4 +- .../xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt | 43 ++- .../xyz/adjutor/aniki/topanime/TopAnimePage.kt | 6 +- .../aniki/topmanga/DetailTopMangaActivity.kt | 2 +- .../xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 6 +- .../xyz/adjutor/aniki/topmanga/TopMangaPage.kt | 2 +- .../main/res/layout/activity_detail_top_anime.xml | 287 +++++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 11 files changed, 518 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt create mode 100644 app/src/main/res/layout/activity_detail_top_anime.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5316b25..09802b7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,10 @@ android:name=".topmanga.DetailTopMangaActivity" android:label="Details" android:theme="@style/Theme.Aniki" /> + + fun getAnimeData(@Path("id") id: String): Call } \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt new file mode 100644 index 0000000..383c73e --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt @@ -0,0 +1,179 @@ +package xyz.adjutor.aniki.topanime + +import android.content.Context +import android.content.SharedPreferences +import android.os.Bundle +import android.widget.ImageView +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.google.gson.GsonBuilder +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.R +import xyz.adjutor.aniki.anime.AnimeApi +import xyz.adjutor.aniki.anime.RestAnimeResponse +import java.lang.reflect.Type + +class DetailTopAnimeActivity : AppCompatActivity() { + + private var baseUrl = "https://api.jikan.moe/" + var sharedPreferences: SharedPreferences? = null + private val gson = GsonBuilder() + .setLenient() + .create() + + private val intentAnimeId = "theanimeid" + private val intentAnimeTitle = "theanimetitle" + private val intentAnimeRank = "theanimerank" + private val intentAnimeScore = "theanimescore" + private val intentAnimeImageUrl = "theanimeimageurl" + + private val intentAnimeEpisodes = "theanimeepisodes" + private val intentAnimeStartDate = "theanimestartdate" + private val intentAnimeEndDate = "theanimeenddate" + private val intentAnimeUrl = "theanimeurl" + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_detail_top_anime) + + sharedPreferences = this.getSharedPreferences("sp_anime", Context.MODE_PRIVATE) + + val animeId = intent.getStringExtra(intentAnimeId) + val animeTitle = intent.getStringExtra(intentAnimeTitle) + val animeRank = intent.getStringExtra(intentAnimeRank) + val animeScore = intent.getStringExtra(intentAnimeScore) + val animeImageUrl = intent.getStringExtra(intentAnimeImageUrl) + + val animeEpisodes = intent.getStringExtra(intentAnimeEpisodes) + val animeStartDate = intent.getStringExtra(intentAnimeStartDate) + val animeEndDate = intent.getStringExtra(intentAnimeEndDate) + val animeUrl = intent.getStringExtra(intentAnimeUrl) + + val tvId: TextView = findViewById(R.id.tv_detail_id) + val tvTitle: TextView = findViewById(R.id.tv_detail_title) + val tvRank: TextView = findViewById(R.id.tv_detail_rank) + val tvScore: TextView = findViewById(R.id.tv_detail_score) + val ivImage: ImageView = findViewById(R.id.iv_detail_image) + + val tvEpisodes: TextView = findViewById(R.id.tv_episodes) + val tvStartDate: TextView = findViewById(R.id.tv_start_date) + val tvEndDate: TextView = findViewById(R.id.tv_end_date) + val tvUrl: TextView = findViewById(R.id.tv_url) + + tvId.text = animeId + tvTitle.text = animeTitle + tvRank.text = animeRank + tvScore.text = animeScore + Glide + .with(this) + .load(animeImageUrl) + .apply(RequestOptions().override(400)) + .into(ivImage) + + //using null as a string because it has been converted to a string before + tvEpisodes.text = if (animeEpisodes != "null"){ + animeEpisodes + } else { + fieldIsNull() + } + + tvStartDate.text = animeStartDate + + tvEndDate.text = if (animeEndDate != "null"){ + animeEndDate + } else { + fieldIsNull() + } + + tvUrl.text = animeUrl + + val anime: RestAnimeResponse? = getDataFromCache(animeId.toString()) + if(anime != null ){ + showDetail(anime) + } else { + //taking the API's fields I want and displaying them + makeApiCall(baseUrl, animeId.toString()) + } + + } + + private fun getDataFromCache(animeId: String): RestAnimeResponse? { + val jsonAnime: String?= sharedPreferences?.getString(animeId, null) + + return if(jsonAnime == null) { + null + } else { + val type: Type = object : TypeToken() {}.type + gson.fromJson(jsonAnime, type) + } + } + + 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 RestAnimeResponse fields + saveList(anime) + showDetail(anime!!) + + } else { + showError("API ERROR : is not successful") + } + } + + override fun onFailure(call: Call, t: Throwable) { + showError("API ERROR : onFailure") + } + + }) + } + + private fun showDetail(anime: RestAnimeResponse) { + //elements from RestAnimeResponse + val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) + val tvBackground: TextView = findViewById(R.id.tv_background) + + tvSynopsis.text = anime.synopsis.toString() + + tvBackground.text = if (anime.background != null){ + anime.background.toString() + } else { + fieldIsNull() + } + + } + + fun showError(text: String) { + Toast.makeText(this, text, Toast.LENGTH_LONG).show() + } + private fun fieldIsNull(): String{ + return "Unknown" + } + + fun saveList(anime: RestAnimeResponse?) { + val jsonString: String = gson.toJson(anime) + + sharedPreferences + ?.edit() + ?.putString(anime?.mal_id.toString(), jsonString) + ?.apply() + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt index e063ad1..1764878 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt @@ -11,8 +11,10 @@ class TopAnime{ var rank: Int? = null @SerializedName("title") var title: String? = null + @SerializedName("url") + var url: String? = null @SerializedName("episodes") - var volumes: Int? = null + var episodes: Int? = null @SerializedName("start_date") var start_date: String? = null @SerializedName("end_date") diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt index d38adb2..e5a2bb5 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt @@ -1,16 +1,18 @@ package xyz.adjutor.aniki.topanime +import android.content.Intent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R -class TopAnimeAdapter(val animeList: List) : +class TopAnimeAdapter(private val animeList: List) : RecyclerView.Adapter() { // Describes an item view and its place within the RecyclerView @@ -19,6 +21,7 @@ class TopAnimeAdapter(val animeList: List) : val animeRank: TextView = itemView.findViewById(R.id.tv_rank) val animeScore: TextView = itemView.findViewById(R.id.tv_score) val animeImage: ImageView = itemView.findViewById(R.id.iv_image) + val cardview: CardView = itemView.findViewById(R.id.cv_cardView) } // Returns a new ViewHolder @@ -40,13 +43,37 @@ class TopAnimeAdapter(val animeList: List) : holder.animeTitle.text = currentAnime.title holder.animeRank.text = currentAnime.rank.toString() holder.animeScore.text = currentAnime.score.toString() - val image : String = currentAnime.image_url.toString() + val image: String = currentAnime.image_url.toString() Glide - .with(holder.itemView.context) - .load(image) - .apply(RequestOptions().override(400)) - .into(holder.animeImage) - } + .with(holder.itemView.context) + .load(image) + .apply(RequestOptions().override(400)) + .into(holder.animeImage) -} + //when you click on a selected cardview, some datas are sent to the other activity + holder.cardview.setOnClickListener { + val currentAnimeId = "theanimeid" + val currentAnimeTitle = "theanimetitle" + val currentAnimeRank = "theanimerank" + val currentAnimeScore = "theanimescore" + val currentAnimeImageUrl = "theanimeimageurl" + val currentAnimeEpisodes = "theanimeepisodes" + val currentAnimeStartDate = "theanimestartdate" + val currentAnimeEndDate = "theanimeenddate" + val currentAnimeUrl = "theanimeurl" + val intent: Intent = Intent(holder.itemView.context, DetailTopAnimeActivity::class.java).apply { + putExtra(currentAnimeId, currentAnime.mal_id.toString()) + putExtra(currentAnimeTitle, currentAnime.title) + putExtra(currentAnimeRank, currentAnime.rank.toString()) + putExtra(currentAnimeScore, currentAnime.score.toString()) + putExtra(currentAnimeImageUrl, currentAnime.image_url.toString()) + putExtra(currentAnimeEpisodes, currentAnime.episodes.toString()) + putExtra(currentAnimeStartDate, currentAnime.start_date) + putExtra(currentAnimeEndDate, currentAnime.end_date.toString()) + putExtra(currentAnimeUrl, currentAnime.url.toString()) + } + holder.itemView.context.startActivity(intent) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt index 53dca8a..f2d5e4c 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt @@ -37,7 +37,7 @@ class TopAnimePage : Fragment() { // Inflate the layout for this fragment val view = inflater.inflate(R.layout.top_anime_page, container, false) - sharedPreferences = view.context.getSharedPreferences("app_aniki", Context.MODE_PRIVATE) + sharedPreferences = view.context.getSharedPreferences("sp_anime", Context.MODE_PRIVATE) val animeList: List? = getDataFromCache() if(animeList != null ){ @@ -94,9 +94,9 @@ class TopAnimePage : Fragment() { 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 = response.body()!!.getResults() //getting the "top" field containing our list of TopAnimes + val animeList: List = response.body()!!.getResults() //getting the "top" field containing our list of TopAnimes saveList(animeList) - showList(view, animeList) // calling the method in charge of displaying on the recyclerview + showList(view, animeList) //calling the method in charge of displaying on the recyclerview } else { showError() //a snackbar diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt index 70e1422..2b1fac4 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -44,7 +44,7 @@ class DetailTopMangaActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) - sharedPreferences = this.getSharedPreferences("app_aniki", Context.MODE_PRIVATE) + sharedPreferences = this.getSharedPreferences("sp_manga", Context.MODE_PRIVATE) val mangaId = intent.getStringExtra(intentMangaId) val mangaTitle = intent.getStringExtra(intentMangaTitle) diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt index d64a744..0396b3d 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt @@ -12,7 +12,7 @@ import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import xyz.adjutor.aniki.R -class TopMangaAdapter(val mangaList: List) : +class TopMangaAdapter(private val mangaList: List) : RecyclerView.Adapter() { // Describes an item view and its place within the RecyclerView @@ -22,7 +22,6 @@ class TopMangaAdapter(val mangaList: List) : val mangaScore: TextView = itemView.findViewById(R.id.tv_score) val mangaImage: ImageView = itemView.findViewById(R.id.iv_image) val cardview: CardView = itemView.findViewById(R.id.cv_cardView) - } // Returns a new ViewHolder @@ -77,5 +76,4 @@ class TopMangaAdapter(val mangaList: List) : holder.itemView.context.startActivity(intent) } } -} - +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt index c560ffd..f99cd9a 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt @@ -37,7 +37,7 @@ class TopMangaPage : Fragment() { // Inflate the layout for this fragment val view = inflater.inflate(R.layout.top_manga_page, container, false) - sharedPreferences = view.context.getSharedPreferences("app_aniki", Context.MODE_PRIVATE) + sharedPreferences = view.context.getSharedPreferences("sp_manga", Context.MODE_PRIVATE) val mangaList: List? = getDataFromCache() if(mangaList != null ){ diff --git a/app/src/main/res/layout/activity_detail_top_anime.xml b/app/src/main/res/layout/activity_detail_top_anime.xml new file mode 100644 index 0000000..6afa6ad --- /dev/null +++ b/app/src/main/res/layout/activity_detail_top_anime.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a730c17..bb9520a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,5 +33,7 @@ Background "More info at" https://myanimelist.net/media/id/name + "Episodes " + 0000 \ No newline at end of file -- cgit v1.2.3 From 494455de615340599cf2cdba0f3f199a47bf5a66 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 20:00:36 +0100 Subject: Removing background because most dont seem to have one. --- .../xyz/adjutor/aniki/anime/RestAnimeResponse.kt | 3 -- .../aniki/topanime/DetailTopAnimeActivity.kt | 7 ----- .../main/res/layout/activity_detail_top_anime.xml | 35 ---------------------- 3 files changed, 45 deletions(-) diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt b/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt index 747ddaf..aa15dfd 100644 --- a/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt +++ b/app/src/main/java/xyz/adjutor/aniki/anime/RestAnimeResponse.kt @@ -8,7 +8,4 @@ class RestAnimeResponse{ //only kept the infos I didn't have and that were inter var mal_id: Int? = null @SerializedName("synopsis") var synopsis: String? = null - @SerializedName("background") - var background: String? = null - } diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt index 383c73e..3f1d008 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/DetailTopAnimeActivity.kt @@ -149,16 +149,9 @@ class DetailTopAnimeActivity : AppCompatActivity() { private fun showDetail(anime: RestAnimeResponse) { //elements from RestAnimeResponse val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) - val tvBackground: TextView = findViewById(R.id.tv_background) tvSynopsis.text = anime.synopsis.toString() - tvBackground.text = if (anime.background != null){ - anime.background.toString() - } else { - fieldIsNull() - } - } fun showError(text: String) { diff --git a/app/src/main/res/layout/activity_detail_top_anime.xml b/app/src/main/res/layout/activity_detail_top_anime.xml index 6afa6ad..a982bdd 100644 --- a/app/src/main/res/layout/activity_detail_top_anime.xml +++ b/app/src/main/res/layout/activity_detail_top_anime.xml @@ -214,46 +214,11 @@ - - - - - - - - - - -