remove liveData for selectedOptions

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-06-23 14:28:22 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent acda3d283b
commit 2da4c37a52
2 changed files with 8 additions and 8 deletions

View file

@ -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)

View file

@ -46,25 +46,25 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
private var disposable: Disposable? = null
private val _selectedOptions: MutableLiveData<List<Int>> = MutableLiveData(emptyList())
val selectedOptions: LiveData<List<Int>>
private var _selectedOptions: List<Int> = emptyList()
val selectedOptions: List<Int>
get() = _selectedOptions
fun initSelectedOptions(selectedOptions: List<Int>) {
_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())