mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-28 01:24:03 +03:00
remove liveData for selectedOptions
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
acda3d283b
commit
2da4c37a52
2 changed files with 8 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue