Browse Source

fixing upload problem (news)

dola 11 months ago
parent
commit
43ba2b457b

+ 11 - 11
app/src/main/java/com/sambath/kunkhmer/screen/lives/LivesAdminFragment.kt

@@ -29,6 +29,7 @@ class LivesAdminFragment : Fragment() {
     private val binding get() = _root!!
     private lateinit var livesViewModel: LivesViewModel
     private lateinit var matchViewModel: FighterViewModel
+    private lateinit var selectedId: String
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -52,24 +53,21 @@ class LivesAdminFragment : Fragment() {
         setDefault()
 
         binding.submitButton.setOnClickListener {
-            val selectedId = binding.radio_group_status.checkedRadioButtonId
+            val selectedStatusId = binding.radio_group_status.checkedRadioButtonId
             var status = false
-            if (selectedId != -1) { // -1 indicates no radio button is checked
-                val selectedRadioButton: RadioButton = binding.findViewById(selectedId)
+            if (selectedStatusId != -1) {
+                val selectedRadioButton: RadioButton = binding.findViewById(selectedStatusId)
                 val selectedValue: String = selectedRadioButton.text.toString()
                 if (selectedValue == "True") {
                     status = true
                 }
             }
 
-//            val createLivesRequest = CreateLivesRequest(
-//                binding.et_match_fighter_id.text.toString(), status, binding.et_url.text.toString()
-//            )
-
             val createLivesRequest = CreateLivesRequest(
-                "", status, binding.et_url.text.toString()
+                selectedId, status, binding.et_url.text.toString()
             )
 
+            //Toast.makeText(requireContext(), "$selectedId-$status",Toast.LENGTH_LONG).show()
             livesViewModel.createLives(createLivesRequest.matchFighterId, createLivesRequest.status, createLivesRequest.url)
         }
 
@@ -86,16 +84,18 @@ class LivesAdminFragment : Fragment() {
             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 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) {
-                    // Handle the selected item here
+                    //  Get the selected Matches object
                     val selectedMatch = matches[position]
-                    // Access the fighters list if needed: selectedMatch.fighters
+
+                    // Access the corresponding ID (it.matchInfo.id)
+                    selectedId = selectedMatch.matchInfo.id
                 }
 
                 override fun onNothingSelected(parentView: AdapterView<*>) {