Navigate to poll detail fragment.

This commit is contained in:
Onuray Sahin 2023-01-27 16:31:30 +03:00 committed by Maxime NATUREL
parent 783596723e
commit c9dc570f83
10 changed files with 67 additions and 4 deletions

View file

@ -37,6 +37,7 @@ import im.vector.app.features.roomprofile.members.RoomMemberListFragment
import im.vector.app.features.roomprofile.notifications.RoomNotificationSettingsFragment import im.vector.app.features.roomprofile.notifications.RoomNotificationSettingsFragment
import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment
import im.vector.app.features.roomprofile.polls.RoomPollsFragment import im.vector.app.features.roomprofile.polls.RoomPollsFragment
import im.vector.app.features.roomprofile.polls.detail.RoomPollDetailFragment
import im.vector.app.features.roomprofile.settings.RoomSettingsFragment import im.vector.app.features.roomprofile.settings.RoomSettingsFragment
import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment
import im.vector.lib.core.utils.compat.getParcelableCompat import im.vector.lib.core.utils.compat.getParcelableCompat
@ -105,6 +106,7 @@ class RoomProfileActivity :
RoomProfileSharedAction.OpenRoomUploads -> openRoomUploads() RoomProfileSharedAction.OpenRoomUploads -> openRoomUploads()
RoomProfileSharedAction.OpenBannedRoomMembers -> openBannedRoomMembers() RoomProfileSharedAction.OpenBannedRoomMembers -> openBannedRoomMembers()
RoomProfileSharedAction.OpenRoomNotificationSettings -> openRoomNotificationSettings() RoomProfileSharedAction.OpenRoomNotificationSettings -> openRoomNotificationSettings()
is RoomProfileSharedAction.OpenPollDetails -> handleOpenPollDetails()
} }
} }
.launchIn(lifecycleScope) .launchIn(lifecycleScope)
@ -130,6 +132,10 @@ class RoomProfileActivity :
finish() finish()
} }
private fun handleOpenPollDetails() {
addFragmentToBackstack(views.simpleFragmentContainer, RoomPollDetailFragment::class.java, roomProfileArgs)
}
private fun openRoomPolls() { private fun openRoomPolls() {
addFragmentToBackstack(views.simpleFragmentContainer, RoomPollsFragment::class.java, roomProfileArgs) addFragmentToBackstack(views.simpleFragmentContainer, RoomPollsFragment::class.java, roomProfileArgs)
} }

View file

@ -26,6 +26,7 @@ sealed class RoomProfileSharedAction : VectorSharedAction {
object OpenRoomAliasesSettings : RoomProfileSharedAction() object OpenRoomAliasesSettings : RoomProfileSharedAction()
object OpenRoomPermissionsSettings : RoomProfileSharedAction() object OpenRoomPermissionsSettings : RoomProfileSharedAction()
object OpenRoomPolls : RoomProfileSharedAction() object OpenRoomPolls : RoomProfileSharedAction()
object OpenPollDetails : RoomProfileSharedAction()
object OpenRoomUploads : RoomProfileSharedAction() object OpenRoomUploads : RoomProfileSharedAction()
object OpenRoomMembers : RoomProfileSharedAction() object OpenRoomMembers : RoomProfileSharedAction()
object OpenBannedRoomMembers : RoomProfileSharedAction() object OpenBannedRoomMembers : RoomProfileSharedAction()

View file

@ -20,4 +20,5 @@ import im.vector.app.core.platform.VectorViewModelAction
sealed interface RoomPollsAction : VectorViewModelAction { sealed interface RoomPollsAction : VectorViewModelAction {
object LoadMorePolls : RoomPollsAction object LoadMorePolls : RoomPollsAction
data class OnPollSelected(val selectedPollId: String) : RoomPollsAction
} }

View file

@ -20,4 +20,5 @@ import im.vector.app.core.platform.VectorViewEvents
sealed class RoomPollsViewEvent : VectorViewEvents { sealed class RoomPollsViewEvent : VectorViewEvents {
object LoadingError : RoomPollsViewEvent() object LoadingError : RoomPollsViewEvent()
object NavigateToPollDetail : RoomPollsViewEvent()
} }

View file

@ -89,9 +89,15 @@ class RoomPollsViewModel @AssistedInject constructor(
override fun handle(action: RoomPollsAction) { override fun handle(action: RoomPollsAction) {
when (action) { when (action) {
RoomPollsAction.LoadMorePolls -> handleLoadMore() RoomPollsAction.LoadMorePolls -> handleLoadMore()
is RoomPollsAction.OnPollSelected -> handleOnPollSelected(action)
} }
} }
private fun handleOnPollSelected(action: RoomPollsAction.OnPollSelected) {
setState { copy(selectedPollId = action.selectedPollId) }
_viewEvents.post(RoomPollsViewEvent.NavigateToPollDetail)
}
private fun handleLoadMore() = withState { viewState -> private fun handleLoadMore() = withState { viewState ->
viewModelScope.launch { viewModelScope.launch {
setState { copy(isLoadingMore = true) } setState { copy(isLoadingMore = true) }

View file

@ -27,10 +27,12 @@ data class RoomPollsViewState(
val canLoadMore: Boolean = true, val canLoadMore: Boolean = true,
val nbSyncedDays: Int = 0, val nbSyncedDays: Int = 0,
val isSyncing: Boolean = false, val isSyncing: Boolean = false,
val selectedPollId: String? = null,
) : MavericksState { ) : MavericksState {
constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId) constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId)
fun hasNoPolls() = polls.isEmpty() fun hasNoPolls() = polls.isEmpty()
fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore
fun getSelectedPoll() = polls.find { it.id == selectedPollId }
} }

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.roomprofile.polls.detail
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentRoomPollDetailBinding
class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>() {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollDetailBinding {
return FragmentRoomPollDetailBinding.inflate(inflater, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar(views.roomPollDetailToolbar)
.allowBack()
}
}

View file

@ -22,11 +22,13 @@ sealed interface PollSummary {
val id: String val id: String
val creationTimestamp: Long val creationTimestamp: Long
val title: String val title: String
val optionViewStates: List<PollOptionViewState>
data class ActivePoll( data class ActivePoll(
override val id: String, override val id: String,
override val creationTimestamp: Long, override val creationTimestamp: Long,
override val title: String, override val title: String,
override val optionViewStates: List<PollOptionViewState>,
) : PollSummary ) : PollSummary
data class EndedPoll( data class EndedPoll(
@ -35,5 +37,6 @@ sealed interface PollSummary {
override val title: String, override val title: String,
val totalVotes: Int, val totalVotes: Int,
val winnerOptions: List<PollOptionViewState.PollEnded>, val winnerOptions: List<PollOptionViewState.PollEnded>,
override val optionViewStates: List<PollOptionViewState>,
) : PollSummary ) : PollSummary
} }

View file

@ -69,13 +69,15 @@ class PollSummaryMapper @Inject constructor(
creationTimestamp = creationTimestamp, creationTimestamp = creationTimestamp,
title = pollTitle, title = pollTitle,
totalVotes = pollResponseData.totalVotes, totalVotes = pollResponseData.totalVotes,
winnerOptions = pollOptionViewStateFactory.createPollEndedOptions(pollCreationInfo, pollResponseData) winnerOptions = pollOptionViewStateFactory.createPollEndedOptions(pollCreationInfo, pollResponseData),
optionViewStates = pollOptionViewStateFactory.createPollSendingOptions(pollCreationInfo),
) )
} else { } else {
PollSummary.ActivePoll( PollSummary.ActivePoll(
id = eventId, id = eventId,
creationTimestamp = creationTimestamp, creationTimestamp = creationTimestamp,
title = pollTitle, title = pollTitle,
optionViewStates = pollOptionViewStateFactory.createPollSendingOptions(pollCreationInfo),
) )
} }
} }

View file

@ -29,13 +29,14 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.FragmentRoomPollsListBinding import im.vector.app.databinding.FragmentRoomPollsListBinding
import im.vector.app.features.roomprofile.RoomProfileSharedAction
import im.vector.app.features.roomprofile.RoomProfileSharedActionViewModel
import im.vector.app.features.roomprofile.polls.RoomPollsAction import im.vector.app.features.roomprofile.polls.RoomPollsAction
import im.vector.app.features.roomprofile.polls.RoomPollsLoadingError import im.vector.app.features.roomprofile.polls.RoomPollsLoadingError
import im.vector.app.features.roomprofile.polls.RoomPollsType import im.vector.app.features.roomprofile.polls.RoomPollsType
import im.vector.app.features.roomprofile.polls.RoomPollsViewEvent import im.vector.app.features.roomprofile.polls.RoomPollsViewEvent
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
import im.vector.app.features.roomprofile.polls.RoomPollsViewState import im.vector.app.features.roomprofile.polls.RoomPollsViewState
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
abstract class RoomPollsListFragment : abstract class RoomPollsListFragment :
@ -49,6 +50,7 @@ abstract class RoomPollsListFragment :
lateinit var stringProvider: StringProvider lateinit var stringProvider: StringProvider
private val viewModel: RoomPollsViewModel by parentFragmentViewModel(RoomPollsViewModel::class) private val viewModel: RoomPollsViewModel by parentFragmentViewModel(RoomPollsViewModel::class)
private lateinit var sharedActionViewModel: RoomProfileSharedActionViewModel
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsListBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsListBinding {
return FragmentRoomPollsListBinding.inflate(inflater, container, false) return FragmentRoomPollsListBinding.inflate(inflater, container, false)
@ -56,6 +58,7 @@ abstract class RoomPollsListFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
sharedActionViewModel = activityViewModelProvider[RoomProfileSharedActionViewModel::class.java]
observeViewEvents() observeViewEvents()
setupList() setupList()
setupLoadMoreButton() setupLoadMoreButton()
@ -65,6 +68,7 @@ abstract class RoomPollsListFragment :
viewModel.observeViewEvents { viewEvent -> viewModel.observeViewEvents { viewEvent ->
when (viewEvent) { when (viewEvent) {
RoomPollsViewEvent.LoadingError -> showErrorInSnackbar(RoomPollsLoadingError()) RoomPollsViewEvent.LoadingError -> showErrorInSnackbar(RoomPollsLoadingError())
RoomPollsViewEvent.NavigateToPollDetail -> sharedActionViewModel.post(RoomProfileSharedAction.OpenPollDetails)
} }
} }
} }
@ -126,8 +130,7 @@ abstract class RoomPollsListFragment :
} }
override fun onPollClicked(pollId: String) { override fun onPollClicked(pollId: String) {
// TODO navigate to details viewModel.handle(RoomPollsAction.OnPollSelected(pollId))
Timber.d("poll with id $pollId clicked")
} }
override fun onLoadMoreClicked() { override fun onLoadMoreClicked() {