aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-22 19:51:27 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-22 19:51:27 +0100
commite79bf68553676c9be09f4616aadcd522149c506e (patch)
tree835124a1b912ec15ab59cd6729a33f1fc5ffc6d0 /app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt
parent965a5d66b4268e9e2f5bb5abb0af8d1500085517 (diff)
Detail is now working for animes
Diffstat (limited to 'app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt43
1 files changed, 35 insertions, 8 deletions
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<TopAnime>) :
+class TopAnimeAdapter(private val animeList: List<TopAnime>) :
RecyclerView.Adapter<TopAnimeAdapter.AnimeViewHolder>() {
// Describes an item view and its place within the RecyclerView
@@ -19,6 +21,7 @@ class TopAnimeAdapter(val animeList: List<TopAnime>) :
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<TopAnime>) :
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