HighlightNewsAdapter.kt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.sambath.kunkhmer.adapter
  2. import android.view.LayoutInflater
  3. import android.view.View
  4. import android.view.ViewGroup
  5. import android.widget.ImageView
  6. import android.widget.TextView
  7. import androidx.recyclerview.widget.RecyclerView
  8. import com.sambath.kunkhmer.R
  9. import com.sambath.kunkhmer.config.Config
  10. import com.sambath.kunkhmer.remote.Highlight
  11. import com.squareup.picasso.Picasso
  12. class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView.Adapter<HighlightNewsAdapter.ViewHolder>() {
  13. class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
  14. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  15. val itemView = LayoutInflater.from(parent.context)
  16. .inflate(R.layout.layout_highlight_item_card, parent, false)
  17. return ViewHolder(itemView)
  18. }
  19. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  20. val currentItem = cardList[position]
  21. // Picasso.get()
  22. // .load(Config.BASE_URL + "/v1/fighter/image/" + currentItem.)
  23. // .into(holder.imageView);
  24. holder.dateTextView.text = currentItem.date
  25. holder.titleTextView.text = currentItem.title
  26. }
  27. override fun getItemCount() = cardList.size
  28. // Holds the views for adding it to image and text
  29. class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
  30. val imageView: ImageView = itemView.findViewById(R.id.imageView)
  31. val dateTextView: TextView = itemView.findViewById(R.id.dateTextView)
  32. val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
  33. }
  34. }