diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt index fef5a0c99..7fd31739a 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt @@ -125,7 +125,7 @@ class PollVoteFragment( checkBox.id = index binding.voteOptionsCheckboxesWrapper.addView(checkBox) - checkBox.isChecked = viewModel.selectedOptions.value?.contains(index) == true + checkBox.isChecked = viewModel.selectedOptions.contains(index) == true checkBox.setOnCheckedChangeListener { buttonView, isChecked -> if (isChecked) { viewModel.selectOption(index) diff --git a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollVoteViewModel.kt b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollVoteViewModel.kt index 41ffe54df..67ffb5fbb 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollVoteViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollVoteViewModel.kt @@ -46,25 +46,25 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito private var disposable: Disposable? = null - private val _selectedOptions: MutableLiveData> = MutableLiveData(emptyList()) - val selectedOptions: LiveData> + private var _selectedOptions: List = emptyList() + val selectedOptions: List get() = _selectedOptions fun initSelectedOptions(selectedOptions: List) { - _selectedOptions.value = selectedOptions + _selectedOptions = selectedOptions } fun selectOption(option: Int) { - _selectedOptions.value = _selectedOptions.value?.plus(option) + _selectedOptions = _selectedOptions.plus(option) } fun deSelectOption(option: Int) { - _selectedOptions.value = _selectedOptions.value?.minus(option) + _selectedOptions = _selectedOptions.minus(option) } fun vote(roomToken: String, pollId: String) { - if (!_selectedOptions.value.isNullOrEmpty()) { - repository.vote(roomToken, pollId, _selectedOptions.value!!) + if (_selectedOptions.isNotEmpty()) { + repository.vote(roomToken, pollId, _selectedOptions) ?.doOnSubscribe { disposable = it } ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread())