Dola TENG 1 rok temu
rodzic
commit
5de437d63e

+ 19 - 5
app/src/main/java/com/sambath/sbc/adapter/FighterAdapter.kt

@@ -1,5 +1,6 @@
 package com.sambath.sbc.adapter
 
+import android.graphics.drawable.Drawable
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -26,13 +27,26 @@ class FighterAdapter (private val cardList: List<FighterCardItem>) : RecyclerVie
         holder.imageRightTitle.text = currentItem.imageRightTitle
         holder.date.text = currentItem.date
         holder.title.text = currentItem.title
-        holder.favorite.setOnCheckedChangeListener { buttonView, isChecked ->
-            if (currentItem.favorite) {
+
+        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
-                buttonView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_user, 0, 0)
+                val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_filled_50)
+                holder.favorite.setImageDrawable(drawable)
+                currentItem.favorite = true
             } else {
                 // Perform unbookmarking action
-                buttonView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_user, 0, 0)
+                val drawable: Drawable? = holder.itemView.context.getDrawable(R.drawable.ic_star_50)
+                holder.favorite.setImageDrawable(drawable)
+                currentItem.favorite = false
             }
         }
 
@@ -48,6 +62,6 @@ class FighterAdapter (private val cardList: List<FighterCardItem>) : RecyclerVie
         val imageRightTitle: TextView = itemView.findViewById(R.id.titleRight)
         val date: TextView = itemView.findViewById(R.id.tvDate)
         val title: TextView = itemView.findViewById(R.id.titleMatch)
-        val favorite: ToggleButton = itemView.findViewById(R.id.bookmarkToggleButton)
+        val favorite: ImageView = itemView.findViewById(R.id.bookmarkToggleButton)
     }
 }

+ 1 - 1
app/src/main/java/com/sambath/sbc/adapter/FighterCardItem.kt

@@ -7,5 +7,5 @@ data class FighterCardItem(
     val imageRightTitle: String,
     val date: String,
     val title: String,
-    val favorite: Boolean
+    var favorite: Boolean
 )

BIN
app/src/main/res/drawable/ic_star_100.png


BIN
app/src/main/res/drawable/ic_star_50.png


BIN
app/src/main/res/drawable/ic_star_filled_100.png


BIN
app/src/main/res/drawable/ic_star_filled_50.png


+ 16 - 9
app/src/main/res/layout/layout_fighter_card.xml

@@ -14,16 +14,23 @@
         android:orientation="vertical"
         app:cardCornerRadius="0dp">
 
-        <ToggleButton
+        <!--        <ToggleButton-->
+        <!--            android:id="@+id/bookmarkToggleButton"-->
+        <!--            android:layout_width="30dp"-->
+        <!--            android:layout_height="30dp"-->
+        <!--            android:layout_centerInParent="true"-->
+        <!--            android:background="@android:color/transparent"-->
+        <!--            android:drawableStart="@drawable/ic_star_50"-->
+        <!--            android:drawablePadding="8dp"-->
+        <!--            android:textOff=""-->
+        <!--            android:textOn="" />-->
+
+        <ImageView
             android:id="@+id/bookmarkToggleButton"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_centerInParent="true"
-            android:background="@android:color/transparent"
-            android:drawableStart="@drawable/ic_user"
-            android:drawablePadding="8dp"
-            android:textOff=""
-            android:textOn="" />
+            android:layout_width="30dp"
+            android:layout_height="30dp"
+            android:layout_margin="5dp"
+            android:src="@drawable/ic_star_50" />
 
         <LinearLayout
             android:layout_width="match_parent"