mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 22:29:09 +00: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
@ -78,9 +78,11 @@ class PollVoteFragment(
|
|||||||
if (state is PollMainViewModel.PollVoteState) {
|
if (state is PollMainViewModel.PollVoteState) {
|
||||||
initPollOptions(state.poll)
|
initPollOptions(state.poll)
|
||||||
initCloseButton(state.showCloseButton)
|
initCloseButton(state.showCloseButton)
|
||||||
|
updateSubmitButton()
|
||||||
} else if (state is PollMainViewModel.PollVoteHiddenState) {
|
} else if (state is PollMainViewModel.PollVoteHiddenState) {
|
||||||
initPollOptions(state.poll)
|
initPollOptions(state.poll)
|
||||||
initCloseButton(state.showCloseButton)
|
initCloseButton(state.showCloseButton)
|
||||||
|
updateSubmitButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +100,7 @@ class PollVoteFragment(
|
|||||||
|
|
||||||
binding.pollVoteRadioGroup.setOnCheckedChangeListener { group, checkedId ->
|
binding.pollVoteRadioGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||||
viewModel.selectOption(checkedId, true)
|
viewModel.selectOption(checkedId, true)
|
||||||
|
updateSubmitButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.pollVoteSubmitButton.setOnClickListener {
|
binding.pollVoteSubmitButton.setOnClickListener {
|
||||||
@ -106,8 +109,7 @@ class PollVoteFragment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initPollOptions(poll: Poll) {
|
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) {
|
if (poll.maxVotes == 1) {
|
||||||
binding.pollVoteRadioGroup.removeAllViews()
|
binding.pollVoteRadioGroup.removeAllViews()
|
||||||
@ -115,9 +117,6 @@ class PollVoteFragment(
|
|||||||
RadioButton(context).apply { text = option }
|
RadioButton(context).apply { text = option }
|
||||||
}?.forEachIndexed { index, radioButton ->
|
}?.forEachIndexed { index, radioButton ->
|
||||||
radioButton.id = index
|
radioButton.id = index
|
||||||
// if (poll.votedSelf?.contains(index) == true) {
|
|
||||||
// radioButton.setTypeface(null, Typeface.BOLD)
|
|
||||||
// }
|
|
||||||
makeOptionBoldIfSelfVoted(radioButton, poll, index)
|
makeOptionBoldIfSelfVoted(radioButton, poll, index)
|
||||||
binding.pollVoteRadioGroup.addView(radioButton)
|
binding.pollVoteRadioGroup.addView(radioButton)
|
||||||
|
|
||||||
@ -129,9 +128,6 @@ class PollVoteFragment(
|
|||||||
CheckBox(context).apply { text = option }
|
CheckBox(context).apply { text = option }
|
||||||
}?.forEachIndexed { index, checkBox ->
|
}?.forEachIndexed { index, checkBox ->
|
||||||
checkBox.id = index
|
checkBox.id = index
|
||||||
// if (poll.votedSelf?.contains(index) == true) {
|
|
||||||
// checkBox.setTypeface(null, Typeface.BOLD)
|
|
||||||
// }
|
|
||||||
makeOptionBoldIfSelfVoted(checkBox, poll, index)
|
makeOptionBoldIfSelfVoted(checkBox, poll, index)
|
||||||
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
|
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
|
||||||
|
|
||||||
@ -147,11 +143,22 @@ class PollVoteFragment(
|
|||||||
} else {
|
} else {
|
||||||
viewModel.deSelectOption(index)
|
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) {
|
private fun makeOptionBoldIfSelfVoted(button: CompoundButton, poll: Poll, index: Int) {
|
||||||
if (poll.votedSelf?.contains(index) == true) {
|
if (poll.votedSelf?.contains(index) == true) {
|
||||||
button.setTypeface(null, Typeface.BOLD)
|
button.setTypeface(null, Typeface.BOLD)
|
||||||
|
@ -46,11 +46,16 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
|
|||||||
|
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
private var _votedOptions: List<Int> = emptyList()
|
||||||
|
val votedOptions: List<Int>
|
||||||
|
get() = _votedOptions
|
||||||
|
|
||||||
private var _selectedOptions: List<Int> = emptyList()
|
private var _selectedOptions: List<Int> = emptyList()
|
||||||
val selectedOptions: List<Int>
|
val selectedOptions: List<Int>
|
||||||
get() = _selectedOptions
|
get() = _selectedOptions
|
||||||
|
|
||||||
fun initSelectedOptions(selectedOptions: List<Int>) {
|
fun initVotedOptions(selectedOptions: List<Int>) {
|
||||||
|
_votedOptions = selectedOptions
|
||||||
_selectedOptions = selectedOptions
|
_selectedOptions = selectedOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user