|
@@ -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...
|
|
|
}
|