mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 14:05:40 +03:00
disable vote button when selection is not changed compared to own votes
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
167aa43ca0
commit
6447b82969
2 changed files with 21 additions and 9 deletions
|
@ -78,9 +78,11 @@ class PollVoteFragment(
|
|||
if (state is PollMainViewModel.PollVoteState) {
|
||||
initPollOptions(state.poll)
|
||||
initCloseButton(state.showCloseButton)
|
||||
updateSubmitButton()
|
||||
} else if (state is PollMainViewModel.PollVoteHiddenState) {
|
||||
initPollOptions(state.poll)
|
||||
initCloseButton(state.showCloseButton)
|
||||
updateSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +100,7 @@ class PollVoteFragment(
|
|||
|
||||
binding.pollVoteRadioGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
viewModel.selectOption(checkedId, true)
|
||||
updateSubmitButton()
|
||||
}
|
||||
|
||||
binding.pollVoteSubmitButton.setOnClickListener {
|
||||
|
@ -106,8 +109,7 @@ class PollVoteFragment(
|
|||
}
|
||||
|
||||
private fun initPollOptions(poll: Poll) {
|
||||
poll.votedSelf?.let { viewModel.initSelectedOptions(it as ArrayList<Int>) }
|
||||
|
||||
poll.votedSelf?.let { viewModel.initVotedOptions(it as ArrayList<Int>) }
|
||||
|
||||
if (poll.maxVotes == 1) {
|
||||
binding.pollVoteRadioGroup.removeAllViews()
|
||||
|
@ -115,9 +117,6 @@ class PollVoteFragment(
|
|||
RadioButton(context).apply { text = option }
|
||||
}?.forEachIndexed { index, radioButton ->
|
||||
radioButton.id = index
|
||||
// if (poll.votedSelf?.contains(index) == true) {
|
||||
// radioButton.setTypeface(null, Typeface.BOLD)
|
||||
// }
|
||||
makeOptionBoldIfSelfVoted(radioButton, poll, index)
|
||||
binding.pollVoteRadioGroup.addView(radioButton)
|
||||
|
||||
|
@ -129,9 +128,6 @@ class PollVoteFragment(
|
|||
CheckBox(context).apply { text = option }
|
||||
}?.forEachIndexed { index, checkBox ->
|
||||
checkBox.id = index
|
||||
// if (poll.votedSelf?.contains(index) == true) {
|
||||
// checkBox.setTypeface(null, Typeface.BOLD)
|
||||
// }
|
||||
makeOptionBoldIfSelfVoted(checkBox, poll, index)
|
||||
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
|
||||
|
||||
|
@ -147,11 +143,22 @@ class PollVoteFragment(
|
|||
} else {
|
||||
viewModel.deSelectOption(index)
|
||||
}
|
||||
updateSubmitButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSubmitButton() {
|
||||
binding.pollVoteSubmitButton.isEnabled =
|
||||
areSelectedOptionsDifferentToVotedOptions() && viewModel.selectedOptions.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun areSelectedOptionsDifferentToVotedOptions(): Boolean {
|
||||
return !(viewModel.votedOptions.containsAll(viewModel.selectedOptions) &&
|
||||
viewModel.selectedOptions.containsAll(viewModel.votedOptions))
|
||||
}
|
||||
|
||||
private fun makeOptionBoldIfSelfVoted(button: CompoundButton, poll: Poll, index: Int) {
|
||||
if (poll.votedSelf?.contains(index) == true) {
|
||||
button.setTypeface(null, Typeface.BOLD)
|
||||
|
|
|
@ -46,11 +46,16 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
|
|||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
private var _votedOptions: List<Int> = emptyList()
|
||||
val votedOptions: List<Int>
|
||||
get() = _votedOptions
|
||||
|
||||
private var _selectedOptions: List<Int> = emptyList()
|
||||
val selectedOptions: List<Int>
|
||||
get() = _selectedOptions
|
||||
|
||||
fun initSelectedOptions(selectedOptions: List<Int>) {
|
||||
fun initVotedOptions(selectedOptions: List<Int>) {
|
||||
_votedOptions = selectedOptions
|
||||
_selectedOptions = selectedOptions
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue