Home: fix double tab selection

This commit is contained in:
ganfra 2019-12-27 17:16:30 +01:00
parent 037bf45884
commit 8109262cbb
1 changed files with 12 additions and 7 deletions

View File

@ -66,6 +66,11 @@ class HomeDetailFragment @Inject constructor(
setupToolbar()
setupKeysBackupBanner()
withState(viewModel) {
// Update the navigation view if needed (for when we restore the tabs)
bottomNavigationView.selectedItemId = it.displayMode.toMenuId()
}
viewModel.selectSubscribe(this, HomeDetailViewState::groupSummary) { groupSummary ->
onGroupChange(groupSummary.orNull())
}
@ -127,7 +132,6 @@ class HomeDetailFragment @Inject constructor(
private fun setupBottomNavigationView() {
bottomNavigationView.setOnNavigationItemSelectedListener {
val displayMode = when (it.itemId) {
R.id.bottom_action_home -> RoomListDisplayMode.HOME
R.id.bottom_action_people -> RoomListDisplayMode.PEOPLE
R.id.bottom_action_rooms -> RoomListDisplayMode.ROOMS
else -> RoomListDisplayMode.HOME
@ -149,12 +153,6 @@ class HomeDetailFragment @Inject constructor(
private fun switchDisplayMode(displayMode: RoomListDisplayMode) {
groupToolbarTitleView.setText(displayMode.titleRes)
updateSelectedFragment(displayMode)
// Update the navigation view (for when we restore the tabs)
bottomNavigationView.selectedItemId = when (displayMode) {
RoomListDisplayMode.PEOPLE -> R.id.bottom_action_people
RoomListDisplayMode.ROOMS -> R.id.bottom_action_rooms
else -> R.id.bottom_action_home
}
}
private fun updateSelectedFragment(displayMode: RoomListDisplayMode) {
@ -194,4 +192,11 @@ class HomeDetailFragment @Inject constructor(
unreadCounterBadgeViews[INDEX_ROOMS].render(UnreadCounterBadgeView.State(it.notificationCountRooms, it.notificationHighlightRooms))
syncStateView.render(it.syncState)
}
private fun RoomListDisplayMode.toMenuId() = when (this) {
RoomListDisplayMode.PEOPLE -> R.id.bottom_action_people
RoomListDisplayMode.ROOMS -> R.id.bottom_action_rooms
else -> R.id.bottom_action_home
}
}