Explorar el Código

Image in fighter

dola hace 1 año
padre
commit
7dd6072a50

+ 20 - 1
app/src/main/java/com/sambath/kunkhmer/adapter/FighterAdapter.kt

@@ -23,6 +23,9 @@ import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
 import okhttp3.ResponseBody
+import java.text.SimpleDateFormat
+import java.util.Locale
+import java.util.TimeZone
 
 
 class FighterAdapter(private val cardList: List<Matches>, private val apiService: ApiService) : RecyclerView.Adapter<ViewHolder>() {
@@ -51,7 +54,7 @@ class FighterAdapter(private val cardList: List<Matches>, private val apiService
 
         //---------------------------------------
 
-        holder.date.text = currentItem.matchInfo.date
+        holder.date.text = parseAndFormatDate(currentItem.matchInfo.date)
         holder.title.text = currentItem.matchInfo.title
     }
 
@@ -67,4 +70,20 @@ class FighterAdapter(private val cardList: List<Matches>, private val apiService
         val title: TextView = itemView.findViewById(R.id.titleMatch)
         val favorite: ImageView = itemView.findViewById(R.id.bookmarkToggleButton)
     }
+
+    private fun parseAndFormatDate(dateString: String): String {
+        // Create a SimpleDateFormat for parsing the date string
+        val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault())
+        parser.timeZone = TimeZone.getTimeZone("UTC")
+
+        // Parse the date
+        val date = parser.parse(dateString)
+
+        // Create a SimpleDateFormat for formatting the date
+        val formatter = SimpleDateFormat("dd MMM yyyy HH:mm", Locale.getDefault())
+        formatter.timeZone = TimeZone.getDefault() // Use local timezone
+
+        // Format the date
+        return formatter.format(date)
+    }
 }

+ 3 - 4
app/src/main/res/layout/activity_main2.xml

@@ -30,13 +30,12 @@
         android:id="@+id/nav_host_fragment_activity_main"
         android:name="androidx.navigation.fragment.NavHostFragment"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_marginTop="?attr/actionBarSize"
+        android:layout_height="0dp"
+        app:layout_constraintTop_toBottomOf="@+id/app_bar"
+        app:layout_constraintBottom_toTopOf="@+id/nav_view"
         app:defaultNavHost="true"
-        app:layout_constraintBottom_toTopOf="@id/nav_view"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
         app:navGraph="@navigation/mobile_navigation" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 12 - 7
app/src/main/res/layout/layout_fighter_card.xml

@@ -17,10 +17,10 @@
         <ImageView
             android:id="@+id/bookmarkToggleButton"
             android:layout_width="30dp"
-            android:visibility="gone"
             android:layout_height="30dp"
             android:layout_margin="5dp"
-            android:src="@drawable/ic_star_50" />
+            android:src="@drawable/ic_star_50"
+            android:visibility="gone" />
 
         <LinearLayout
             android:layout_width="match_parent"
@@ -52,7 +52,8 @@
                     android:text="@string/title_fighters"
                     android:textAlignment="center"
                     android:textColor="@color/color_white"
-                    android:textSize="12sp" />
+                    android:textSize="12sp"
+                    android:textStyle="bold" />
 
             </LinearLayout>
 
@@ -60,6 +61,7 @@
             <LinearLayout
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
+                android:layout_gravity="center"
                 android:layout_weight="1"
                 android:orientation="vertical">
 
@@ -71,7 +73,8 @@
                     android:text="@string/title_vs"
                     android:textAlignment="center"
                     android:textColor="@color/color_white"
-                    android:textSize="12sp" />
+                    android:textSize="12sp"
+                    android:textStyle="bold" />
 
                 <TextView
                     android:id="@+id/tvDate"
@@ -82,7 +85,8 @@
                     android:text="@string/title_date"
                     android:textAlignment="center"
                     android:textColor="@color/color_white"
-                    android:textSize="12sp" />
+                    android:textSize="12sp"
+                    android:textStyle="bold" />
 
             </LinearLayout>
 
@@ -110,7 +114,8 @@
                     android:text="@string/title_fighters"
                     android:textAlignment="center"
                     android:textColor="@color/color_white"
-                    android:textSize="12sp" />
+                    android:textSize="12sp"
+                    android:textStyle="bold" />
             </LinearLayout>
         </LinearLayout>
 
@@ -128,6 +133,6 @@
             android:text="@string/title_fighters"
             android:textAlignment="center"
             android:textColor="@color/color_white"
-            android:textSize="12sp" />
+            android:textStyle="bold" />
     </LinearLayout>
 </androidx.cardview.widget.CardView>