mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 13:09:46 +01:00
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:
parent
8c898404d1
commit
8541ebbfc0
@ -73,10 +73,10 @@ class PollVoteFragment(
|
|||||||
parentViewModel.viewState.observe(viewLifecycleOwner) { state ->
|
parentViewModel.viewState.observe(viewLifecycleOwner) { state ->
|
||||||
if (state is PollMainViewModel.PollVoteState) {
|
if (state is PollMainViewModel.PollVoteState) {
|
||||||
initPollOptions(state.poll)
|
initPollOptions(state.poll)
|
||||||
// binding.pollVoteHiddenHint.visibility = View.GONE
|
initCloseButton(state.showCloseButton)
|
||||||
} else if (state is PollMainViewModel.PollVoteHiddenState) {
|
} else if (state is PollMainViewModel.PollVoteHiddenState) {
|
||||||
initPollOptions(state.poll)
|
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
|
// todo observe viewmodel checked, set view checked with it
|
||||||
|
|
||||||
binding.submitVote.setOnClickListener {
|
binding.pollVoteSubmitButton.setOnClickListener {
|
||||||
viewModel.vote(roomToken, pollId, binding.radioGroup.checkedRadioButtonId)
|
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() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
_binding = null
|
_binding = null
|
||||||
|
@ -36,8 +36,16 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
|
|||||||
|
|
||||||
sealed interface ViewState
|
sealed interface ViewState
|
||||||
object InitialState : ViewState
|
object InitialState : ViewState
|
||||||
open class PollVoteState(val poll: Poll) : ViewState
|
open class PollVoteState(
|
||||||
open class PollVoteHiddenState(val poll: Poll) : ViewState
|
val poll: Poll,
|
||||||
|
val showCloseButton: Boolean
|
||||||
|
) : ViewState
|
||||||
|
|
||||||
|
open class PollVoteHiddenState(
|
||||||
|
val poll: Poll,
|
||||||
|
val showCloseButton: Boolean
|
||||||
|
) : ViewState
|
||||||
|
|
||||||
open class PollResultState(
|
open class PollResultState(
|
||||||
val poll: Poll,
|
val poll: Poll,
|
||||||
val showParticipants: Boolean,
|
val showParticipants: Boolean,
|
||||||
@ -103,15 +111,17 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onComplete() {
|
override fun onComplete() {
|
||||||
|
val showCloseButton = poll.status == Poll.STATUS_OPEN && isPollCreatedByCurrentUser(poll)
|
||||||
|
|
||||||
if (votedForOpenHiddenPoll(poll)) {
|
if (votedForOpenHiddenPoll(poll)) {
|
||||||
_viewState.value = PollVoteHiddenState(poll)
|
_viewState.value = PollVoteHiddenState(poll, showCloseButton)
|
||||||
} else if (editPoll && poll.status == Poll.STATUS_OPEN) {
|
} else if (editPoll && poll.status == Poll.STATUS_OPEN) {
|
||||||
_viewState.value = PollVoteState(poll)
|
_viewState.value = PollVoteState(poll, showCloseButton)
|
||||||
editPoll = false
|
editPoll = false
|
||||||
} else if (poll.status == Poll.STATUS_CLOSED || poll.votedSelf?.isNotEmpty() == true) {
|
} else if (poll.status == Poll.STATUS_CLOSED || poll.votedSelf?.isNotEmpty() == true) {
|
||||||
setPollResultState(poll)
|
setPollResultState(poll)
|
||||||
} else if (poll.votedSelf.isNullOrEmpty()) {
|
} else if (poll.votedSelf.isNullOrEmpty()) {
|
||||||
_viewState.value = PollVoteState(poll)
|
_viewState.value = PollVoteState(poll, showCloseButton)
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "unknown poll state")
|
Log.w(TAG, "unknown poll state")
|
||||||
}
|
}
|
||||||
|
@ -41,19 +41,17 @@
|
|||||||
android:id="@+id/poll_results_close_poll_button"
|
android:id="@+id/poll_results_close_poll_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:text="@string/polls_close_poll"
|
||||||
android:text="Close"
|
style="@style/OutlinedButton"
|
||||||
android:theme="@style/Button.Primary"
|
android:layout_marginEnd="@dimen/standard_margin"
|
||||||
app:cornerRadius="@dimen/button_corner_radius"
|
app:cornerRadius="@dimen/button_corner_radius"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/edit_vote_button"
|
app:layout_constraintEnd_toStartOf="@+id/edit_vote_button"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/poll_results_list_wrapper" />
|
app:layout_constraintTop_toBottomOf="@+id/poll_results_list_wrapper" />
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/edit_vote_button"
|
android:id="@+id/edit_vote_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/edit"
|
android:text="@string/edit"
|
||||||
android:theme="@style/Button.Primary"
|
android:theme="@style/Button.Primary"
|
||||||
app:cornerRadius="@dimen/button_corner_radius"
|
app:cornerRadius="@dimen/button_corner_radius"
|
||||||
|
@ -33,13 +33,24 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:cornerRadius="@dimen/button_corner_radius"
|
app:cornerRadius="@dimen/button_corner_radius"
|
||||||
android:text="@string/nc_common_submit"
|
android:text="@string/nc_common_submit"
|
||||||
android:theme="@style/Button.Primary"
|
android:theme="@style/Button.Primary"
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
|
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
|
||||||
|
|
||||||
|
@ -539,6 +539,7 @@
|
|||||||
<!-- Polls -->
|
<!-- Polls -->
|
||||||
<string name="polls_amount_voters">Poll results - %1$s votes</string>
|
<string name="polls_amount_voters">Poll results - %1$s votes</string>
|
||||||
<string name="polls_add_option">Add Option</string>
|
<string name="polls_add_option">Add Option</string>
|
||||||
|
<string name="polls_close_poll">Close Poll</string>
|
||||||
|
|
||||||
<string name="title_attachments">Attachments</string>
|
<string name="title_attachments">Attachments</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user