close dialog when voted for hidden poll

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-07-20 17:26:26 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent fe217d9700
commit f46d2d28f5
6 changed files with 21 additions and 31 deletions

View File

@ -85,21 +85,17 @@ class PollMainDialogFragment : DialogFragment() {
viewModel.viewState.observe(viewLifecycleOwner) { state -> viewModel.viewState.observe(viewLifecycleOwner) { state ->
when (state) { when (state) {
PollMainViewModel.InitialState -> {} PollMainViewModel.InitialState -> {}
is PollMainViewModel.PollVoteHiddenState -> {
binding.pollVotedHidden.visibility = View.VISIBLE
initVotersAmount(state.showVotersAmount, state.poll.numVoters, false)
showVoteScreen()
}
is PollMainViewModel.PollVoteState -> { is PollMainViewModel.PollVoteState -> {
binding.pollVotedHidden.visibility = View.GONE
initVotersAmount(state.showVotersAmount, state.poll.numVoters, false) initVotersAmount(state.showVotersAmount, state.poll.numVoters, false)
showVoteScreen() showVoteScreen()
} }
is PollMainViewModel.PollResultState -> { is PollMainViewModel.PollResultState -> {
binding.pollVotedHidden.visibility = View.GONE
initVotersAmount(state.showVotersAmount, state.poll.numVoters, true) initVotersAmount(state.showVotersAmount, state.poll.numVoters, true)
showResultsScreen() showResultsScreen()
} }
is PollMainViewModel.DismissDialogState -> {
dismiss()
}
else -> {} else -> {}
} }
} }

View File

@ -80,10 +80,6 @@ class PollVoteFragment : Fragment() {
initEndPollButton(state.showEndPollButton) initEndPollButton(state.showEndPollButton)
updateSubmitButton() updateSubmitButton()
updateDismissEditButton(state.showDismissEditButton) updateDismissEditButton(state.showDismissEditButton)
} else if (state is PollMainViewModel.PollVoteHiddenState) {
initPollOptions(state.poll)
initEndPollButton(state.showEndPollButton)
updateSubmitButton()
} }
} }
@ -94,6 +90,10 @@ class PollVoteFragment : Fragment() {
Log.e(TAG, "Failed to vote on poll.") Log.e(TAG, "Failed to vote on poll.")
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show() Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
} }
is PollVoteViewModel.PollVoteHiddenSuccessState -> {
Toast.makeText(context, R.string.polls_voted_hidden_success, Toast.LENGTH_LONG).show()
parentViewModel.dismissDialog()
}
is PollVoteViewModel.PollVoteSuccessState -> { is PollVoteViewModel.PollVoteSuccessState -> {
parentViewModel.voted() parentViewModel.voted()
} }

View File

@ -49,6 +49,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
sealed interface ViewState sealed interface ViewState
object InitialState : ViewState object InitialState : ViewState
object DismissDialogState : ViewState
open class PollVoteState( open class PollVoteState(
val poll: Poll, val poll: Poll,
val showVotersAmount: Boolean, val showVotersAmount: Boolean,
@ -56,12 +57,6 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
val showDismissEditButton: Boolean val showDismissEditButton: Boolean
) : ViewState ) : ViewState
open class PollVoteHiddenState(
val poll: Poll,
val showVotersAmount: Boolean,
val showEndPollButton: Boolean
) : ViewState
open class PollResultState( open class PollResultState(
val poll: Poll, val poll: Poll,
val showVotersAmount: Boolean, val showVotersAmount: Boolean,
@ -138,7 +133,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
val showVotersAmount = showVotersAmount(poll) val showVotersAmount = showVotersAmount(poll)
if (votedForOpenHiddenPoll(poll)) { if (votedForOpenHiddenPoll(poll)) {
_viewState.value = PollVoteHiddenState(poll, showVotersAmount, showEndPollButton) _viewState.value = PollVoteState(poll, showVotersAmount, showEndPollButton, false)
} else if (editVotes && poll.status == Poll.STATUS_OPEN) { } else if (editVotes && poll.status == Poll.STATUS_OPEN) {
_viewState.value = PollVoteState(poll, false, showEndPollButton, true) _viewState.value = PollVoteState(poll, false, showEndPollButton, true)
editVotes = false editVotes = false
@ -179,6 +174,10 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
return userUtils.currentUser?.userId == poll.actorId return userUtils.currentUser?.userId == poll.actorId
} }
fun dismissDialog() {
_viewState.value = DismissDialogState
}
companion object { companion object {
private val TAG = PollMainViewModel::class.java.simpleName private val TAG = PollMainViewModel::class.java.simpleName
} }

View File

@ -38,7 +38,8 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
sealed interface ViewState sealed interface ViewState
object InitialState : ViewState object InitialState : ViewState
open class PollVoteSuccessState(val poll: Poll) : ViewState open class PollVoteSuccessState : ViewState
open class PollVoteHiddenSuccessState : ViewState
open class PollVoteFailedState : ViewState open class PollVoteFailedState : ViewState
private val _viewState: MutableLiveData<ViewState> = MutableLiveData(InitialState) private val _viewState: MutableLiveData<ViewState> = MutableLiveData(InitialState)
@ -116,7 +117,11 @@ class PollVoteViewModel @Inject constructor(private val repository: PollReposito
} }
override fun onComplete() { override fun onComplete() {
_viewState.value = PollVoteSuccessState(poll) if (poll.resultMode == 1) {
_viewState.value = PollVoteHiddenSuccessState()
} else {
_viewState.value = PollVoteSuccessState()
}
} }
} }

View File

@ -85,16 +85,6 @@
</LinearLayout> </LinearLayout>
<TextView
android:id="@+id/poll_voted_hidden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textColor="@color/low_emphasis_text"
android:text="@string/polls_private_voted" />
<FrameLayout <FrameLayout
android:id="@+id/message_poll_content_fragment" android:id="@+id/message_poll_content_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -536,9 +536,9 @@
<string name="message_poll_tap_see_results">Tap to see results</string> <string name="message_poll_tap_see_results">Tap to see results</string>
<string name="polls_amount_voters">%1$s votes</string> <string name="polls_amount_voters">%1$s votes</string>
<string name="polls_add_option">Add option</string> <string name="polls_add_option">Add option</string>
<string name="polls_private_voted">You successfully voted for this private poll.</string>
<string name="polls_edit_vote">Edit vote</string> <string name="polls_edit_vote">Edit vote</string>
<string name="polls_submit_vote">Vote</string> <string name="polls_submit_vote">Vote</string>
<string name="polls_voted_hidden_success">Successfully voted</string>
<string name="polls_end_poll">End poll</string> <string name="polls_end_poll">End poll</string>
<string name="polls_end_poll_confirm">Do you really want to end this poll? This can\'t be undone.</string> <string name="polls_end_poll_confirm">Do you really want to end this poll? This can\'t be undone.</string>
<string name="polls_max_votes_reached">You can\'t vote with more options for this poll.</string> <string name="polls_max_votes_reached">You can\'t vote with more options for this poll.</string>