Dola 11 сар өмнө
parent
commit
f0d7a7895c

+ 17 - 17
app/src/main/java/com/sambath/kunkhmer/remote/FighterDataModel.kt

@@ -22,7 +22,7 @@ data class FightersData(
 @JsonClass(generateAdapter = true)
 data class FightersInfo(
     @Json(name = "file_id")
-    val fighterFile: FighterFile,
+    val fighterFile: FighterFile?,
 
     @Json(name = "_id")
     val id: String,
@@ -50,28 +50,28 @@ data class FighterFile(
     val fieldName: String,
     @Json(name = "originalname")
     val originalName: String,
-    @Json(name = "encoding")
-    val encoding: String,
+//    @Json(name = "encoding")
+//    val encoding: String,
     @Json(name = "mimetype")
     val mimetype: String,
     @Json(name = "id")
     val id: String,
     @Json(name = "filename")
     val filename: String,
-    @Json(name = "metadata")
-    val metadata: String,
-    @Json(name = "bucketName")
-    val bucketName: String,
-    @Json(name = "chunkSize")
-    val chunkSize: Int,
-    @Json(name = "size")
-    val size: Int,
-    @Json(name = "md5")
-    val md5: String,
-    @Json(name = "uploadDate")
-    val uploadDate: String,
-    @Json(name = "contentType")
-    val contentType: String,
+//    @Json(name = "metadata")
+//    val metadata: String = "",
+//    @Json(name = "bucketName")
+//    val bucketName: String,
+//    @Json(name = "chunkSize")
+//    val chunkSize: Int,
+//    @Json(name = "size")
+//    val size: Int,
+//    @Json(name = "md5")
+//    val md5: String,
+//    @Json(name = "uploadDate")
+//    val uploadDate: String,
+//    @Json(name = "contentType")
+//    val contentType: String,
 )
 
 

+ 52 - 14
app/src/main/java/com/sambath/kunkhmer/screen/fighter/FighterAdminFragment.kt

@@ -1,35 +1,33 @@
 package com.sambath.kunkhmer.screen.fighter
 
 import android.app.DatePickerDialog
-import android.os.Build
 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.Toast
-import androidx.annotation.RequiresApi
 import androidx.navigation.findNavController
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.app.App
-import kotlinx.android.synthetic.main.fragment_fighter_admin.et_date
 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_fighter_1
-import kotlinx.android.synthetic.main.fragment_fighter_admin.view.et_fighter_2
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.et_title
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.fighter_button
+import kotlinx.android.synthetic.main.fragment_fighter_admin.view.spinner_fighter_1
+import kotlinx.android.synthetic.main.fragment_fighter_admin.view.spinner_fighter_2
 import kotlinx.android.synthetic.main.fragment_fighter_admin.view.submitButton
 import java.text.SimpleDateFormat
-import java.time.LocalDateTime
-import java.time.ZoneOffset
-import java.time.format.DateTimeFormatter
 import java.util.Calendar
 
 class FighterAdminFragment : Fragment() {
     private var _root: View? = null
     private val binding get() = _root!!
     private lateinit var fighterViewModel: FighterViewModel
+    private lateinit var selectedFighter1Id: String
+    private lateinit var selectedFighter2Id: String
 
     private val calendar = Calendar.getInstance()
     private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000")
@@ -51,6 +49,8 @@ class FighterAdminFragment : Fragment() {
         fighterViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
             render(it)
         })
+        fighterViewModel.getFighters()
+
 
         binding.et_date.setOnClickListener {
             showDatePickerDialog()
@@ -62,7 +62,7 @@ class FighterAdminFragment : Fragment() {
                 binding.et_date.text.toString(),
                 binding.et_title.text.toString(),
                 binding.et_desc.text.toString(),
-                listOf(binding.et_fighter_1.text.toString(), binding.et_fighter_2.text.toString())
+                listOf(selectedFighter1Id, selectedFighter2Id)
             )
         }
 
@@ -77,8 +77,6 @@ class FighterAdminFragment : Fragment() {
     private fun setDefaultData() {
         binding.et_title.setText("Keo Rumchong VS Thiago Teixeira")
         binding.et_desc.setText("Keo Rumchong VS Thiago Teixeira")
-        binding.et_fighter_1.setText("65542230c82a6853109bceed")
-        binding.et_fighter_2.setText("65542284c82a6829d69bcef2")
     }
 
     private fun showDatePickerDialog() {
@@ -105,14 +103,54 @@ class FighterAdminFragment : Fragment() {
     }
 
     private fun render(state: FighterViewState) {
-        if (state.isLoginSuccess) {
+        if (state.isCreatedMatch) {
             Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
 
             binding.et_date.setText("")
             binding.et_title.setText("")
             binding.et_desc.setText("")
-            binding.et_fighter_1.setText("")
-            binding.et_fighter_2.setText("")
+        }
+
+        if (state.isGetFighters) {
+            val matchesData = state.fightersData!!
+            // Ensure matches is not null before mapping
+            val dropdownItems1 = matchesData.map { it.name  }
+
+            val adapter1 = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, dropdownItems1)
+            adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
+            binding.spinner_fighter_1.adapter = adapter1
+            binding.spinner_fighter_1.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+                override fun onItemSelected(parentView: AdapterView<*>, selectedItemView: View, position: Int, id: Long) {
+                    //  Get the selected Matches object
+                    val selectedMatch = matchesData[position]
+
+                    // Access the corresponding ID (it.matchInfo.id)
+                    selectedFighter1Id = selectedMatch.id
+                }
+
+                override fun onNothingSelected(parentView: AdapterView<*>) {
+                    // Do nothing here
+                }
+            }
+            //
+            val dropdownItems2 = matchesData.map { it.name  }
+
+            val adapter2 = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, dropdownItems2)
+            adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
+            binding.spinner_fighter_2.adapter = adapter2
+            binding.spinner_fighter_2.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+                override fun onItemSelected(parentView: AdapterView<*>, selectedItemView: View, position: Int, id: Long) {
+                    //  Get the selected Matches object
+                    val selectedMatch = matchesData[position]
+
+                    // Access the corresponding ID (it.matchInfo.id)
+                    selectedFighter2Id = selectedMatch.id
+                }
+
+                override fun onNothingSelected(parentView: AdapterView<*>) {
+                    // Do nothing here
+                }
+            }
         }
         // Other state handling...
     }

+ 5 - 3
app/src/main/java/com/sambath/kunkhmer/screen/fighter/FighterViewModel.kt

@@ -63,7 +63,7 @@ class FighterViewModel(val apiService: ApiService, val prefHelper: PrefHelper) :
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe({
                     if (it.resultCode == 1) {
-                        _state.value = prev().copy(isProgress = false, isLoginSuccess = true)
+                        _state.value = prev().copy(isProgress = false, isCreatedMatch = true)
                     } else {
                         _state.value =
                             prev().copy(isProgress = false, error = "[${it.message.description}]")
@@ -75,7 +75,7 @@ class FighterViewModel(val apiService: ApiService, val prefHelper: PrefHelper) :
         )
     }
 
-    fun getFighters(){
+    fun getFighters() {
         if (_state.value!!.isProgress) return
         _state.value = prev().copy(isProgress = true)
 
@@ -86,7 +86,7 @@ class FighterViewModel(val apiService: ApiService, val prefHelper: PrefHelper) :
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe({
                     if (it.resultCode == 1) {
-                        _state.value = prev().copy(isProgress = false, isLoginSuccess = true, fightersData = it.data!!.obj)
+                        _state.value = prev().copy(isProgress = false, isGetFighters = true, fightersData = it.data!!.obj)
                     } else {
                         _state.value =
                             prev().copy(isProgress = false, error = "[${it.message.description}]")
@@ -155,6 +155,8 @@ data class FighterViewState(
     val initial: Boolean = false,
     val isProgress: Boolean = false,
     val isLoginSuccess: Boolean = false,
+    val isCreatedMatch: Boolean = false,
+    val isGetFighters: Boolean = false,
     val error: String? = null,
     val matchesData: MatchesData? = null,
     val fightersData: List<FightersInfo>? = null

+ 4 - 0
app/src/main/res/drawable/custom_dropdown_icon.xml

@@ -0,0 +1,4 @@
+<!-- res/drawable/custom_dropdown_icon.xml -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:drawable="@drawable/ic_dropdown" />
+</layer-list>

BIN
app/src/main/res/drawable/ic_dropdown.png


+ 27 - 0
app/src/main/res/layout/custom_spinner_layout.xml

@@ -0,0 +1,27 @@
+<!-- res/layout/custom_spinner_layout.xml -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="48dp"
+    android:background="@color/color_white"
+    android:gravity="center_vertical"
+    android:orientation="horizontal">
+
+    <TextView
+        android:id="@+id/textViewSelectedItem"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:ellipsize="end"
+        android:paddingStart="8dp"
+        android:paddingEnd="8dp"
+        android:singleLine="true"
+        android:textColor="@color/color_black"
+        android:textSize="16sp" />
+
+    <ImageView
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        android:contentDescription="@null"
+        android:paddingEnd="8dp"
+        android:src="@drawable/ic_dropdown" />
+</LinearLayout>

+ 18 - 4
app/src/main/res/layout/fragment_event_admin.xml

@@ -7,11 +7,25 @@
     android:orientation="vertical"
     android:padding="10dp">
 
-    <androidx.appcompat.widget.AppCompatSpinner
-        android:id="@+id/spinner_match"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        android:background="@color/color_white" />
+        android:layout_height="wrap_content"
+        android:background="@color/color_white"
+        android:orientation="horizontal">
+
+        <androidx.appcompat.widget.AppCompatSpinner
+            android:id="@+id/spinner_match"
+            android:layout_width="match_parent"
+            android:layout_height="48dp"
+            android:background="@color/color_white" />
+
+        <ImageView
+            android:layout_width="25dp"
+            android:layout_height="25dp"
+            android:layout_gravity="center|end"
+            android:background="@drawable/ic_dropdown" />
+
+    </FrameLayout>
 
     <View
         android:layout_width="match_parent"

+ 40 - 30
app/src/main/res/layout/fragment_fighter_admin.xml

@@ -45,43 +45,53 @@
             android:padding="0dp" />
     </com.google.android.material.textfield.TextInputLayout>
 
-    <com.google.android.material.textfield.TextInputLayout
-        android:id="@+id/til_fighter_1"
-        style="@style/BoxInputLayout"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        app:endIconMode="clear_text"
-        app:hintEnabled="false">
+        android:layout_height="wrap_content"
+        android:background="@color/color_white"
+        android:orientation="horizontal">
 
-        <androidx.appcompat.widget.AppCompatEditText
-            android:id="@+id/et_fighter_1"
+        <androidx.appcompat.widget.AppCompatSpinner
+            android:id="@+id/spinner_fighter_1"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:background="@color/color_white"
-            android:hint="@string/hint_fighter_1"
-            android:inputType="text"
-            android:maxLength="50"
-            android:padding="0dp" />
-    </com.google.android.material.textfield.TextInputLayout>
+            android:layout_height="48dp"
+            android:background="@color/color_white" />
 
-    <com.google.android.material.textfield.TextInputLayout
-        android:id="@+id/til_fighter_2"
-        style="@style/BoxInputLayout"
+        <ImageView
+            android:layout_width="25dp"
+            android:layout_height="25dp"
+            android:layout_gravity="center|end"
+            android:background="@drawable/ic_dropdown" />
+
+    </FrameLayout>
+
+    <View
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        app:endIconMode="clear_text"
-        app:hintEnabled="false">
+        android:layout_height="1dp" />
 
-        <androidx.appcompat.widget.AppCompatEditText
-            android:id="@+id/et_fighter_2"
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/color_white"
+        android:orientation="horizontal">
+
+        <androidx.appcompat.widget.AppCompatSpinner
+            android:id="@+id/spinner_fighter_2"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:background="@color/color_white"
-            android:hint="@string/hint_fighter_2"
-            android:inputType="text"
-            android:maxLength="50"
-            android:padding="0dp" />
-    </com.google.android.material.textfield.TextInputLayout>
+            android:layout_height="48dp"
+            android:background="@color/color_white" />
+
+        <ImageView
+            android:layout_width="25dp"
+            android:layout_height="25dp"
+            android:layout_gravity="center|end"
+            android:background="@drawable/ic_dropdown" />
+
+    </FrameLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp" />
 
     <com.google.android.material.textfield.TextInputLayout
         android:id="@+id/til_desc"

+ 19 - 4
app/src/main/res/layout/fragment_lives_admin.xml

@@ -7,11 +7,26 @@
     android:orientation="vertical"
     android:padding="10dp">
 
-    <androidx.appcompat.widget.AppCompatSpinner
-        android:id="@+id/spinner_match"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        android:background="@color/color_white" />
+        android:layout_height="wrap_content"
+        android:background="@color/color_white"
+        android:orientation="horizontal">
+
+        <Spinner
+            android:id="@+id/spinner_match"
+            android:layout_width="match_parent"
+            android:layout_height="48dp"
+            android:background="@color/color_white"
+            android:spinnerMode="dropdown"
+            android:theme="@style/ThemeOverlay.AppCompat.Light" />
+
+        <ImageView
+            android:layout_width="25dp"
+            android:layout_height="25dp"
+            android:layout_gravity="center|end"
+            android:background="@drawable/ic_dropdown" />
+    </FrameLayout>
 
     <TextView
         android:layout_width="match_parent"