|
@@ -1,25 +1,34 @@
|
|
package com.sambath.kunkhmer.screen.lives
|
|
package com.sambath.kunkhmer.screen.lives
|
|
|
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
-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.RadioButton
|
|
import android.widget.RadioButton
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
|
|
+import androidx.fragment.app.Fragment
|
|
|
|
+import com.google.gson.Gson
|
|
|
|
+import com.google.gson.reflect.TypeToken
|
|
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.CreateLivesRequest
|
|
import com.sambath.kunkhmer.remote.CreateLivesRequest
|
|
-import com.sambath.kunkhmer.remote.CreateProductRequest
|
|
|
|
-import kotlinx.android.synthetic.main.fragment_lives_admin.view.et_match_fighter_id
|
|
|
|
|
|
+import com.sambath.kunkhmer.remote.Matches
|
|
|
|
+import com.sambath.kunkhmer.remote.MatchesResponse
|
|
|
|
+import com.sambath.kunkhmer.screen.fighter.FighterViewModel
|
|
|
|
+import com.sambath.kunkhmer.screen.fighter.FighterViewState
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.et_url
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.et_url
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.radio_group_status
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.radio_group_status
|
|
|
|
+import kotlinx.android.synthetic.main.fragment_lives_admin.view.spinner_match
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.submitButton
|
|
import kotlinx.android.synthetic.main.fragment_lives_admin.view.submitButton
|
|
|
|
|
|
|
|
+
|
|
class LivesAdminFragment : Fragment() {
|
|
class LivesAdminFragment : Fragment() {
|
|
private var _root: View? = null
|
|
private var _root: View? = null
|
|
private val binding get() = _root!!
|
|
private val binding get() = _root!!
|
|
private lateinit var livesViewModel: LivesViewModel
|
|
private lateinit var livesViewModel: LivesViewModel
|
|
|
|
+ private lateinit var matchViewModel: FighterViewModel
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -29,10 +38,17 @@ class LivesAdminFragment : Fragment() {
|
|
// Inflate the layout for this fragment
|
|
// Inflate the layout for this fragment
|
|
_root = inflater.inflate(R.layout.fragment_lives_admin, container, false)
|
|
_root = inflater.inflate(R.layout.fragment_lives_admin, container, false)
|
|
livesViewModel = LivesViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
livesViewModel = LivesViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+ matchViewModel = FighterViewModel(App.injectApiService(), App.injectPrefHelper())
|
|
|
|
+
|
|
livesViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
livesViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
render(it)
|
|
render(it)
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ matchViewModel.state.observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
|
|
|
+ renderMatch(it)
|
|
|
|
+ })
|
|
|
|
+ matchViewModel.getMatches()
|
|
|
|
+
|
|
setDefault()
|
|
setDefault()
|
|
|
|
|
|
binding.submitButton.setOnClickListener {
|
|
binding.submitButton.setOnClickListener {
|
|
@@ -46,8 +62,12 @@ class LivesAdminFragment : Fragment() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// val createLivesRequest = CreateLivesRequest(
|
|
|
|
+// binding.et_match_fighter_id.text.toString(), status, binding.et_url.text.toString()
|
|
|
|
+// )
|
|
|
|
+
|
|
val createLivesRequest = CreateLivesRequest(
|
|
val createLivesRequest = CreateLivesRequest(
|
|
- binding.et_match_fighter_id.text.toString(), status, binding.et_url.text.toString()
|
|
|
|
|
|
+ "", status, binding.et_url.text.toString()
|
|
)
|
|
)
|
|
|
|
|
|
livesViewModel.createLives(createLivesRequest.matchFighterId, createLivesRequest.status, createLivesRequest.url)
|
|
livesViewModel.createLives(createLivesRequest.matchFighterId, createLivesRequest.status, createLivesRequest.url)
|
|
@@ -57,16 +77,40 @@ class LivesAdminFragment : Fragment() {
|
|
}
|
|
}
|
|
|
|
|
|
private fun setDefault() {
|
|
private fun setDefault() {
|
|
- binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
|
|
|
|
|
|
+ //binding.et_match_fighter_id.setText("650ea3b6b66ab4183c1657c1")
|
|
binding.et_url.setText("https://youtu.be/xZtadif15WU")
|
|
binding.et_url.setText("https://youtu.be/xZtadif15WU")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ 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.id }
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
|
|
+ // Handle the selected item here
|
|
|
|
+ val selectedMatch = matches[position]
|
|
|
|
+ // Access the fighters list if needed: selectedMatch.fighters
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onNothingSelected(parentView: AdapterView<*>) {
|
|
|
|
+ // Do nothing here
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
private fun render(state: LivesViewModel.LivesViewState) {
|
|
private fun render(state: LivesViewModel.LivesViewState) {
|
|
if (state.isLoginSuccess) {
|
|
if (state.isLoginSuccess) {
|
|
Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
|
|
Toast.makeText(context, "Create Success...", Toast.LENGTH_LONG).show()
|
|
|
|
|
|
- binding.et_match_fighter_id.setText("")
|
|
|
|
|
|
+ //binding.et_match_fighter_id.setText("")
|
|
binding.et_url.setText("")
|
|
binding.et_url.setText("")
|
|
}
|
|
}
|
|
// Other state handling...
|
|
// Other state handling...
|