blob: 2eaf958cd57265d987d5000ea77c60a4ab3240f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
@file:Suppress("DEPRECATION")
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
import xyz.adjutor.aniki.R
class TopMangaAdapter(val mangaList: List<TopManga>) :
RecyclerView.Adapter<TopMangaAdapter.MangaViewHolder>() {
// 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: TopManga = 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)
//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)
}
}
}
|