From 6ff80d29dc080c9fe1a10fa44f395c602c16768a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 11 Aug 2022 11:51:01 +0200 Subject: [PATCH] Cherry pick fix for FAB not showing correctly without bottom navigation --- .../features/home/NewHomeDetailFragment.kt | 83 +++++++++---------- .../room/list/home/HomeRoomListFragment.kt | 53 ------------ .../res/layout/fragment_new_home_detail.xml | 52 +++++++++--- .../main/res/layout/fragment_room_list.xml | 43 ---------- 4 files changed, 80 insertions(+), 151 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt index f77efee31fa..bfce033fe12 100644 --- a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt @@ -44,16 +44,22 @@ import im.vector.app.features.call.SharedKnownCallsViewModel import im.vector.app.features.call.VectorCallActivity import im.vector.app.features.call.dialpad.DialPadFragment import im.vector.app.features.call.webrtc.WebRtcCallManager +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.home.room.list.home.HomeRoomListFragment +import im.vector.app.features.home.room.list.home.NewChatBottomSheet import im.vector.app.features.popup.PopupAlertManager import im.vector.app.features.popup.VerificationVectorAlert import im.vector.app.features.settings.VectorLocale import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorSettingsActivity.Companion.EXTRA_DIRECT_ACCESS_SECURITY_PRIVACY_MANAGE_SESSIONS +import im.vector.app.features.spaces.SpaceListBottomSheet import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.workers.signout.BannerState import im.vector.app.features.workers.signout.ServerBackupStatusViewModel import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo @@ -79,9 +85,13 @@ class NewHomeDetailFragment @Inject constructor( private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel() private val serverBackupStatusViewModel: ServerBackupStatusViewModel by activityViewModel() - private lateinit var sharedActionViewModel: HomeSharedActionViewModel + private lateinit var homeSharedActionViewModel: HomeSharedActionViewModel + private lateinit var sharedActionViewModel: RoomListSharedActionViewModel private lateinit var sharedCallActionViewModel: SharedKnownCallsViewModel + private val newChatBottomSheet = NewChatBottomSheet() + private val spaceListBottomSheet = SpaceListBottomSheet() + private var hasUnreadRooms = false set(value) { if (value != field) { @@ -117,17 +127,18 @@ class NewHomeDetailFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) + homeSharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) + sharedActionViewModel = activityViewModelProvider[RoomListSharedActionViewModel::class.java] sharedCallActionViewModel = activityViewModelProvider.get(SharedKnownCallsViewModel::class.java) - setupBottomNavigationView() setupToolbar() setupKeysBackupBanner() setupActiveCallView() + setupFabs() - withState(viewModel) { - // Update the navigation view if needed (for when we restore the tabs) - views.bottomNavigationView.selectedItemId = it.currentTab.toMenuId() - } + sharedActionViewModel + .stream() + .onEach(::handleSharedAction) + .launchIn(viewLifecycleOwner.lifecycleScope) viewModel.onEach(HomeDetailViewState::selectedSpace) { selectedSpace -> onSpaceChange(selectedSpace) @@ -137,10 +148,6 @@ class NewHomeDetailFragment @Inject constructor( updateUIForTab(currentTab) } - viewModel.onEach(HomeDetailViewState::showDialPadTab) { showDialPadTab -> - updateTabVisibilitySafely(R.id.bottom_action_dial_pad, showDialPadTab) - } - viewModel.observeViewEvents { viewEvent -> when (viewEvent) { HomeDetailViewEvents.CallStarted -> handleCallStarted() @@ -174,6 +181,28 @@ class NewHomeDetailFragment @Inject constructor( } } + private fun setupFabs() { + views.newLayoutCreateChatButton.setOnClickListener { + newChatBottomSheet.show(requireActivity().supportFragmentManager, NewChatBottomSheet.TAG) + } + + views.newLayoutOpenSpacesButton.setOnClickListener { + // Click action for open spaces modal goes here + spaceListBottomSheet.show(requireActivity().supportFragmentManager, SpaceListBottomSheet.TAG) + } + } + + private fun handleSharedAction(action: RoomListSharedAction) { + when (action) { + RoomListSharedAction.CloseBottomSheet -> spaceListBottomSheet.dismiss() + } + } + + private fun setCurrentSpace(spaceId: String?) { + spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false) + homeSharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace) + } + private fun handleCallStarted() { dismissLoadingDialog() val fragmentTag = HomeTab.DialPad.toFragmentTag() @@ -187,7 +216,6 @@ class NewHomeDetailFragment @Inject constructor( override fun onResume() { super.onResume() - updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab()) callManager.checkForProtocolsSupportIfNeeded() refreshSpaceState() } @@ -290,22 +318,7 @@ class NewHomeDetailFragment @Inject constructor( } } - private fun setupBottomNavigationView() { - views.bottomNavigationView.menu.findItem(R.id.bottom_action_notification).isVisible = vectorPreferences.labAddNotificationTab() - views.bottomNavigationView.setOnItemSelectedListener { - val tab = when (it.itemId) { - R.id.bottom_action_people -> HomeTab.RoomList(RoomListDisplayMode.PEOPLE) - R.id.bottom_action_rooms -> HomeTab.RoomList(RoomListDisplayMode.ROOMS) - R.id.bottom_action_notification -> HomeTab.RoomList(RoomListDisplayMode.NOTIFICATIONS) - else -> HomeTab.DialPad - } - viewModel.handle(HomeDetailAction.SwitchTab(tab)) - true - } - } - private fun updateUIForTab(tab: HomeTab) { - views.bottomNavigationView.menu.findItem(tab.toMenuId()).isChecked = true updateSelectedFragment(tab) invalidateOptionsMenu() } @@ -351,19 +364,6 @@ class NewHomeDetailFragment @Inject constructor( } } - private fun updateTabVisibilitySafely(tabId: Int, isVisible: Boolean) { - val wasVisible = views.bottomNavigationView.menu.findItem(tabId).isVisible - views.bottomNavigationView.menu.findItem(tabId).isVisible = isVisible - if (wasVisible && !isVisible) { - // As we hide it check if it's not the current item! - withState(viewModel) { - if (it.currentTab.toMenuId() == tabId) { - viewModel.handle(HomeDetailAction.SwitchTab(HomeTab.RoomList(RoomListDisplayMode.PEOPLE))) - } - } - } - } - /* ========================================================================================== * KeysBackupBanner Listener * ========================================================================================== */ @@ -377,9 +377,6 @@ class NewHomeDetailFragment @Inject constructor( } override fun invalidate() = withState(viewModel) { - views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_people).render(it.notificationCountPeople, it.notificationHighlightPeople) - views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_rooms).render(it.notificationCountRooms, it.notificationHighlightRooms) - views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_notification).render(it.notificationCountCatchup, it.notificationHighlightCatchup) views.syncStateView.render( it.syncState, it.incrementalSyncRequestState, diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index 94640338962..0908e9e63ce 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -66,16 +66,11 @@ class HomeRoomListFragment @Inject constructor( private val roomListViewModel: HomeRoomListViewModel by fragmentViewModel() private lateinit var sharedQuickActionsViewModel: RoomListQuickActionsSharedActionViewModel - private lateinit var sharedActionViewModel: RoomListSharedActionViewModel private var concatAdapter = ConcatAdapter() private var modelBuildListener: OnModelBuildFinishedListener? = null - private val spaceListBottomSheet = SpaceListBottomSheet() - private lateinit var stateRestorer: LayoutManagerStateRestorer - private val newChatBottomSheet = NewChatBottomSheet() - override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomListBinding { return FragmentRoomListBinding.inflate(inflater, container, false) } @@ -86,17 +81,11 @@ class HomeRoomListFragment @Inject constructor( 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) @@ -112,12 +101,6 @@ class HomeRoomListFragment @Inject constructor( } } - private fun handleSharedAction(action: RoomListSharedAction) { - when (action) { - RoomListSharedAction.CloseBottomSheet -> spaceListBottomSheet.dismiss() - } - } - private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) { when (quickAction) { is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> { @@ -173,42 +156,6 @@ class HomeRoomListFragment @Inject constructor( }) } - private fun setupFabs() { - showFABs() - - views.newLayoutCreateChatButton.setOnClickListener { - newChatBottomSheet.show(requireActivity().supportFragmentManager, NewChatBottomSheet.TAG) - } - - views.newLayoutOpenSpacesButton.setOnClickListener { - // Click action for open spaces modal goes here - spaceListBottomSheet.show(requireActivity().supportFragmentManager, SpaceListBottomSheet.TAG) - } - - // Hide FABs when list is scrolling - views.roomListView.addOnScrollListener(object : RecyclerView.OnScrollListener() { - override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - views.createChatFabMenu.handler.removeCallbacksAndMessages(null) - - when (newState) { - RecyclerView.SCROLL_STATE_IDLE -> views.createChatFabMenu.postDelayed(::showFABs, 250) - RecyclerView.SCROLL_STATE_DRAGGING, - RecyclerView.SCROLL_STATE_SETTLING -> hideFABs() - } - } - }) - } - - private fun showFABs() { - views.newLayoutCreateChatButton.show() - views.newLayoutOpenSpacesButton.show() - } - - private fun hideFABs() { - views.newLayoutCreateChatButton.hide() - views.newLayoutOpenSpacesButton.hide() - } - override fun invalidate() = withState(roomListViewModel) { state -> views.stateView.state = state.state } diff --git a/vector/src/main/res/layout/fragment_new_home_detail.xml b/vector/src/main/res/layout/fragment_new_home_detail.xml index 8066ab1bd9c..892d068979e 100644 --- a/vector/src/main/res/layout/fragment_new_home_detail.xml +++ b/vector/src/main/res/layout/fragment_new_home_detail.xml @@ -78,24 +78,52 @@ - + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + - + + + + app:layout_constraintEnd_toEndOf="parent" + tools:targetApi="lollipop_mr1" + tools:visibility="visible" /> diff --git a/vector/src/main/res/layout/fragment_room_list.xml b/vector/src/main/res/layout/fragment_room_list.xml index 4b6f8f5895b..19310bdf67f 100644 --- a/vector/src/main/res/layout/fragment_room_list.xml +++ b/vector/src/main/res/layout/fragment_room_list.xml @@ -59,49 +59,6 @@ tools:layout_marginEnd="144dp" tools:visibility="visible" /> - - - - - - - - -