Kaynağa Gözat

close dialog when voted for hidden poll

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 yıl önce
ebeveyn
işleme
f46d2d28f5

+ 3 - 7
app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt

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

+ 4 - 4
app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt

@@ -80,10 +80,6 @@ class PollVoteFragment : Fragment() {
                 initEndPollButton(state.showEndPollButton)
                 updateSubmitButton()
                 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.")
                     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 -> {
                     parentViewModel.voted()
                 }

+ 6 - 7
app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt

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

+ 7 - 2
app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollVoteViewModel.kt

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

+ 0 - 10
app/src/main/res/layout/dialog_poll_main.xml

@@ -85,16 +85,6 @@
 
     </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
         android:id="@+id/message_poll_content_fragment"
         android:layout_width="match_parent"

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -536,9 +536,9 @@
     <string name="message_poll_tap_see_results">Tap to see results</string>
     <string name="polls_amount_voters">%1$s votes</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_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_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>