|
@@ -1,24 +1,37 @@
|
|
|
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.Toast
|
|
|
+import androidx.annotation.RequiresApi
|
|
|
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.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 val calendar = Calendar.getInstance()
|
|
|
+ private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000")
|
|
|
+
|
|
|
private final val fighter1 = "650d97d08cc32f66d67c0b60"
|
|
|
private final val fighter2 = "650d98498cc32f66d67c0b65"
|
|
|
private final val desc = "Keo Rumchong VS Thiago Teixeira"
|
|
@@ -37,10 +50,54 @@ class FighterAdminFragment : Fragment() {
|
|
|
render(it)
|
|
|
})
|
|
|
|
|
|
+ binding.et_date.setOnClickListener{
|
|
|
+ showDatePickerDialog()
|
|
|
+ }
|
|
|
+ setDefaultData()
|
|
|
+
|
|
|
+ binding.submitButton.setOnClickListener{
|
|
|
+ fighterViewModel.createMatch(
|
|
|
+ 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())
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
// Inflate the layout for this fragment
|
|
|
return binding
|
|
|
}
|
|
|
|
|
|
+ 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("650d97d08cc32f66d67c0b60")
|
|
|
+ binding.et_fighter_2.setText("650d98498cc32f66d67c0b65")
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showDatePickerDialog() {
|
|
|
+ val year = calendar.get(Calendar.YEAR)
|
|
|
+ val month = calendar.get(Calendar.MONTH)
|
|
|
+ val day = calendar.get(Calendar.DAY_OF_MONTH)
|
|
|
+
|
|
|
+ val datePickerDialog = DatePickerDialog(
|
|
|
+ requireContext(),
|
|
|
+ DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
|
|
|
+ // Update the calendar with the selected date
|
|
|
+ calendar.set(year, monthOfYear, dayOfMonth)
|
|
|
+
|
|
|
+ // Format the selected date and update the EditText text
|
|
|
+ val formattedDate = dateFormat.format(calendar.time)
|
|
|
+ binding.et_date.setText(formattedDate)
|
|
|
+ },
|
|
|
+ year,
|
|
|
+ month,
|
|
|
+ day
|
|
|
+ )
|
|
|
+
|
|
|
+ datePickerDialog.show()
|
|
|
+ }
|
|
|
+
|
|
|
private fun render(state: FighterViewState) {
|
|
|
if (state.isLoginSuccess) {
|
|
|
Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
|