mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 20:22:03 +00:00
remove liveData for selectedOptions
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
acda3d283b
commit
2da4c37a52
@ -125,7 +125,7 @@ class PollVoteFragment(
|
|||||||
checkBox.id = index
|
checkBox.id = index
|
||||||
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
|
binding.voteOptionsCheckboxesWrapper.addView(checkBox)
|
||||||
|
|
||||||
checkBox.isChecked = viewModel.selectedOptions.value?.contains(index) == true
|
checkBox.isChecked = viewModel.selectedOptions.contains(index) == true
|
||||||
checkBox.setOnCheckedChangeListener { buttonView, isChecked ->
|
checkBox.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
viewModel.selectOption(index)
|
viewModel.selectOption(index)
|
||||||
|
@ -46,25 +46,25 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
|
|||||||
|
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
private val _selectedOptions: MutableLiveData<List<Int>> = MutableLiveData(emptyList())
|
private var _selectedOptions: List<Int> = emptyList()
|
||||||
val selectedOptions: LiveData<List<Int>>
|
val selectedOptions: List<Int>
|
||||||
get() = _selectedOptions
|
get() = _selectedOptions
|
||||||
|
|
||||||
fun initSelectedOptions(selectedOptions: List<Int>) {
|
fun initSelectedOptions(selectedOptions: List<Int>) {
|
||||||
_selectedOptions.value = selectedOptions
|
_selectedOptions = selectedOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectOption(option: Int) {
|
fun selectOption(option: Int) {
|
||||||
_selectedOptions.value = _selectedOptions.value?.plus(option)
|
_selectedOptions = _selectedOptions.plus(option)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deSelectOption(option: Int) {
|
fun deSelectOption(option: Int) {
|
||||||
_selectedOptions.value = _selectedOptions.value?.minus(option)
|
_selectedOptions = _selectedOptions.minus(option)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun vote(roomToken: String, pollId: String) {
|
fun vote(roomToken: String, pollId: String) {
|
||||||
if (!_selectedOptions.value.isNullOrEmpty()) {
|
if (_selectedOptions.isNotEmpty()) {
|
||||||
repository.vote(roomToken, pollId, _selectedOptions.value!!)
|
repository.vote(roomToken, pollId, _selectedOptions)
|
||||||
?.doOnSubscribe { disposable = it }
|
?.doOnSubscribe { disposable = it }
|
||||||
?.subscribeOn(Schedulers.io())
|
?.subscribeOn(Schedulers.io())
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
Loading…
Reference in New Issue
Block a user