Skip to content

Commit

Permalink
Cherry pick fix for FAB not showing correctly without bottom navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdecanini committed Aug 16, 2022
1 parent 2249a4d commit 6ff80d2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -187,7 +216,6 @@ class NewHomeDetailFragment @Inject constructor(

override fun onResume() {
super.onResume()
updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab())
callManager.checkForProtocolsSupportIfNeeded()
refreshSpaceState()
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
* ========================================================================================== */
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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 -> {
Expand Down Expand Up @@ -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
}
Expand Down
52 changes: 40 additions & 12 deletions vector/src/main/res/layout/fragment_new_home_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,52 @@

</com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
<androidx.fragment.app.FragmentContainerView
android:id="@+id/roomListContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/roomListContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newLayoutOpenSpacesButton"
style="@style/Widget.Vector.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:accessibilityTraversalAfter="@id/newLayoutCreateChatButton"
android:contentDescription="@string/a11y_open_spaces"
android:src="@drawable/ic_open_spaces"
android:visibility="visible"
app:backgroundTint="?attr/vctr_toolbar_background"
app:fabSize="mini"
app:layout_constraintBottom_toTopOf="@id/newLayoutCreateChatButton"
app:layout_constraintEnd_toEndOf="@id/newLayoutCreateChatButton"
app:layout_constraintStart_toStartOf="@id/newLayoutCreateChatButton"
app:tint="?attr/colorPrimary"
tools:targetApi="lollipop_mr1"
tools:visibility="visible" />


<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newLayoutCreateChatButton"
style="@style/Widget.Vector.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:accessibilityTraversalBefore="@id/roomListView"
android:contentDescription="@string/a11y_create_message"
android:src="@drawable/ic_new_chat"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/home_bottom_navigation" />
app:layout_constraintEnd_toEndOf="parent"
tools:targetApi="lollipop_mr1"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
43 changes: 0 additions & 43 deletions vector/src/main/res/layout/fragment_room_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,6 @@
tools:layout_marginEnd="144dp"
tools:visibility="visible" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newLayoutOpenSpacesButton"
style="@style/Widget.Vector.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:accessibilityTraversalAfter="@id/newLayoutCreateChatButton"
android:contentDescription="@string/a11y_open_spaces"
android:src="@drawable/ic_open_spaces"
android:visibility="gone"
app:backgroundTint="?attr/vctr_toolbar_background"
app:fabSize="mini"
app:layout_constraintBottom_toTopOf="@id/newLayoutCreateChatButton"
app:layout_constraintEnd_toEndOf="@id/newLayoutCreateChatButton"
app:layout_constraintStart_toStartOf="@id/newLayoutCreateChatButton"
app:tint="?attr/colorPrimary"
tools:targetApi="lollipop_mr1"
tools:visibility="visible" />


<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/newLayoutCreateChatButton"
style="@style/Widget.Vector.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:accessibilityTraversalBefore="@id/roomListView"
android:contentDescription="@string/a11y_create_message"
android:src="@drawable/ic_new_chat"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:targetApi="lollipop_mr1"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>

</im.vector.app.core.platform.StateView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit 6ff80d2

Please sign in to comment.