Procházet zdrojové kódy

add dismiss button for edit votes mode

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe před 3 roky
rodič
revize
6b8c83f553

+ 1 - 1
app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.kt

@@ -125,7 +125,7 @@ data class ChatMessage(
     var voiceMessageDownloadProgress: Int = 0,
 ) : Parcelable, MessageContentType, MessageContentType.Image {
 
-    // TODO: messageTypesToIgnore is weird. must be deleted by refactoring!
+    // messageTypesToIgnore is weird. must be deleted by refactoring!!!
     @JsonIgnore
     var messageTypesToIgnore = Arrays.asList(
         MessageType.REGULAR_TEXT_MESSAGE,

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

@@ -89,6 +89,7 @@ class PollVoteFragment : Fragment() {
                 initPollOptions(state.poll)
                 initEndPollButton(state.showEndPollButton)
                 updateSubmitButton()
+                updateDismissEditButton(state.showDismissEditButton)
             } else if (state is PollMainViewModel.PollVoteHiddenState) {
                 initPollOptions(state.poll)
                 initEndPollButton(state.showEndPollButton)
@@ -117,6 +118,18 @@ class PollVoteFragment : Fragment() {
         binding.pollVoteSubmitButton.setOnClickListener {
             viewModel.vote(roomToken, pollId)
         }
+
+        binding.pollVoteEditDismiss.setOnClickListener {
+            parentViewModel.dismissEditVotes()
+        }
+    }
+
+    private fun updateDismissEditButton(showDismissEditButton: Boolean) {
+        if (showDismissEditButton) {
+            binding.pollVoteEditDismiss.visibility = View.VISIBLE
+        } else {
+            binding.pollVoteEditDismiss.visibility = View.GONE
+        }
     }
 
     private fun initPollOptions(poll: Poll) {

+ 8 - 3
app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt

@@ -61,7 +61,8 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
     open class PollVoteState(
         val poll: Poll,
         val showVotersAmount: Boolean,
-        val showEndPollButton: Boolean
+        val showEndPollButton: Boolean,
+        val showDismissEditButton: Boolean
     ) : ViewState
 
     open class PollVoteHiddenState(
@@ -99,6 +100,10 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
         loadPoll()
     }
 
+    fun dismissEditVotes() {
+        loadPoll()
+    }
+
     private fun loadPoll() {
         repository.getPoll(roomToken, pollId)
             ?.doOnSubscribe { disposable = it }
@@ -141,13 +146,13 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
             if (votedForOpenHiddenPoll(poll)) {
                 _viewState.value = PollVoteHiddenState(poll, showVotersAmount, showEndPollButton)
             } else if (editVotes && poll.status == Poll.STATUS_OPEN) {
-                _viewState.value = PollVoteState(poll, false, showEndPollButton)
+                _viewState.value = PollVoteState(poll, false, showEndPollButton, true)
                 editVotes = false
             } else if (poll.status == Poll.STATUS_CLOSED || poll.votedSelf?.isNotEmpty() == true) {
                 val showEditButton = poll.status == Poll.STATUS_OPEN && poll.resultMode == Poll.RESULT_MODE_PUBLIC
                 _viewState.value = PollResultState(poll, showVotersAmount, showEndPollButton, showEditButton)
             } else if (poll.votedSelf.isNullOrEmpty()) {
-                _viewState.value = PollVoteState(poll, showVotersAmount, showEndPollButton)
+                _viewState.value = PollVoteState(poll, showVotersAmount, showEndPollButton, false)
             } else {
                 Log.w(TAG, "unknown poll state")
             }

+ 11 - 0
app/src/main/res/layout/dialog_poll_vote.xml

@@ -66,6 +66,17 @@
             android:layout_marginEnd="@dimen/standard_margin"
             app:cornerRadius="@dimen/button_corner_radius" />
 
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/poll_vote_edit_dismiss"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/nc_common_dismiss"
+            style="@style/OutlinedButton"
+            android:layout_marginEnd="@dimen/standard_margin"
+            android:visibility="gone"
+            app:cornerRadius="@dimen/button_corner_radius"
+            tools:visibility="visible"/>
+
         <com.google.android.material.button.MaterialButton
             android:id="@+id/poll_vote_submit_button"
             android:layout_width="wrap_content"