blob: f378c65e73b6e5d702d3c0ec86fa20ae84b29809 (
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
|
package xyz.adjutor.aniki
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
class MangaAdapter(val mangaList: List<TopManga>) :
RecyclerView.Adapter<MangaAdapter.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 mangaImage: ImageView = itemView.findViewById(R.id.iv_image)
}
// 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 //use specific json data
holder.mangaRank.text = currentManga.rank.toString() //replace by the actual rank
//holder.mangaImage.setImageResource(mangaList[position]) //replace by the manga image
}
}
|