diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollCreateDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollCreateDialogFragment.kt index 2e9a11e72..6d9c38661 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollCreateDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollCreateDialogFragment.kt @@ -83,9 +83,6 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener super.onViewCreated(view, savedInstanceState) viewModel.options.observe(viewLifecycleOwner) { options -> adapter?.updateOptionsList(options) } - viewModel.question.observe(viewLifecycleOwner) { binding.pollCreateQuestion.setText(it) } - viewModel.privatePoll.observe(viewLifecycleOwner) { binding.pollPrivatePollCheckbox.isChecked = it } - viewModel.multipleAnswer.observe(viewLifecycleOwner) { binding.pollMultipleAnswersCheckbox.isChecked = it } binding.pollCreateOptionsList.layoutManager = LinearLayoutManager(context) @@ -118,7 +115,7 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener } override fun onTextChanged(question: CharSequence, start: Int, before: Int, count: Int) { - if (question.toString() != viewModel.question.value) { + if (question.toString() != viewModel.question) { viewModel.setQuestion(question.toString()) binding.pollCreateQuestion.setSelection(binding.pollCreateQuestion.length()) } diff --git a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollCreateViewModel.kt b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollCreateViewModel.kt index 71755c713..abbfdd920 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollCreateViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollCreateViewModel.kt @@ -56,16 +56,16 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi val options: LiveData> get() = _options - private var _question: MutableLiveData = MutableLiveData() - val question: LiveData + private var _question: String = "" + val question: String get() = _question - private var _privatePoll: MutableLiveData = MutableLiveData() - val privatePoll: LiveData + private var _privatePoll: Boolean = false + val privatePoll: Boolean get() = _privatePoll - private var _multipleAnswer: MutableLiveData = MutableLiveData() - val multipleAnswer: LiveData + private var _multipleAnswer: Boolean = false + val multipleAnswer: Boolean get() = _multipleAnswer private var disposable: Disposable? = null @@ -97,18 +97,18 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi fun createPoll() { var maxVotes = 1 - if (multipleAnswer.value == true) { + if (multipleAnswer) { maxVotes = 0 } var resultMode = 0 - if (privatePoll.value == true) { + if (privatePoll) { resultMode = 1 } - if (_question.value?.isNotEmpty() == true && _options.value?.isNotEmpty() == true) { + if (_question.isNotEmpty() && _options.value?.isNotEmpty() == true) { repository.createPoll( - roomToken, _question.value!!, _options.value!!.map { it.pollOption }, resultMode, + roomToken, _question, _options.value!!.map { it.pollOption }, resultMode, maxVotes ) ?.doOnSubscribe { disposable = it } @@ -119,16 +119,16 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi } fun setQuestion(question: String) { - _question.value = question + _question = question updateCreationState() } fun setPrivatePoll(checked: Boolean) { - _privatePoll.value = checked + _privatePoll = checked } fun setMultipleAnswer(checked: Boolean) { - _multipleAnswer.value = checked + _multipleAnswer = checked } fun optionsItemTextChanged() { @@ -140,7 +140,7 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi } private fun enableCreatePollButton(): Boolean { - return _question.value?.isNotEmpty() == true && atLeastTwoOptionsAreFilled() + return _question.isNotEmpty() && atLeastTwoOptionsAreFilled() } private fun atLeastTwoOptionsAreFilled(): Boolean {