|
@@ -5,18 +5,25 @@ import androidx.fragment.app.Fragment
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
+import android.widget.AdapterView
|
|
|
|
+import android.widget.ArrayAdapter
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.app.App
|
|
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_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.et_title
|
|
import kotlinx.android.synthetic.main.fragment_event_admin.view.submitButton
|
|
import kotlinx.android.synthetic.main.fragment_event_admin.view.submitButton
|
|
|
|
+import kotlinx.android.synthetic.main.fragment_lives_admin.view.spinner_match
|
|
|
|
|
|
class EventAdminFragment : Fragment() {
|
|
class EventAdminFragment : Fragment() {
|
|
private var _root: View? = null
|
|
private var _root: View? = null
|
|
private val binding get() = _root!!
|
|
private val binding get() = _root!!
|
|
private lateinit var eventViewModel: EventViewModel
|
|
private lateinit var eventViewModel: EventViewModel
|
|
|
|
+ private lateinit var matchViewModel: FighterViewModel
|
|
|
|
+ private lateinit var selectedId: String
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -33,12 +40,18 @@ class EventAdminFragment : Fragment() {
|
|
render(it)
|
|
render(it)
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ matchViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+ matchViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
|
+ renderMatch(it)
|
|
|
|
+ })
|
|
|
|
+ matchViewModel.getMatches()
|
|
|
|
+
|
|
setDefaultData()
|
|
setDefaultData()
|
|
binding.submitButton.setOnClickListener{
|
|
binding.submitButton.setOnClickListener{
|
|
eventViewModel.createEvent(
|
|
eventViewModel.createEvent(
|
|
binding.et_title.text.toString(),
|
|
binding.et_title.text.toString(),
|
|
binding.et_desc.text.toString(),
|
|
binding.et_desc.text.toString(),
|
|
- binding.et_match_fighter_id.text.toString()
|
|
|
|
|
|
+ selectedId
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -46,8 +59,34 @@ class EventAdminFragment : Fragment() {
|
|
return binding
|
|
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() {
|
|
private fun setDefaultData() {
|
|
- binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
|
|
|
|
binding.et_title.setText("Prum Samnang VS Thoeun Theara")
|
|
binding.et_title.setText("Prum Samnang VS Thoeun Theara")
|
|
binding.et_desc.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_title.setText("")
|
|
binding.et_desc.setText("")
|
|
binding.et_desc.setText("")
|
|
- binding.et_match_fighter_id.setText("")
|
|
|
|
}
|
|
}
|
|
// Other state handling...
|
|
// Other state handling...
|
|
}
|
|
}
|