dola 1 rok pred
rodič
commit
fffb28c58b

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

@@ -10,6 +10,9 @@ import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.config.Config
 import com.sambath.kunkhmer.remote.Highlight
 import com.squareup.picasso.Picasso
+import java.text.SimpleDateFormat
+import java.util.Locale
+import java.util.TimeZone
 
 class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView.Adapter<HighlightNewsAdapter.ViewHolder>() {
     class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
@@ -30,7 +33,7 @@ class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView
             .placeholder(R.drawable.ic_logo_header)
             .into(holder.imageView);
 
-        holder.dateTextView.text = currentItem.date
+        holder.dateTextView.text = parseAndFormatDate(currentItem.date)
         holder.titleTextView.text = currentItem.title
     }
 
@@ -42,4 +45,20 @@ class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView
         val dateTextView: TextView = itemView.findViewById(R.id.dateTextView)
         val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
     }
+
+    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)
+    }
 }

+ 8 - 1
app/src/main/java/com/sambath/kunkhmer/adapter/TopNewsAdapter.kt

@@ -15,7 +15,10 @@ import java.text.SimpleDateFormat
 import java.util.Locale
 import java.util.TimeZone
 
-class TopNewsAdapter(var cardList: MutableList<News>) : RecyclerView.Adapter<TopNewsAdapter.ViewHolder>() {
+class TopNewsAdapter(var cardList: MutableList<News>, private val itemClickListener: OnItemClickListener) : RecyclerView.Adapter<TopNewsAdapter.ViewHolder>() {
+    interface OnItemClickListener {
+        fun onItemClick(newsItem: News)
+    }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
         val itemView = LayoutInflater.from(parent.context).inflate(R.layout.layout_top_news_item_card, parent, false)
@@ -36,6 +39,10 @@ class TopNewsAdapter(var cardList: MutableList<News>) : RecyclerView.Adapter<Top
         holder.dateTextView.text = parseAndFormatDate(currentItem.createdAt)
         holder.titleTextView.text = currentItem.title
         holder.subTextView.text = currentItem.desc
+
+        holder.itemView.setOnClickListener{
+            itemClickListener.onItemClick(cardList[position])
+        }
     }
 
     override fun getItemCount() = cardList.size

+ 14 - 5
app/src/main/java/com/sambath/kunkhmer/screen/news/NewsFragment.kt

@@ -5,14 +5,11 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import androidx.lifecycle.Observer
 import androidx.recyclerview.widget.LinearLayoutManager
 import com.google.android.material.tabs.TabLayout
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.adapter.HighlightNewsAdapter
 import com.sambath.kunkhmer.adapter.TopNewsAdapter
-import com.sambath.kunkhmer.adapter.TopNewsCardItem
-import com.sambath.kunkhmer.adapter.TopNewsHeaderAdapter
 import com.sambath.kunkhmer.app.App
 import com.sambath.kunkhmer.remote.HighlightData
 import com.sambath.kunkhmer.remote.News
@@ -22,7 +19,7 @@ import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNewsHeader
 import kotlinx.android.synthetic.main.fragment_news.view.selectedTabTextView
 import kotlinx.android.synthetic.main.fragment_news.view.tabLayout
 
-class NewsFragment : Fragment() {
+class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
     private var _root: View? = null
     private val binding get() = _root!!
     private lateinit var newsViewModel: NewsViewModel
@@ -39,7 +36,7 @@ class NewsFragment : Fragment() {
         // Inflate the layout for this fragment
         _root = inflater.inflate(R.layout.fragment_news, container, false)
 
-        topNewsAdapter = TopNewsAdapter(mutableListOf())
+        topNewsAdapter = TopNewsAdapter(mutableListOf(), this)
         highlightNewsAdapter = HighlightNewsAdapter(mutableListOf())
 
         // Set adapters
@@ -153,4 +150,16 @@ class NewsFragment : Fragment() {
     fun selectTab(tabIndex: Int) {
         binding.tabLayout.getTabAt(tabIndex)?.select()
     }
+
+    override fun onItemClick(newsItem: News) {
+        val topNewsDetailFragment = TopNewsDetailFragment()
+        val bundle = Bundle()
+        bundle.putString("news_id", newsItem.id)
+        topNewsDetailFragment.arguments = bundle
+
+        parentFragmentManager.beginTransaction()
+            .replace(R.id.nav_host_fragment_activity_main, topNewsDetailFragment)
+            .addToBackStack(null) // Add to back stack to handle the back navigation
+            .commit()
+    }
 }

+ 26 - 0
app/src/main/java/com/sambath/kunkhmer/screen/news/TopNewsDetailFragment.kt

@@ -0,0 +1,26 @@
+package com.sambath.kunkhmer.screen.news
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.sambath.kunkhmer.R
+import com.sambath.kunkhmer.remote.News
+
+class TopNewsDetailFragment : Fragment() {
+    private var _root: View? = null
+    private val binding get() = _root!!
+    private var newsItem: News? = null
+
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+    }
+
+    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+        _root = inflater.inflate(R.layout.fragment_top_news_detail, container, false)
+        val newsId = arguments?.getString("news_id")
+        return _root
+    }
+}

+ 14 - 0
app/src/main/res/layout/fragment_top_news_detail.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".screen.news.TopNewsDetailFragment">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>

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

@@ -41,8 +41,8 @@
                 android:orientation="horizontal">
 
                 <ImageView
-                    android:layout_width="25dp"
-                    android:layout_height="25dp"
+                    android:layout_width="20dp"
+                    android:layout_height="20dp"
                     android:src="@drawable/ic_alarm_clock_64" />
 
                 <TextView

+ 12 - 47
app/src/main/res/navigation/nav_graph.xml

@@ -3,58 +3,23 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/nav_graph"
-    app:startDestination="@id/MainFragment">
+    app:startDestination="@id/newsFragment">
 
     <fragment
-        android:id="@+id/MainFragment"
-        android:name="com.sambath.kunkhmer.screen.main.MainFragment"
-        android:label="@string/main_fragment_label"
-        tools:layout="@layout/fragment_main">
+        android:id="@+id/newsFragment"
+        android:name="com.sambath.kunkhmer.screen.news.NewsFragment"
+        android:label="NewsFragment" >
         <action
-            android:id="@+id/action_MainFragment_to_SettingFragment"
-            app:destination="@id/SettingFragment"
-            app:enterAnim="@anim/slide_in"
-            app:exitAnim="@anim/slide_out"
-            app:popEnterAnim="@anim/slide_in_exit"
-            app:popExitAnim="@anim/slide_out_exit"/>
-
-        <action
-            android:id="@+id/action_MainFragment_to_ReportFragment"
-            app:destination="@id/ReportFragment"
-            app:enterAnim="@anim/slide_in"
-            app:exitAnim="@anim/slide_out"
-            app:popEnterAnim="@anim/slide_in_exit"
-            app:popExitAnim="@anim/slide_out_exit"/>
-        <action
-            android:id="@+id/action_MainFragment_to_cfResultFragment"
-            app:destination="@id/cfResultFragment" />
-        <action
-            android:id="@+id/action_MainFragment_to_cfBetFragment"
-            app:destination="@id/cfBetFragment" />
-
+            android:id="@+id/action_newsFragment_to_topNewsDetailFragment"
+            app:destination="@id/topNewsDetailFragment" />
     </fragment>
-    <fragment
-        android:id="@+id/ReportFragment"
-        android:name="com.sambath.kunkhmer.screen.report.StatementFragment"
-        android:label="@string/report_fragment_label"
-        tools:layout="@layout/fragment_report">
 
-    </fragment>
     <fragment
-        android:id="@+id/SettingFragment"
-        android:name="com.sambath.kunkhmer.screen.setting.SettingFragment"
-        android:label="@string/setting_fragment_label"
-        tools:layout="@layout/fragment_setting">
-
+        android:id="@+id/topNewsDetailFragment"
+        android:name="com.sambath.kunkhmer.screen.news.TopNewsDetailFragment"
+        android:label="TopNewsDetailFragment" >
+        <argument
+            android:name="newsItem"
+            app:argType="com.sambath.kunkhmer.remote.News" />
     </fragment>
-    <fragment
-        android:id="@+id/cfBetFragment"
-        android:name="com.sambath.kunkhmer.screen.main.cflive.Betting.CfBetFragment"
-        android:label="fragment_cf_betting"
-        tools:layout="@layout/fragment_cf_betting" />
-    <fragment
-        android:id="@+id/cfResultFragment"
-        android:name="com.sambath.kunkhmer.screen.main.cflive.result.CfResultFragment"
-        android:label="fragment_cf_result"
-        tools:layout="@layout/fragment_cf_result" />
 </navigation>