Dola преди 11 месеца
родител
ревизия
931204ca7f

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

@@ -7,14 +7,18 @@ import android.widget.ImageView
 import android.widget.TextView
 import androidx.recyclerview.widget.RecyclerView
 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 HighlightNewsAdapter (var cardList: MutableList<Highlight>, private val listener: OnItemClickListener) : RecyclerView.Adapter<HighlightNewsAdapter.ViewHolder>() {
+
+    interface OnItemClickListener {
+        fun onItemClick(position: Int)
+    }
+
     class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@@ -40,10 +44,19 @@ class HighlightNewsAdapter (var cardList: MutableList<Highlight>) : RecyclerView
     override fun getItemCount() = cardList.size
 
     // Holds the views for adding it to image and text
-    class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
+    inner class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
         val imageView: ImageView = itemView.findViewById(R.id.imageView)
         val dateTextView: TextView = itemView.findViewById(R.id.dateTextView)
         val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
+
+        init {
+            itemView.setOnClickListener {
+                val position = adapterPosition
+                if (position != RecyclerView.NO_POSITION) {
+                    listener.onItemClick(position)
+                }
+            }
+        }
     }
 
     private fun parseAndFormatDate(dateString: String): String {

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

@@ -5,12 +5,10 @@ import android.view.View
 import android.view.ViewGroup
 import android.widget.ImageView
 import android.widget.TextView
-import androidx.appcompat.app.AppCompatActivity
 import androidx.recyclerview.widget.RecyclerView
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.config.Config
 import com.sambath.kunkhmer.remote.LivesInfo
-import com.sambath.kunkhmer.screen.lives.LiveDetailFragment
 import com.squareup.picasso.Picasso
 
 class LivesAdapter(var cardList: List<LivesInfo>, private val listener: OnItemClickListener) : RecyclerView.Adapter<LivesAdapter.ViewHolder>() {

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

@@ -23,9 +23,9 @@ class TopNewsDetailAdapter(var newsDetail: NewsDetail) : RecyclerView.Adapter<To
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
         val currentItem = newsDetail
-        if (!currentItem.filename.isNullOrEmpty()) {
+        if (currentItem.filename != null) {
             Picasso.get()
-                .load(Config.BASE_URL + "/v1/new/image/" + currentItem.filename)
+                .load(Config.BASE_URL + "/v1/new/image/" + currentItem.filename.filename)
                 .into(holder.imageView);
         } else {
             Picasso.get()

+ 2 - 0
app/src/main/java/com/sambath/kunkhmer/remote/LivesDataModel.kt

@@ -35,6 +35,8 @@ data class LivesInfo(
     val name: String,
     @Json(name = "filename")
     val filename: String,
+    @Json(name = "url")
+    val url: String,
 )
 
 //@JsonClass(generateAdapter = true)

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

@@ -42,6 +42,18 @@ data class NewsDetail(
     @Json(name = "__v")
     val _v: Int = 0,
 
+    @Json(name = "file_id")
+    val filename: NewsFile? = null
+)
+
+@JsonClass(generateAdapter = true)
+data class NewsFile(
+    @Json(name = "originalname")
+    val originalName: String,
+    @Json(name = "mimetype")
+    val mimetype: String,
+    @Json(name = "id")
+    val id: String,
     @Json(name = "filename")
-    val filename: String = ""
+    val filename: String,
 )

+ 8 - 0
app/src/main/java/com/sambath/kunkhmer/screen/fighter/CreateFighterFragment.kt

@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.ProgressBar
 import android.widget.Toast
 import androidx.activity.result.ActivityResultLauncher
 import androidx.activity.result.contract.ActivityResultContracts
@@ -29,6 +30,7 @@ class CreateFighterFragment : Fragment() {
     private val binding get() = _root!!
     private var imageUri: Uri? = null
     private lateinit var fighterViewModel: FighterViewModel
+    private lateinit var loadingProgressBar: ProgressBar
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -38,6 +40,7 @@ class CreateFighterFragment : Fragment() {
         // Inflate the layout for this fragment
         _root = inflater.inflate(R.layout.fragment_create_fighter, container, false)
 
+        loadingProgressBar = binding.findViewById(R.id.loadingProgressBar)
         fighterViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
         fighterViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
             render(it)
@@ -48,6 +51,9 @@ class CreateFighterFragment : Fragment() {
         }
 
         binding.submitButton.setOnClickListener {
+            // Show loading view
+            loadingProgressBar.visibility = View.VISIBLE
+
             val imagePath = imageUri?.let { it1 -> getImagePathFromUri(it1) }
             if (imagePath != null) {
                 fighterViewModel.createFighter(
@@ -77,6 +83,8 @@ class CreateFighterFragment : Fragment() {
     private fun render(state: FighterViewState) {
         if (state.isLoginSuccess) {
             Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
+            // Hide loading view
+            loadingProgressBar.visibility = View.GONE
 
             binding.et_name.setText("")
             binding.et_desc.setText("")

+ 4 - 0
app/src/main/java/com/sambath/kunkhmer/screen/fighter/FighterAdminFragment.kt

@@ -12,6 +12,7 @@ import android.widget.Toast
 import androidx.navigation.findNavController
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.app.App
+import kotlinx.android.synthetic.main.fragment_fighter_admin.loadingProgressBar
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.et_date
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.et_desc
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.et_title
@@ -58,6 +59,8 @@ class FighterAdminFragment : Fragment() {
         setDefaultData()
 
         binding.submitButton.setOnClickListener {
+            loadingProgressBar.visibility = View.VISIBLE
+
             fighterViewModel.createMatch(
                 binding.et_date.text.toString(),
                 binding.et_title.text.toString(),
@@ -105,6 +108,7 @@ class FighterAdminFragment : Fragment() {
     private fun render(state: FighterViewState) {
         if (state.isCreatedMatch) {
             Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
+            loadingProgressBar.visibility = View.GONE
 
             binding.et_date.setText("")
             binding.et_title.setText("")

+ 2 - 1
app/src/main/java/com/sambath/kunkhmer/screen/lives/LiveDetailFragment.kt

@@ -24,7 +24,8 @@ class LiveDetailFragment : Fragment() {
         val imageUrl = arguments?.getString("image_url")
         val title = arguments?.getString("title")
         val description = arguments?.getString("description")
-        val link = "https://youtu.be/SyheySKTg-U?si=RCK3NV6AgSKEV6cM"
+        val link = arguments?.getString("url") ?: "https://youtu.be/SyheySKTg-U?si=RCK3NV6AgSKEV6cM"
+        //val link = "https://youtu.be/SyheySKTg-U?si=RCK3NV6AgSKEV6cM"
 
         val webView = binding.findViewById<WebView>(R.id.webView)
 

+ 1 - 0
app/src/main/java/com/sambath/kunkhmer/screen/lives/LivesFragment.kt

@@ -99,6 +99,7 @@ class LivesFragment : Fragment(), LivesAdapter.OnItemClickListener  {
         bundle.putString("image_url", clickedItem.filename)
         bundle.putString("title", clickedItem.name)
         bundle.putString("description", clickedItem.desc)
+        bundle.putString("url", clickedItem.url)
         liveDetailFragment.arguments = bundle
 
         // Replace the current fragment with the LiveDetailFragment

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

@@ -11,20 +11,23 @@ import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.adapter.HighlightNewsAdapter
 import com.sambath.kunkhmer.adapter.TopNewsAdapter
 import com.sambath.kunkhmer.app.App
+import com.sambath.kunkhmer.remote.Highlight
 import com.sambath.kunkhmer.remote.HighlightData
 import com.sambath.kunkhmer.remote.News
 import com.sambath.kunkhmer.remote.NewsData
+import com.sambath.kunkhmer.screen.lives.LiveDetailFragment
 import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNews
 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(), TopNewsAdapter.OnItemClickListener {
+class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener, HighlightNewsAdapter.OnItemClickListener {
     private var _root: View? = null
     private val binding get() = _root!!
     private lateinit var newsViewModel: NewsViewModel
     private lateinit var topNewsAdapter: TopNewsAdapter
     private lateinit var highlightNewsAdapter: HighlightNewsAdapter
+    private var cardList: List<Highlight>? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -37,7 +40,7 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
         _root = inflater.inflate(R.layout.fragment_news, container, false)
 
         topNewsAdapter = TopNewsAdapter(mutableListOf(), this)
-        highlightNewsAdapter = HighlightNewsAdapter(mutableListOf())
+        highlightNewsAdapter = HighlightNewsAdapter(mutableListOf(), this)
 
         // Set adapters
         binding.recyclerViewNews.apply {
@@ -63,6 +66,7 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
 
             if(state.highlightData != null) {
                 updateHighlight(state.highlightData)
+                cardList = state.highlightData.obj
             }
         }
         // Other state handling...
@@ -162,4 +166,23 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
             .addToBackStack("NewsFragment") // Add to back stack to handle the back navigation
             .commit()
     }
+
+    override fun onItemClick(position: Int) {
+        val clickedItem = cardList!![position]
+        val liveDetailFragment = LiveDetailFragment()
+
+        // You can pass data to the LiveDetailFragment using arguments if needed
+        val bundle = Bundle()
+        bundle.putString("image_url", "")
+        bundle.putString("title", clickedItem.title)
+        bundle.putString("description", clickedItem.title)
+        bundle.putString("url", clickedItem.url)
+        liveDetailFragment.arguments = bundle
+
+        // Replace the current fragment with the LiveDetailFragment
+        parentFragmentManager.beginTransaction()
+            .replace(R.id.nav_host_fragment_activity_main, liveDetailFragment)
+            .addToBackStack(null) // Add to back stack to handle the back navigation
+            .commit()
+    }
 }

+ 7 - 0
app/src/main/res/layout/fragment_create_fighter.xml

@@ -133,4 +133,11 @@
         android:paddingEnd="16dp"
         android:text="Submit" />
 
+    <ProgressBar
+        android:id="@+id/loadingProgressBar"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:visibility="gone"/>
+
 </androidx.appcompat.widget.LinearLayoutCompat>

+ 1 - 0
app/src/main/res/layout/fragment_event_admin.xml

@@ -16,6 +16,7 @@
         <androidx.appcompat.widget.AppCompatSpinner
             android:id="@+id/spinner_match"
             android:layout_width="match_parent"
+            android:paddingLeft="7dp"
             android:layout_height="48dp"
             android:background="@color/color_white" />
 

+ 11 - 2
app/src/main/res/layout/fragment_fighter_admin.xml

@@ -55,7 +55,8 @@
             android:id="@+id/spinner_fighter_1"
             android:layout_width="match_parent"
             android:layout_height="48dp"
-            android:background="@color/color_white" />
+            android:background="@color/color_white"
+            android:paddingLeft="7dp" />
 
         <ImageView
             android:layout_width="25dp"
@@ -79,7 +80,8 @@
             android:id="@+id/spinner_fighter_2"
             android:layout_width="match_parent"
             android:layout_height="48dp"
-            android:background="@color/color_white" />
+            android:background="@color/color_white"
+            android:paddingLeft="7dp" />
 
         <ImageView
             android:layout_width="25dp"
@@ -122,6 +124,13 @@
         android:paddingEnd="16dp"
         android:text="Submit" />
 
+    <ProgressBar
+        android:id="@+id/loadingProgressBar"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:visibility="gone"/>
+
     <TextView
         android:id="@+id/fighter_button"
         android:layout_width="wrap_content"