Browse Source

fixing upload problem (news)

dola 11 tháng trước cách đây
mục cha
commit
970fc3bbef

+ 50 - 6
app/src/main/java/com/sambath/kunkhmer/screen/lives/LivesAdminFragment.kt

@@ -1,25 +1,34 @@
 package com.sambath.kunkhmer.screen.lives
 
 import android.os.Bundle
-import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.AdapterView
+import android.widget.ArrayAdapter
 import android.widget.RadioButton
 import android.widget.Toast
+import androidx.fragment.app.Fragment
+import com.google.gson.Gson
+import com.google.gson.reflect.TypeToken
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.app.App
 import com.sambath.kunkhmer.remote.CreateLivesRequest
-import com.sambath.kunkhmer.remote.CreateProductRequest
-import kotlinx.android.synthetic.main.fragment_lives_admin.view.et_match_fighter_id
+import com.sambath.kunkhmer.remote.Matches
+import com.sambath.kunkhmer.remote.MatchesResponse
+import com.sambath.kunkhmer.screen.fighter.FighterViewModel
+import com.sambath.kunkhmer.screen.fighter.FighterViewState
 import kotlinx.android.synthetic.main.fragment_lives_admin.view.et_url
 import kotlinx.android.synthetic.main.fragment_lives_admin.view.radio_group_status
+import kotlinx.android.synthetic.main.fragment_lives_admin.view.spinner_match
 import kotlinx.android.synthetic.main.fragment_lives_admin.view.submitButton
 
+
 class LivesAdminFragment : Fragment() {
     private var _root: View? = null
     private val binding get() = _root!!
     private lateinit var livesViewModel: LivesViewModel
+    private lateinit var matchViewModel: FighterViewModel
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -29,10 +38,17 @@ class LivesAdminFragment : Fragment() {
         // Inflate the layout for this fragment
         _root = inflater.inflate(R.layout.fragment_lives_admin, container, false)
         livesViewModel = LivesViewModel(App.injectApiService(), App.injectPrefHelper())
+        matchViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
+
         livesViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
             render(it)
         })
 
+        matchViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
+            renderMatch(it)
+        })
+        matchViewModel.getMatches()
+
         setDefault()
 
         binding.submitButton.setOnClickListener {
@@ -46,8 +62,12 @@ class LivesAdminFragment : Fragment() {
                 }
             }
 
+//            val createLivesRequest = CreateLivesRequest(
+//                binding.et_match_fighter_id.text.toString(), status, binding.et_url.text.toString()
+//            )
+
             val createLivesRequest = CreateLivesRequest(
-                binding.et_match_fighter_id.text.toString(), status, binding.et_url.text.toString()
+                "", status, binding.et_url.text.toString()
             )
 
             livesViewModel.createLives(createLivesRequest.matchFighterId, createLivesRequest.status, createLivesRequest.url)
@@ -57,16 +77,40 @@ class LivesAdminFragment : Fragment() {
     }
 
     private fun setDefault() {
-        binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
+        //binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
         binding.et_url.setText("https://youtu.be/xZtadif15WU")
     }
 
+    private fun renderMatch(state: FighterViewState) {
+        if (state.isLoginSuccess) {
+            val matchesResponse = state.matchesData
+            val matches: List<Matches> = matchesResponse!!.obj
+            // Ensure matches is not null before mapping
+            val dropdownItems = matches?.map { it.matchInfo.id }
+
+            val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, dropdownItems)
+            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
+            binding.spinner_match.adapter = adapter
+            binding.spinner_match.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+                override fun onItemSelected(parentView: AdapterView<*>, selectedItemView: View, position: Int, id: Long) {
+                    // Handle the selected item here
+                    val selectedMatch = matches[position]
+                    // Access the fighters list if needed: selectedMatch.fighters
+                }
+
+                override fun onNothingSelected(parentView: AdapterView<*>) {
+                    // Do nothing here
+                }
+            }
+
+        }
+    }
 
     private fun render(state: LivesViewModel.LivesViewState) {
         if (state.isLoginSuccess) {
             Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
 
-            binding.et_match_fighter_id.setText("")
+            //binding.et_match_fighter_id.setText("")
             binding.et_url.setText("")
         }
         // Other state handling...

+ 23 - 17
app/src/main/res/layout/fragment_lives_admin.xml

@@ -7,25 +7,31 @@
     android:orientation="vertical"
     android:padding="10dp">
 
-    <com.google.android.material.textfield.TextInputLayout
-        android:id="@+id/til_match_fighter_id"
-        style="@style/BoxInputLayout"
+    <!--    <com.google.android.material.textfield.TextInputLayout-->
+    <!--        android:id="@+id/til_match_fighter_id"-->
+    <!--        style="@style/BoxInputLayout"-->
+    <!--        android:layout_width="match_parent"-->
+    <!--        android:layout_height="48dp"-->
+    <!--        android:layout_below="@id/tv_username"-->
+    <!--        app:endIconMode="clear_text"-->
+    <!--        app:hintEnabled="false">-->
+
+    <!--        <androidx.appcompat.widget.AppCompatEditText-->
+    <!--            android:id="@+id/et_match_fighter_id"-->
+    <!--            android:layout_width="match_parent"-->
+    <!--            android:layout_height="match_parent"-->
+    <!--            android:background="@color/color_white"-->
+    <!--            android:hint="@string/hint_match_fighter_id"-->
+    <!--            android:inputType="text"-->
+    <!--            android:maxLength="50"-->
+    <!--            android:padding="0dp" />-->
+    <!--    </com.google.android.material.textfield.TextInputLayout>-->
+
+    <androidx.appcompat.widget.AppCompatSpinner
+        android:id="@+id/spinner_match"
         android:layout_width="match_parent"
         android:layout_height="48dp"
-        android:layout_below="@id/tv_username"
-        app:endIconMode="clear_text"
-        app:hintEnabled="false">
-
-        <androidx.appcompat.widget.AppCompatEditText
-            android:id="@+id/et_match_fighter_id"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:background="@color/color_white"
-            android:hint="@string/hint_match_fighter_id"
-            android:inputType="text"
-            android:maxLength="50"
-            android:padding="0dp" />
-    </com.google.android.material.textfield.TextInputLayout>
+        android:background="@color/color_white" />
 
     <TextView
         android:layout_width="match_parent"