package xyz.adjutor.aniki.topanime 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 TopAnimeAdapter(val animeList: List) : RecyclerView.Adapter() { // Describes an item view and its place within the RecyclerView class AnimeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val animeTitle: TextView = itemView.findViewById(R.id.tv_title) 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 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AnimeViewHolder { val view = LayoutInflater.from(parent.context) .inflate(R.layout.item_layout, parent, false) return AnimeViewHolder(view) } // Returns size of data list override fun getItemCount(): Int { return animeList.size } // Displays data at a certain position override fun onBindViewHolder(holder: AnimeViewHolder, position: Int) { val currentAnime: TopAnime = animeList[position] holder.animeTitle.text = currentAnime.title holder.animeRank.text = currentAnime.rank.toString() holder.animeScore.text = currentAnime.score.toString() val image : String = currentAnime.image_url.toString() Glide .with(holder.itemView.context) .load(image) .apply(RequestOptions().override(400)) .into(holder.animeImage) } }