add ability to close poll in PollVoteFragment

this adds duplicate button logic atm. might need to be improved..

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-06-22 20:34:50 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent 8c898404d1
commit 8541ebbfc0
5 changed files with 46 additions and 15 deletions

View File

@ -73,10 +73,10 @@ class PollVoteFragment(
parentViewModel.viewState.observe(viewLifecycleOwner) { state ->
if (state is PollMainViewModel.PollVoteState) {
initPollOptions(state.poll)
// binding.pollVoteHiddenHint.visibility = View.GONE
initCloseButton(state.showCloseButton)
} else if (state is PollMainViewModel.PollVoteHiddenState) {
initPollOptions(state.poll)
// binding.pollVoteHiddenHint.visibility = View.VISIBLE
initCloseButton(state.showCloseButton)
}
}
@ -98,7 +98,7 @@ class PollVoteFragment(
}
// todo observe viewmodel checked, set view checked with it
binding.submitVote.setOnClickListener {
binding.pollVoteSubmitButton.setOnClickListener {
viewModel.vote(roomToken, pollId, binding.radioGroup.checkedRadioButtonId)
}
}
@ -113,6 +113,17 @@ class PollVoteFragment(
}
}
private fun initCloseButton(showCloseButton: Boolean) {
if (showCloseButton) {
_binding?.pollVoteClosePollButton?.visibility = View.VISIBLE
_binding?.pollVoteClosePollButton?.setOnClickListener {
parentViewModel.closePoll()
}
} else {
_binding?.pollVoteClosePollButton?.visibility = View.GONE
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null

View File

@ -36,8 +36,16 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
sealed interface ViewState
object InitialState : ViewState
open class PollVoteState(val poll: Poll) : ViewState
open class PollVoteHiddenState(val poll: Poll) : ViewState
open class PollVoteState(
val poll: Poll,
val showCloseButton: Boolean
) : ViewState
open class PollVoteHiddenState(
val poll: Poll,
val showCloseButton: Boolean
) : ViewState
open class PollResultState(
val poll: Poll,
val showParticipants: Boolean,
@ -103,15 +111,17 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
}
override fun onComplete() {
val showCloseButton = poll.status == Poll.STATUS_OPEN && isPollCreatedByCurrentUser(poll)
if (votedForOpenHiddenPoll(poll)) {
_viewState.value = PollVoteHiddenState(poll)
_viewState.value = PollVoteHiddenState(poll, showCloseButton)
} else if (editPoll && poll.status == Poll.STATUS_OPEN) {
_viewState.value = PollVoteState(poll)
_viewState.value = PollVoteState(poll, showCloseButton)
editPoll = false
} else if (poll.status == Poll.STATUS_CLOSED || poll.votedSelf?.isNotEmpty() == true) {
setPollResultState(poll)
} else if (poll.votedSelf.isNullOrEmpty()) {
_viewState.value = PollVoteState(poll)
_viewState.value = PollVoteState(poll, showCloseButton)
} else {
Log.w(TAG, "unknown poll state")
}

View File

@ -41,19 +41,17 @@
android:id="@+id/poll_results_close_poll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Close"
android:theme="@style/Button.Primary"
android:text="@string/polls_close_poll"
style="@style/OutlinedButton"
android:layout_marginEnd="@dimen/standard_margin"
app:cornerRadius="@dimen/button_corner_radius"
app:layout_constraintEnd_toStartOf="@+id/edit_vote_button"
app:layout_constraintTop_toBottomOf="@+id/poll_results_list_wrapper" />
<com.google.android.material.button.MaterialButton
android:id="@+id/edit_vote_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/edit"
android:theme="@style/Button.Primary"
app:cornerRadius="@dimen/button_corner_radius"

View File

@ -33,13 +33,24 @@
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/submitVote"
android:id="@+id/poll_vote_close_poll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/polls_close_poll"
style="@style/OutlinedButton"
android:layout_marginEnd="@dimen/standard_margin"
app:cornerRadius="@dimen/button_corner_radius"
app:layout_constraintEnd_toStartOf="@+id/poll_vote_submit_button"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
<com.google.android.material.button.MaterialButton
android:id="@+id/poll_vote_submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cornerRadius="@dimen/button_corner_radius"
android:text="@string/nc_common_submit"
android:theme="@style/Button.Primary"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

View File

@ -539,6 +539,7 @@
<!-- Polls -->
<string name="polls_amount_voters">Poll results - %1$s votes</string>
<string name="polls_add_option">Add Option</string>
<string name="polls_close_poll">Close Poll</string>
<string name="title_attachments">Attachments</string>