dola 1 éve
szülő
commit
766e6092b9

+ 2 - 0
app/src/main/java/com/sambath/kunkhmer/adapter/FighterAdapter.kt

@@ -44,12 +44,14 @@ class FighterAdapter(private val cardList: List<Matches>, private val apiService
         holder.imageLeftTitle.text = currentItem.fighters[0]?.name
         Picasso.get()
             .load(Config.BASE_URL + "/v1/fighter/image/" + currentItem.fighters[0].filename)
+            .placeholder(R.drawable.ic_logo_header)
             .into(holder.imageLeft);
 
         //------------------------------Right
         holder.imageRightTitle.text = currentItem.fighters[1]?.name
         Picasso.get()
             .load(Config.BASE_URL + "/v1/fighter/image/" + currentItem.fighters[1].filename)
+            .placeholder(R.drawable.ic_logo_header)
             .into(holder.imageRight);
 
         //---------------------------------------

+ 7 - 3
app/src/main/java/com/sambath/kunkhmer/adapter/HighlightNewsAdapter.kt

@@ -22,10 +22,14 @@ class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
         val currentItem = cardList[position]
+        val videoId = currentItem.url.substringAfterLast("/")
+        val thumbnailUrl = "https://img.youtube.com/vi/$videoId/0.jpg"
+
+        Picasso.get()
+            .load(thumbnailUrl)
+            .placeholder(R.drawable.ic_logo_header)
+            .into(holder.imageView);
 
-//        Picasso.get()
-//            .load(Config.BASE_URL + "/v1/fighter/image/" + currentItem.)
-//            .into(holder.imageView);
         holder.dateTextView.text = currentItem.date
         holder.titleTextView.text = currentItem.title
     }

+ 29 - 7
app/src/main/java/com/sambath/kunkhmer/adapter/TopNewsAdapter.kt

@@ -11,9 +11,11 @@ import com.sambath.kunkhmer.config.Config
 import com.sambath.kunkhmer.remote.News
 import com.sambath.kunkhmer.remote.NewsData
 import com.squareup.picasso.Picasso
+import java.text.SimpleDateFormat
+import java.util.Locale
+import java.util.TimeZone
 
 class TopNewsAdapter(var cardList: MutableList<News>) : RecyclerView.Adapter<TopNewsAdapter.ViewHolder>() {
-    class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
         val itemView = LayoutInflater.from(parent.context).inflate(R.layout.layout_top_news_item_card, parent, false)
@@ -22,18 +24,22 @@ class TopNewsAdapter(var cardList: MutableList<News>) : RecyclerView.Adapter<Top
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
         val currentItem = cardList[position]
-
-        Picasso.get()
-            .load(Config.BASE_URL + "/v1/new/image/" + currentItem.filename)
-            .into(holder.imageView);
-        holder.dateTextView.text = currentItem.createdAt
+        if (!currentItem.filename.isNullOrEmpty()) {
+            Picasso.get()
+                .load(Config.BASE_URL + "/v1/new/image/" + currentItem.filename)
+                .into(holder.imageView);
+        } else {
+            Picasso.get()
+                .load(R.drawable.ic_logo_header)
+                .into(holder.imageView);
+        }
+        holder.dateTextView.text = parseAndFormatDate(currentItem.createdAt)
         holder.titleTextView.text = currentItem.title
         holder.subTextView.text = currentItem.desc
     }
 
     override fun getItemCount() = cardList.size
 
-
     // Holds the views for adding it to image and text
     class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
         val imageView: ImageView = itemView.findViewById(R.id.imageView)
@@ -41,4 +47,20 @@ class TopNewsAdapter(var cardList: MutableList<News>) : RecyclerView.Adapter<Top
         val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
         val subTextView: TextView = itemView.findViewById(R.id.descTextView)
     }
+
+    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)
+    }
 }

+ 1 - 1
app/src/main/java/com/sambath/kunkhmer/remote/NewsDataModel.kt

@@ -32,5 +32,5 @@ data class News(
     @Json(name = "createdAt")
     val createdAt: String,
     @Json(name = "filename")
-    val filename: String,
+    val filename: String?,
 )

+ 0 - 2
app/src/main/java/com/sambath/kunkhmer/screen/news/NewsFragment.kt

@@ -49,8 +49,6 @@ class NewsFragment : Fragment() {
         }
 
         newsViewModel = NewsViewModel(App.injectApiService(), App.injectPrefHelper())
-//        newsViewModel.getNews()
-//        newsViewModel.getHighlight()
         newsViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
             render(it)
         })

+ 2 - 2
app/src/main/res/layout/layout_fighter_card.xml

@@ -40,7 +40,7 @@
                     android:layout_width="100dp"
                     android:layout_height="100dp"
                     android:layout_gravity="center"
-                    android:scaleType="centerCrop"
+                    android:scaleType="fitCenter"
                     android:src="@drawable/ic_user_white" />
 
                 <TextView
@@ -102,7 +102,7 @@
                     android:layout_width="100dp"
                     android:layout_height="100dp"
                     android:layout_gravity="center"
-                    android:scaleType="centerCrop"
+                    android:scaleType="fitCenter"
                     android:src="@drawable/ic_user_white" />
 
                 <TextView

+ 1 - 1
app/src/main/res/layout/layout_highlight_item_card.xml

@@ -18,7 +18,7 @@
             android:layout_width="match_parent"
             android:layout_height="200dp"
             android:background="@color/color_gray_600"
-            android:scaleType="centerCrop" />
+            android:scaleType="fitCenter" />
 
         <LinearLayout
             android:layout_width="match_parent"

+ 6 - 6
app/src/main/res/layout/layout_top_news_item_card.xml

@@ -17,8 +17,8 @@
             android:id="@+id/imageView"
             android:layout_width="150dp"
             android:layout_height="120dp"
-            android:scaleType="centerCrop"
-            android:src="@color/color_gray_600" />
+            android:scaleType="fitCenter"
+            android:src="@drawable/ic_logo_header" />
 
         <LinearLayout
             android:layout_width="match_parent"
@@ -30,7 +30,6 @@
                 android:id="@+id/titleTextView"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:text="Your Title"
                 android:textColor="@color/color_white"
                 android:textSize="16sp"
                 android:textStyle="bold" />
@@ -39,18 +38,20 @@
                 android:id="@+id/descTextView"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:text="Description......................................................"
+                android:ellipsize="end"
+                android:maxLines="2"
                 android:textColor="@color/color_white"
                 android:textSize="14sp" />
 
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
+                android:layout_marginLeft="-15px"
                 android:orientation="horizontal">
 
                 <ImageView
                     android:layout_width="25dp"
-                    android:layout_height="25dp"
+                    android:layout_height="20dp"
                     android:src="@drawable/ic_alarm_clock_64" />
 
                 <TextView
@@ -59,7 +60,6 @@
                     android:layout_height="wrap_content"
                     android:layout_gravity="center_vertical"
                     android:gravity="center_vertical"
-                    android:text="Your Date"
                     android:textColor="@color/color_gray_400"
                     android:textSize="12sp" />
             </LinearLayout>