diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt index 1ee30ee68..ba7f0d57d 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt @@ -10,8 +10,10 @@ import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.lifecycle.ViewModelProvider import autodagger.AutoInjector +import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.databinding.DialogPollMainBinding +import com.nextcloud.talk.polls.model.Poll import com.nextcloud.talk.polls.viewmodels.PollMainViewModel import javax.inject.Inject @@ -58,16 +60,23 @@ class PollMainDialogFragment( viewModel.viewState.observe(viewLifecycleOwner) { state -> when (state) { PollMainViewModel.InitialState -> {} - is PollMainViewModel.PollVoteHiddenState -> showVoteFragment() - is PollMainViewModel.PollVoteState -> showVoteFragment() - is PollMainViewModel.PollResultState -> showResultsFragment() + is PollMainViewModel.PollVoteHiddenState -> { + binding.pollDetailsText.visibility = View.VISIBLE + binding.pollDetailsText.text = "You already voted for this private poll" + showVoteScreen() + } + is PollMainViewModel.PollVoteState -> { + binding.pollDetailsText.visibility = View.GONE + showVoteScreen() + } + is PollMainViewModel.PollResultState -> showResultsScreen(state.poll) } } viewModel.initialize(roomToken, pollId) } - private fun showVoteFragment() { + private fun showVoteScreen() { val contentFragment = PollVoteFragment( viewModel, roomToken, @@ -78,7 +87,9 @@ class PollMainDialogFragment( transaction.commit() } - private fun showResultsFragment() { + private fun showResultsScreen(poll: Poll) { + initVotersAmount(poll.numVoters) + val contentFragment = PollResultsFragment( viewModel, roomToken, @@ -89,6 +100,14 @@ class PollMainDialogFragment( transaction.commit() } + private fun initVotersAmount(numVoters: Int) { + binding.pollDetailsText.visibility = View.VISIBLE + binding.pollDetailsText.text = String.format( + resources.getString(R.string.polls_amount_voters), + numVoters + ) + } + /** * Fragment creator */ diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt index b4262060c..a40cd0156 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt @@ -30,7 +30,6 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import autodagger.AutoInjector -import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.databinding.DialogPollResultsBinding import com.nextcloud.talk.polls.adapters.PollResultItem @@ -79,9 +78,8 @@ class PollResultsFragment( parentViewModel.viewState.observe(viewLifecycleOwner) { state -> if (state is PollMainViewModel.PollResultState) { - initAdapter(state.showDetails) + initAdapter(state.showParticipants) initPollResults(state.poll) - initAmountVotersInfo(state) initEditButton(state.showEditButton) initCloseButton(state.showCloseButton) } @@ -125,24 +123,6 @@ class PollResultsFragment( } } - private fun initAmountVotersInfo(state: PollMainViewModel.PollResultState) { - _binding?.pollAmountVoters?.text = String.format( - resources.getString(R.string.polls_amount_voters), - state.poll.numVoters - ) - } - - // private fun initEditButton(state: PollMainViewModel.PollResultState) { - // if (state.poll.status == Poll.STATUS_OPEN && state.poll.resultMode == Poll.RESULT_MODE_PUBLIC) { - // _binding?.editVoteButton?.visibility = View.VISIBLE - // _binding?.editVoteButton?.setOnClickListener { - // parentViewModel.edit() - // } - // } else { - // _binding?.editVoteButton?.visibility = View.GONE - // } - // } - private fun initEditButton(showEditButton: Boolean) { if (showEditButton) { _binding?.editVoteButton?.visibility = View.VISIBLE diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt index d3b700811..f6fbd2541 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt @@ -73,10 +73,10 @@ class PollVoteFragment( parentViewModel.viewState.observe(viewLifecycleOwner) { state -> if (state is PollMainViewModel.PollVoteState) { initPollOptions(state.poll) - binding.pollVoteHiddenHint.visibility = View.GONE + // binding.pollVoteHiddenHint.visibility = View.GONE } else if (state is PollMainViewModel.PollVoteHiddenState) { initPollOptions(state.poll) - binding.pollVoteHiddenHint.visibility = View.VISIBLE + // binding.pollVoteHiddenHint.visibility = View.VISIBLE } } diff --git a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt index 3e7955d23..35f166344 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt @@ -40,7 +40,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito open class PollVoteHiddenState(val poll: Poll) : ViewState open class PollResultState( val poll: Poll, - val showDetails: Boolean, + val showParticipants: Boolean, val showEditButton: Boolean, val showCloseButton: Boolean ) : ViewState @@ -59,7 +59,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito } fun voted() { - loadPoll() // TODO load other view + loadPoll() } fun edit() { @@ -118,7 +118,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito } } - fun setPollResultState(poll: Poll) { + private fun setPollResultState(poll: Poll) { val showDetails = poll.status == Poll.STATUS_CLOSED && poll.resultMode == Poll.RESULT_MODE_PUBLIC val showEditButton = poll.status == Poll.STATUS_OPEN && poll.resultMode == Poll.RESULT_MODE_PUBLIC val showCloseButton = poll.status == Poll.STATUS_OPEN && isPollCreatedByCurrentUser(poll) @@ -126,13 +126,13 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito _viewState.value = PollResultState(poll, showDetails, showEditButton, showCloseButton) } - fun votedForOpenHiddenPoll(poll: Poll): Boolean { + private fun votedForOpenHiddenPoll(poll: Poll): Boolean { return poll.status == Poll.STATUS_OPEN && poll.resultMode == Poll.RESULT_MODE_HIDDEN && poll.votedSelf?.isNotEmpty() == true } - fun isPollCreatedByCurrentUser(poll: Poll): Boolean { + private fun isPollCreatedByCurrentUser(poll: Poll): Boolean { return userUtils.currentUser?.userId == poll.actorId } diff --git a/app/src/main/res/layout/dialog_poll_main.xml b/app/src/main/res/layout/dialog_poll_main.xml index c03afd25d..59e5e8a84 100644 --- a/app/src/main/res/layout/dialog_poll_main.xml +++ b/app/src/main/res/layout/dialog_poll_main.xml @@ -21,14 +21,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:padding="@dimen/standard_padding" tools:background="@color/white"> + + diff --git a/app/src/main/res/layout/dialog_poll_results.xml b/app/src/main/res/layout/dialog_poll_results.xml index 49308a76c..211dfb61a 100644 --- a/app/src/main/res/layout/dialog_poll_results.xml +++ b/app/src/main/res/layout/dialog_poll_results.xml @@ -21,7 +21,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" - android:padding="@dimen/standard_padding" tools:background="@color/white"> - - - -