mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Makes bottom sheet dismiss on space change
This commit is contained in:
parent
b4ed380caf
commit
79e6dd074a
6 changed files with 122 additions and 49 deletions
|
@ -34,6 +34,7 @@ import im.vector.app.features.home.HomeSharedActionViewModel
|
||||||
import im.vector.app.features.home.room.detail.RoomDetailSharedActionViewModel
|
import im.vector.app.features.home.room.detail.RoomDetailSharedActionViewModel
|
||||||
import im.vector.app.features.home.room.detail.timeline.action.MessageSharedActionViewModel
|
import im.vector.app.features.home.room.detail.timeline.action.MessageSharedActionViewModel
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel
|
||||||
|
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||||
import im.vector.app.features.reactions.EmojiChooserViewModel
|
import im.vector.app.features.reactions.EmojiChooserViewModel
|
||||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
||||||
import im.vector.app.features.roomprofile.RoomProfileSharedActionViewModel
|
import im.vector.app.features.roomprofile.RoomProfileSharedActionViewModel
|
||||||
|
@ -157,4 +158,9 @@ interface ViewModelModule {
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@ViewModelKey(SpacePeopleSharedActionViewModel::class)
|
@ViewModelKey(SpacePeopleSharedActionViewModel::class)
|
||||||
fun bindSpacePeopleSharedActionViewModel(viewModel: SpacePeopleSharedActionViewModel): ViewModel
|
fun bindSpacePeopleSharedActionViewModel(viewModel: SpacePeopleSharedActionViewModel): ViewModel
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@ViewModelKey(RoomListSharedActionViewModel::class)
|
||||||
|
fun bindRoomListSharedActionViewModel(viewModel: RoomListSharedActionViewModel): ViewModel
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,7 @@ sealed class RoomListQuickActionsSharedAction(
|
||||||
@StringRes val titleRes: Int,
|
@StringRes val titleRes: Int,
|
||||||
@DrawableRes val iconResId: Int?,
|
@DrawableRes val iconResId: Int?,
|
||||||
val destructive: Boolean = false
|
val destructive: Boolean = false
|
||||||
) :
|
) : VectorSharedAction {
|
||||||
VectorSharedAction {
|
|
||||||
|
|
||||||
data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActionsSharedAction(
|
data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActionsSharedAction(
|
||||||
R.string.room_list_quick_actions_notifications_all_noisy,
|
R.string.room_list_quick_actions_notifications_all_noisy,
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.home.room.list.actions
|
||||||
|
|
||||||
|
import im.vector.app.core.platform.VectorSharedAction
|
||||||
|
|
||||||
|
sealed class RoomListSharedAction : VectorSharedAction {
|
||||||
|
|
||||||
|
object CloseBottomSheet : RoomListSharedAction()
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.home.room.list.actions
|
||||||
|
|
||||||
|
import im.vector.app.core.platform.VectorSharedActionViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class RoomListSharedActionViewModel @Inject constructor() : VectorSharedActionViewModel<RoomListSharedAction>()
|
|
@ -44,6 +44,8 @@ import im.vector.app.features.home.room.list.RoomSummaryPagedController
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedAction
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedAction
|
||||||
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel
|
import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel
|
||||||
|
import im.vector.app.features.home.room.list.actions.RoomListSharedAction
|
||||||
|
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||||
import im.vector.app.features.spaces.SpacesBottomSheet
|
import im.vector.app.features.spaces.SpacesBottomSheet
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -60,7 +62,8 @@ class HomeRoomListFragment @Inject constructor(
|
||||||
RoomListListener {
|
RoomListListener {
|
||||||
|
|
||||||
private val roomListViewModel: HomeRoomListViewModel by fragmentViewModel()
|
private val roomListViewModel: HomeRoomListViewModel by fragmentViewModel()
|
||||||
private lateinit var sharedActionViewModel: RoomListQuickActionsSharedActionViewModel
|
private lateinit var sharedQuickActionsViewModel: RoomListQuickActionsSharedActionViewModel
|
||||||
|
private lateinit var sharedActionViewModel: RoomListSharedActionViewModel
|
||||||
private var concatAdapter = ConcatAdapter()
|
private var concatAdapter = ConcatAdapter()
|
||||||
private var modelBuildListener: OnModelBuildFinishedListener? = null
|
private var modelBuildListener: OnModelBuildFinishedListener? = null
|
||||||
|
|
||||||
|
@ -74,15 +77,25 @@ class HomeRoomListFragment @Inject constructor(
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
sharedActionViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java]
|
|
||||||
sharedActionViewModel
|
|
||||||
.stream()
|
|
||||||
.onEach { handleQuickActions(it) }
|
|
||||||
.launchIn(viewLifecycleOwner.lifecycleScope)
|
|
||||||
|
|
||||||
views.stateView.contentView = views.roomListView
|
views.stateView.contentView = views.roomListView
|
||||||
views.stateView.state = StateView.State.Loading
|
views.stateView.state = StateView.State.Loading
|
||||||
|
setupObservers()
|
||||||
|
setupRecyclerView()
|
||||||
|
setupFabs()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupObservers() {
|
||||||
|
sharedQuickActionsViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java]
|
||||||
|
sharedActionViewModel = activityViewModelProvider[RoomListSharedActionViewModel::class.java]
|
||||||
|
|
||||||
|
sharedActionViewModel
|
||||||
|
.stream()
|
||||||
|
.onEach(::handleSharedAction)
|
||||||
|
.launchIn(viewLifecycleOwner.lifecycleScope)
|
||||||
|
sharedQuickActionsViewModel
|
||||||
|
.stream()
|
||||||
|
.onEach(::handleQuickActions)
|
||||||
|
.launchIn(viewLifecycleOwner.lifecycleScope)
|
||||||
|
|
||||||
roomListViewModel.observeViewEvents {
|
roomListViewModel.observeViewEvents {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -92,9 +105,42 @@ class HomeRoomListFragment @Inject constructor(
|
||||||
is HomeRoomListViewEvents.Done -> Unit
|
is HomeRoomListViewEvents.Done -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setupRecyclerView()
|
private fun handleSharedAction(action: RoomListSharedAction) {
|
||||||
setupFabs()
|
when (action) {
|
||||||
|
RoomListSharedAction.CloseBottomSheet -> spacesBottomSheet.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) {
|
||||||
|
when (quickAction) {
|
||||||
|
is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES_NOISY))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.NotificationsAll -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.NotificationsMentionsOnly -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MENTIONS_ONLY))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.NotificationsMute -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.Settings -> {
|
||||||
|
navigator.openRoomProfile(requireActivity(), quickAction.roomId)
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.Favorite -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_FAVOURITE))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.LowPriority -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY))
|
||||||
|
}
|
||||||
|
is RoomListQuickActionsSharedAction.Leave -> {
|
||||||
|
roomListViewModel.handle(HomeRoomListAction.LeaveRoom(quickAction.roomId))
|
||||||
|
promptLeaveRoom(quickAction.roomId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
|
@ -159,35 +205,6 @@ class HomeRoomListFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) {
|
|
||||||
when (quickAction) {
|
|
||||||
is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES_NOISY))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.NotificationsAll -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.NotificationsMentionsOnly -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MENTIONS_ONLY))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.NotificationsMute -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.Settings -> {
|
|
||||||
navigator.openRoomProfile(requireActivity(), quickAction.roomId)
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.Favorite -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_FAVOURITE))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.LowPriority -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY))
|
|
||||||
}
|
|
||||||
is RoomListQuickActionsSharedAction.Leave -> {
|
|
||||||
roomListViewModel.handle(HomeRoomListAction.LeaveRoom(quickAction.roomId))
|
|
||||||
promptLeaveRoom(quickAction.roomId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun promptLeaveRoom(roomId: String) {
|
private fun promptLeaveRoom(roomId: String) {
|
||||||
val isPublicRoom = roomListViewModel.isPublicRoom(roomId)
|
val isPublicRoom = roomListViewModel.isPublicRoom(roomId)
|
||||||
|
|
|
@ -35,6 +35,8 @@ import im.vector.app.databinding.FragmentSpaceListBinding
|
||||||
import im.vector.app.features.VectorFeatures
|
import im.vector.app.features.VectorFeatures
|
||||||
import im.vector.app.features.home.HomeActivitySharedAction
|
import im.vector.app.features.home.HomeActivitySharedAction
|
||||||
import im.vector.app.features.home.HomeSharedActionViewModel
|
import im.vector.app.features.home.HomeSharedActionViewModel
|
||||||
|
import im.vector.app.features.home.room.list.actions.RoomListSharedAction
|
||||||
|
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -48,7 +50,8 @@ class SpaceListFragment @Inject constructor(
|
||||||
private val vectorFeatures: VectorFeatures,
|
private val vectorFeatures: VectorFeatures,
|
||||||
) : VectorBaseFragment<FragmentSpaceListBinding>(), SpaceSummaryController.Callback, NewSpaceSummaryController.Callback {
|
) : VectorBaseFragment<FragmentSpaceListBinding>(), SpaceSummaryController.Callback, NewSpaceSummaryController.Callback {
|
||||||
|
|
||||||
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
|
private lateinit var homeActivitySharedActionViewModel: HomeSharedActionViewModel
|
||||||
|
private lateinit var roomListSharedActionViewModel: RoomListSharedActionViewModel
|
||||||
private val viewModel: SpaceListViewModel by fragmentViewModel()
|
private val viewModel: SpaceListViewModel by fragmentViewModel()
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSpaceListBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSpaceListBinding {
|
||||||
|
@ -57,7 +60,8 @@ class SpaceListFragment @Inject constructor(
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
sharedActionViewModel = activityViewModelProvider[HomeSharedActionViewModel::class.java]
|
homeActivitySharedActionViewModel = activityViewModelProvider[HomeSharedActionViewModel::class.java]
|
||||||
|
roomListSharedActionViewModel = activityViewModelProvider[RoomListSharedActionViewModel::class.java]
|
||||||
views.stateView.contentView = views.groupListView
|
views.stateView.contentView = views.groupListView
|
||||||
setupSpaceController()
|
setupSpaceController()
|
||||||
enableDragAndDrop()
|
enableDragAndDrop()
|
||||||
|
@ -121,10 +125,10 @@ class SpaceListFragment @Inject constructor(
|
||||||
|
|
||||||
private fun observeViewEvents() = viewModel.observeViewEvents {
|
private fun observeViewEvents() = viewModel.observeViewEvents {
|
||||||
when (it) {
|
when (it) {
|
||||||
is SpaceListViewEvents.OpenSpaceSummary -> sharedActionViewModel.post(HomeActivitySharedAction.OpenSpacePreview(it.id))
|
is SpaceListViewEvents.OpenSpaceSummary -> homeActivitySharedActionViewModel.post(HomeActivitySharedAction.OpenSpacePreview(it.id))
|
||||||
is SpaceListViewEvents.AddSpace -> sharedActionViewModel.post(HomeActivitySharedAction.AddSpace)
|
is SpaceListViewEvents.AddSpace -> homeActivitySharedActionViewModel.post(HomeActivitySharedAction.AddSpace)
|
||||||
is SpaceListViewEvents.OpenSpaceInvite -> sharedActionViewModel.post(HomeActivitySharedAction.OpenSpaceInvite(it.id))
|
is SpaceListViewEvents.OpenSpaceInvite -> homeActivitySharedActionViewModel.post(HomeActivitySharedAction.OpenSpaceInvite(it.id))
|
||||||
SpaceListViewEvents.CloseDrawer -> sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer)
|
SpaceListViewEvents.CloseDrawer -> homeActivitySharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +155,7 @@ class SpaceListFragment @Inject constructor(
|
||||||
|
|
||||||
override fun onSpaceSelected(spaceSummary: RoomSummary?) {
|
override fun onSpaceSelected(spaceSummary: RoomSummary?) {
|
||||||
viewModel.handle(SpaceListAction.SelectSpace(spaceSummary))
|
viewModel.handle(SpaceListAction.SelectSpace(spaceSummary))
|
||||||
|
roomListSharedActionViewModel.post(RoomListSharedAction.CloseBottomSheet)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSpaceInviteSelected(spaceSummary: RoomSummary) {
|
override fun onSpaceInviteSelected(spaceSummary: RoomSummary) {
|
||||||
|
@ -158,7 +163,7 @@ class SpaceListFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSpaceSettings(spaceSummary: RoomSummary) {
|
override fun onSpaceSettings(spaceSummary: RoomSummary) {
|
||||||
sharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(spaceSummary.roomId))
|
homeActivitySharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(spaceSummary.roomId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onToggleExpand(spaceSummary: RoomSummary) {
|
override fun onToggleExpand(spaceSummary: RoomSummary) {
|
||||||
|
@ -170,6 +175,6 @@ class SpaceListFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendFeedBack() {
|
override fun sendFeedBack() {
|
||||||
sharedActionViewModel.post(HomeActivitySharedAction.SendSpaceFeedBack)
|
homeActivitySharedActionViewModel.post(HomeActivitySharedAction.SendSpaceFeedBack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue