From a9a6ab39a9bb7c5b8a3c1f20e2e56fd902bf0cd7 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 14 Mar 2021 13:01:06 +0100 Subject: Added detail for searched animes. --- app/src/main/AndroidManifest.xml | 4 + .../java/xyz/adjutor/aniki/anime/AnimeResponse.kt | 4 + .../anime/search/DetailSearchAnimeActivity.kt | 156 +++++++++++++ .../xyz/adjutor/aniki/anime/search/SearchAnime.kt | 2 +- .../aniki/anime/search/SearchAnimeAdapter.kt | 21 +- .../xyz/adjutor/aniki/manga/search/SearchManga.kt | 2 +- .../aniki/manga/search/SearchMangaAdapter.kt | 1 - .../res/layout/activity_detail_search_anime.xml | 259 +++++++++++++++++++++ 8 files changed, 436 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/xyz/adjutor/aniki/anime/search/DetailSearchAnimeActivity.kt create mode 100644 app/src/main/res/layout/activity_detail_search_anime.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4c79bd2..4de763c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,10 @@ android:name="xyz.adjutor.aniki.manga.search.DetailSearchMangaActivity" android:label="Details" android:theme="@style/Theme.Aniki" /> + { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty + + val anime = response.body() //getting the AnimeResponse fields + showDetail(anime!!) + + } else { + showError("API ERROR : is not successful") + } + } + + override fun onFailure(call: Call, t: Throwable) { + showError("API ERROR : onFailure") + } + + }) + } + + private fun showDetail(anime: AnimeResponse) { + //elements from AnimeResponse + val tvSynopsis: TextView = findViewById(R.id.tv_synopsis) + val tvRank: TextView = findViewById(R.id.tv_detail_rank) + + tvSynopsis.text = anime.synopsis.toString() + + tvRank.text = anime.rank.toString() + + } + + fun showError(text: String) { + Toast.makeText(this, text, Toast.LENGTH_LONG).show() + } + + private fun fieldIsNull(): String { + return "Unknown" + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnime.kt b/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnime.kt index 7771646..ad7b7eb 100644 --- a/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnime.kt +++ b/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnime.kt @@ -28,4 +28,4 @@ class SearchAnime { @SerializedName("end_date") //we'll maybe remove this later var end_date: String? = null -} +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnimeAdapter.kt index a3a4a97..78718dd 100644 --- a/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnimeAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/anime/search/SearchAnimeAdapter.kt @@ -1,10 +1,12 @@ package xyz.adjutor.aniki.anime.search +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 @@ -19,7 +21,7 @@ class SearchAnimeAdapter(private 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) + val cardview: CardView = itemView.findViewById(R.id.cv_cardView) } // Returns a new ViewHolder @@ -39,7 +41,7 @@ class SearchAnimeAdapter(private val animeList: List) : override fun onBindViewHolder(holder: AnimeViewHolder, position: Int) { val currentAnime: SearchAnime = animeList[position] holder.animeTitle.text = currentAnime.title - holder.animeRank.text = "" //the rank isnt supplied by this API + holder.animeRank.text = "" //the rank isn't supplied by this API holder.animeScore.text = currentAnime.score.toString() val image: String = currentAnime.image_url.toString() Glide @@ -48,33 +50,32 @@ class SearchAnimeAdapter(private val animeList: List) : .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 currentAnimeUrl = "theanimeurl" + val currentAnimeImageUrl = "theanimeimageurl" val currentAnimeTitle = "theanimetitle" + val currentAnimeEpisodes = "theanimeepisodes" val currentAnimeScore = "theanimescore" - val currentAnimeImageUrl = "theanimeimageurl" - val currentAnimeVolumes = "theanimevolumes" val currentAnimeStartDate = "theanimestartdate" val currentAnimeEndDate = "theanimeenddate" - val currentAnimeUrl = "theanimeurl" //intent is used to pass data to another activity val intent: Intent = Intent(holder.itemView.context, DetailSearchAnimeActivity::class.java).apply { putExtra(currentAnimeId, currentAnime.mal_id.toString()) + putExtra(currentAnimeUrl, currentAnime.url.toString()) + putExtra(currentAnimeImageUrl, currentAnime.image_url.toString()) putExtra(currentAnimeTitle, currentAnime.title) + putExtra(currentAnimeEpisodes, currentAnime.episodes.toString()) putExtra(currentAnimeScore, currentAnime.score.toString()) - putExtra(currentAnimeImageUrl, currentAnime.image_url.toString()) - putExtra(currentAnimeVolumes, currentAnime.volumes.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/manga/search/SearchManga.kt b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchManga.kt index 53899e2..518a0a6 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchManga.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchManga.kt @@ -31,4 +31,4 @@ class SearchManga { @SerializedName("end_date") //we'll maybe remove this later var end_date: String? = null -} +} \ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaAdapter.kt index 79f8cb3..fb95c9c 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaAdapter.kt @@ -50,7 +50,6 @@ class SearchMangaAdapter(private val mangaList: List) : .apply(RequestOptions().override(400)) .into(holder.mangaImage) - //when you click on a selected cardview, some datas are sent to the other activity holder.cardview.setOnClickListener { val currentMangaId = "themangaid" diff --git a/app/src/main/res/layout/activity_detail_search_anime.xml b/app/src/main/res/layout/activity_detail_search_anime.xml new file mode 100644 index 0000000..90f2459 --- /dev/null +++ b/app/src/main/res/layout/activity_detail_search_anime.xml @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3