fix radiobuttons

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-06-23 15:11:48 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent 2da4c37a52
commit a4c48b11d6
2 changed files with 10 additions and 7 deletions

View File

@ -94,13 +94,10 @@ class PollVoteFragment(
}
binding.pollVoteRadioGroup.setOnCheckedChangeListener { group, checkedId ->
// todo set selected in viewmodel.
Log.d("bb", "click")
viewModel.selectOption(checkedId, true)
}
// todo observe viewmodel checked, set view checked with it
binding.pollVoteSubmitButton.setOnClickListener {
// viewModel.vote(roomToken, pollId, binding.pollVoteRadioGroup.checkedRadioButtonId)
viewModel.vote(roomToken, pollId)
}
}
@ -116,6 +113,8 @@ class PollVoteFragment(
}?.forEachIndexed { index, radioButton ->
radioButton.id = index
binding.pollVoteRadioGroup.addView(radioButton)
radioButton.isChecked = viewModel.selectedOptions.contains(index) == true
}
} else {
binding.voteOptionsCheckboxesWrapper.removeAllViews()
@ -128,7 +127,7 @@ class PollVoteFragment(
checkBox.isChecked = viewModel.selectedOptions.contains(index) == true
checkBox.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
viewModel.selectOption(index)
viewModel.selectOption(index, false)
} else {
viewModel.deSelectOption(index)
}

View File

@ -54,8 +54,12 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
_selectedOptions = selectedOptions
}
fun selectOption(option: Int) {
_selectedOptions = _selectedOptions.plus(option)
fun selectOption(option: Int, isRadioBox: Boolean) {
if (isRadioBox) {
_selectedOptions = listOf(option)
} else {
_selectedOptions = _selectedOptions.plus(option)
}
}
fun deSelectOption(option: Int) {