mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
fix radiobuttons
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
2da4c37a52
commit
a4c48b11d6
@ -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)
|
||||
}
|
||||
|
@ -54,9 +54,13 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
|
||||
_selectedOptions = selectedOptions
|
||||
}
|
||||
|
||||
fun selectOption(option: Int) {
|
||||
fun selectOption(option: Int, isRadioBox: Boolean) {
|
||||
if (isRadioBox) {
|
||||
_selectedOptions = listOf(option)
|
||||
} else {
|
||||
_selectedOptions = _selectedOptions.plus(option)
|
||||
}
|
||||
}
|
||||
|
||||
fun deSelectOption(option: Int) {
|
||||
_selectedOptions = _selectedOptions.minus(option)
|
||||
|
Loading…
Reference in New Issue
Block a user