Jelajahi Sumber

fixing upload problem (news)

dola 11 bulan lalu
induk
melakukan
2d9e8bbc97

+ 42 - 4
app/src/main/java/com/sambath/kunkhmer/screen/event/EventAdminFragment.kt

@@ -5,18 +5,25 @@ 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.Toast
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.app.App
+import com.sambath.kunkhmer.remote.Matches
+import com.sambath.kunkhmer.screen.fighter.FighterViewModel
+import com.sambath.kunkhmer.screen.fighter.FighterViewState
 import kotlinx.android.synthetic.main.fragment_event_admin.view.et_desc
-import kotlinx.android.synthetic.main.fragment_event_admin.view.et_match_fighter_id
 import kotlinx.android.synthetic.main.fragment_event_admin.view.et_title
 import kotlinx.android.synthetic.main.fragment_event_admin.view.submitButton
+import kotlinx.android.synthetic.main.fragment_lives_admin.view.spinner_match
 
 class EventAdminFragment : Fragment() {
     private var _root: View? = null
     private val binding get() = _root!!
     private lateinit var eventViewModel: EventViewModel
+    private lateinit var matchViewModel: FighterViewModel
+    private lateinit var selectedId: String
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -33,12 +40,18 @@ class EventAdminFragment : Fragment() {
             render(it)
         })
 
+        matchViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
+        matchViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
+            renderMatch(it)
+        })
+        matchViewModel.getMatches()
+
         setDefaultData()
         binding.submitButton.setOnClickListener{
             eventViewModel.createEvent(
                 binding.et_title.text.toString(),
                 binding.et_desc.text.toString(),
-                binding.et_match_fighter_id.text.toString()
+                selectedId
             )
         }
 
@@ -46,8 +59,34 @@ class EventAdminFragment : Fragment() {
         return binding
     }
 
+    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.title  }
+
+            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) {
+                    //  Get the selected Matches object
+                    val selectedMatch = matches[position]
+
+                    // Access the corresponding ID (it.matchInfo.id)
+                    selectedId = selectedMatch.matchInfo.id
+                }
+
+                override fun onNothingSelected(parentView: AdapterView<*>) {
+                    // Do nothing here
+                }
+            }
+
+        }
+    }
+
     private fun setDefaultData() {
-        binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
         binding.et_title.setText("Prum Samnang VS Thoeun Theara")
         binding.et_desc.setText("Prum Samnang VS Thoeun Theara")
     }
@@ -58,7 +97,6 @@ class EventAdminFragment : Fragment() {
 
             binding.et_title.setText("")
             binding.et_desc.setText("")
-            binding.et_match_fighter_id.setText("")
         }
         // Other state handling...
     }

+ 7 - 16
app/src/main/res/layout/fragment_event_admin.xml

@@ -7,25 +7,16 @@
     android:orientation="vertical"
     android:padding="10dp">
 
-    <com.google.android.material.textfield.TextInputLayout
-        android:id="@+id/til_match_fighter_id"
-        style="@style/BoxInputLayout"
+    <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">
+        android:background="@color/color_white" />
 
-        <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>
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="@color/color_black" />
 
     <com.google.android.material.textfield.TextInputLayout
         android:id="@+id/til_title"

+ 0 - 20
app/src/main/res/layout/fragment_lives_admin.xml

@@ -7,26 +7,6 @@
     android:orientation="vertical"
     android:padding="10dp">
 
-    <!--    <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"