add dismiss button for edit votes mode

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

View file

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

View file

@ -89,6 +89,7 @@ class PollVoteFragment : Fragment() {
initPollOptions(state.poll) initPollOptions(state.poll)
initEndPollButton(state.showEndPollButton) initEndPollButton(state.showEndPollButton)
updateSubmitButton() updateSubmitButton()
updateDismissEditButton(state.showDismissEditButton)
} else if (state is PollMainViewModel.PollVoteHiddenState) { } else if (state is PollMainViewModel.PollVoteHiddenState) {
initPollOptions(state.poll) initPollOptions(state.poll)
initEndPollButton(state.showEndPollButton) initEndPollButton(state.showEndPollButton)
@ -117,6 +118,18 @@ class PollVoteFragment : Fragment() {
binding.pollVoteSubmitButton.setOnClickListener { binding.pollVoteSubmitButton.setOnClickListener {
viewModel.vote(roomToken, pollId) 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) { private fun initPollOptions(poll: Poll) {

View file

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

View file

@ -66,6 +66,17 @@
android:layout_marginEnd="@dimen/standard_margin" android:layout_marginEnd="@dimen/standard_margin"
app:cornerRadius="@dimen/button_corner_radius" /> 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 <com.google.android.material.button.MaterialButton
android:id="@+id/poll_vote_submit_button" android:id="@+id/poll_vote_submit_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"