|
@@ -1,6 +1,7 @@
|
|
|
package com.sambath.kunkhmer.adapter
|
|
|
|
|
|
import android.graphics.drawable.Drawable
|
|
|
+import android.util.Patterns
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
@@ -8,8 +9,11 @@ import android.widget.ImageView
|
|
|
import android.widget.TextView
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.sambath.kunkhmer.R
|
|
|
+import com.sambath.kunkhmer.remote.Matches
|
|
|
+import com.squareup.picasso.Picasso
|
|
|
|
|
|
-class FighterAdapter (private val cardList: List<FighterCardItem>) : RecyclerView.Adapter<FighterAdapter.ViewHolder>() {
|
|
|
+
|
|
|
+class FighterAdapter (private val cardList: List<Matches>) : RecyclerView.Adapter<FighterAdapter.ViewHolder>() {
|
|
|
class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FighterAdapter.ViewHolder {
|
|
@@ -20,34 +24,56 @@ class FighterAdapter (private val cardList: List<FighterCardItem>) : RecyclerVie
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
val currentItem = cardList[position]
|
|
|
|
|
|
- holder.imageLeft.setImageResource(currentItem.imageLeft)
|
|
|
- holder.imageLeftTitle.text = currentItem.imageLeftTitle
|
|
|
- holder.imageRight.setImageResource(currentItem.imageRight)
|
|
|
- holder.imageRightTitle.text = currentItem.imageRightTitle
|
|
|
- holder.date.text = currentItem.date
|
|
|
- holder.title.text = currentItem.title
|
|
|
-
|
|
|
- if(currentItem.favorite) {
|
|
|
- val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_filled_50)
|
|
|
- holder.favorite.setImageDrawable(drawable)
|
|
|
+ val imageUrl = currentItem.fighters[0].filename
|
|
|
+ if (Patterns.WEB_URL.matcher(imageUrl).matches()) {
|
|
|
+ // Load image from URL
|
|
|
+ Picasso.get()
|
|
|
+ .load(currentItem.fighters[0].filename)
|
|
|
+ .into(holder.imageLeft);
|
|
|
} else {
|
|
|
- val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_50)
|
|
|
- holder.favorite.setImageDrawable(drawable)
|
|
|
+ // Load default image
|
|
|
+ Picasso.get()
|
|
|
+ .load(R.drawable.ic_user_white)
|
|
|
+ .into(holder.imageLeft)
|
|
|
}
|
|
|
|
|
|
- holder.favorite.setOnClickListener{
|
|
|
- if (!currentItem.favorite) {
|
|
|
- // Perform bookmarking action
|
|
|
- val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_filled_50)
|
|
|
- holder.favorite.setImageDrawable(drawable)
|
|
|
- currentItem.favorite = true
|
|
|
- } else {
|
|
|
- // Perform unbookmarking action
|
|
|
- val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_50)
|
|
|
- holder.favorite.setImageDrawable(drawable)
|
|
|
- currentItem.favorite = false
|
|
|
- }
|
|
|
+ holder.imageLeftTitle.text = currentItem.fighters[0]?.name
|
|
|
+ if (Patterns.WEB_URL.matcher(imageUrl).matches()) {
|
|
|
+ // Load image from URL
|
|
|
+ Picasso.get()
|
|
|
+ .load(currentItem.fighters[0].filename)
|
|
|
+ .into(holder.imageRight);
|
|
|
+ } else {
|
|
|
+ // Load default image
|
|
|
+ Picasso.get()
|
|
|
+ .load(R.drawable.ic_user_white)
|
|
|
+ .into(holder.imageRight)
|
|
|
}
|
|
|
+ holder.imageRightTitle.text = currentItem.fighters[1]?.name
|
|
|
+ holder.date.text = currentItem.matchInfo.date
|
|
|
+ holder.title.text = currentItem.matchInfo.title
|
|
|
+
|
|
|
+// if(currentItem.favorite) {
|
|
|
+// val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_filled_50)
|
|
|
+// holder.favorite.setImageDrawable(drawable)
|
|
|
+// } else {
|
|
|
+// val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_50)
|
|
|
+// holder.favorite.setImageDrawable(drawable)
|
|
|
+// }
|
|
|
+
|
|
|
+// holder.favorite.setOnClickListener{
|
|
|
+// if (!currentItem.favorite) {
|
|
|
+// // Perform bookmarking action
|
|
|
+// val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_filled_50)
|
|
|
+// holder.favorite.setImageDrawable(drawable)
|
|
|
+// currentItem.favorite = true
|
|
|
+// } else {
|
|
|
+// // Perform unbookmarking action
|
|
|
+// val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_50)
|
|
|
+// holder.favorite.setImageDrawable(drawable)
|
|
|
+// currentItem.favorite = false
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|