remove livedata where it's not needed

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-07-01 12:56:25 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent 2988b667fe
commit 9e8dbb70f3
2 changed files with 15 additions and 18 deletions

View File

@ -83,9 +83,6 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
viewModel.options.observe(viewLifecycleOwner) { options -> adapter?.updateOptionsList(options) } 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) binding.pollCreateOptionsList.layoutManager = LinearLayoutManager(context)
@ -118,7 +115,7 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
} }
override fun onTextChanged(question: CharSequence, start: Int, before: Int, count: Int) { 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()) viewModel.setQuestion(question.toString())
binding.pollCreateQuestion.setSelection(binding.pollCreateQuestion.length()) binding.pollCreateQuestion.setSelection(binding.pollCreateQuestion.length())
} }

View File

@ -56,16 +56,16 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi
val options: LiveData<ArrayList<PollCreateOptionItem>> val options: LiveData<ArrayList<PollCreateOptionItem>>
get() = _options get() = _options
private var _question: MutableLiveData<String> = MutableLiveData<String>() private var _question: String = ""
val question: LiveData<String> val question: String
get() = _question get() = _question
private var _privatePoll: MutableLiveData<Boolean> = MutableLiveData<Boolean>() private var _privatePoll: Boolean = false
val privatePoll: LiveData<Boolean> val privatePoll: Boolean
get() = _privatePoll get() = _privatePoll
private var _multipleAnswer: MutableLiveData<Boolean> = MutableLiveData<Boolean>() private var _multipleAnswer: Boolean = false
val multipleAnswer: LiveData<Boolean> val multipleAnswer: Boolean
get() = _multipleAnswer get() = _multipleAnswer
private var disposable: Disposable? = null private var disposable: Disposable? = null
@ -97,18 +97,18 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi
fun createPoll() { fun createPoll() {
var maxVotes = 1 var maxVotes = 1
if (multipleAnswer.value == true) { if (multipleAnswer) {
maxVotes = 0 maxVotes = 0
} }
var resultMode = 0 var resultMode = 0
if (privatePoll.value == true) { if (privatePoll) {
resultMode = 1 resultMode = 1
} }
if (_question.value?.isNotEmpty() == true && _options.value?.isNotEmpty() == true) { if (_question.isNotEmpty() && _options.value?.isNotEmpty() == true) {
repository.createPoll( repository.createPoll(
roomToken, _question.value!!, _options.value!!.map { it.pollOption }, resultMode, roomToken, _question, _options.value!!.map { it.pollOption }, resultMode,
maxVotes maxVotes
) )
?.doOnSubscribe { disposable = it } ?.doOnSubscribe { disposable = it }
@ -119,16 +119,16 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi
} }
fun setQuestion(question: String) { fun setQuestion(question: String) {
_question.value = question _question = question
updateCreationState() updateCreationState()
} }
fun setPrivatePoll(checked: Boolean) { fun setPrivatePoll(checked: Boolean) {
_privatePoll.value = checked _privatePoll = checked
} }
fun setMultipleAnswer(checked: Boolean) { fun setMultipleAnswer(checked: Boolean) {
_multipleAnswer.value = checked _multipleAnswer = checked
} }
fun optionsItemTextChanged() { fun optionsItemTextChanged() {
@ -140,7 +140,7 @@ class PollCreateViewModel @Inject constructor(private val repository: PollReposi
} }
private fun enableCreatePollButton(): Boolean { private fun enableCreatePollButton(): Boolean {
return _question.value?.isNotEmpty() == true && atLeastTwoOptionsAreFilled() return _question.isNotEmpty() && atLeastTwoOptionsAreFilled()
} }
private fun atLeastTwoOptionsAreFilled(): Boolean { private fun atLeastTwoOptionsAreFilled(): Boolean {