From 6624bd4bad8974858fb6e470508f6cdb65d70b88 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 7 Feb 2021 15:03:16 +0100 Subject: [PATCH] Support notification tab with unified overview Closes https://github.com/SchildiChat/SchildiChat-android/issues/27. Change-Id: I828f522264aa8a3cae2becfe52805320235002dd --- .../app/features/home/HomeDetailFragment.kt | 65 +++++++++++++------ .../features/settings/VectorPreferences.kt | 6 +- .../settings/VectorSettingsLabsFragment.kt | 6 -- .../ui/SharedPreferencesUiStateRepository.kt | 31 +++++---- .../main/res/menu/home_bottom_navigation.xml | 6 ++ 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index 1807fa20b2..3326190754 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -21,6 +21,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import androidx.lifecycle.Observer import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel @@ -97,15 +98,7 @@ class HomeDetailFragment @Inject constructor( setupKeysBackupBanner() setupActiveCallView() - withState(viewModel) { - // Update the navigation view if needed (for when we restore the tabs) - if (it.displayMode == RoomListDisplayMode.ALL) { - views.bottomNavigationView.visibility = View.GONE - } else { - views.bottomNavigationView.selectedItemId = it.displayMode.toMenuId() - views.bottomNavigationView.visibility = View.VISIBLE - } - } + loadNavigationView() viewModel.selectSubscribe(this, HomeDetailViewState::groupSummary) { groupSummary -> onGroupChange(groupSummary.orNull()) @@ -140,28 +133,52 @@ class HomeDetailFragment @Inject constructor( }) } - override fun onResume() { - super.onResume() - // update notification tab if needed - checkNotificationTabStatus() - // Recreate if single-mode overview status changed + private fun loadNavigationView() { withState(viewModel) { - if ((it.displayMode == RoomListDisplayMode.ALL) != vectorPreferences.singleOverview()) { - Timber.i("Restart due to single-overview setting change") - startActivity(activity?.intent) - activity?.finish() + // Update the navigation view if needed (for when we restore the tabs) + if (!vectorPreferences.enableOverviewTabs()) { + views.bottomNavigationView.isVisible = false + } else { + views.bottomNavigationView.selectedItemId = it.displayMode.toMenuId() + views.bottomNavigationView.isVisible = true } } } + override fun onResume() { + super.onResume() + // update notification tab if needed + checkNotificationTabStatus() + } + private fun checkNotificationTabStatus() { val wasVisible = views.bottomNavigationView.menu.findItem(R.id.bottom_action_notification).isVisible + val combinedOverview = vectorPreferences.combinedOverview() + val combinedOverviewWasVisible = views.bottomNavigationView.menu.findItem(R.id.bottom_action_all).isVisible views.bottomNavigationView.menu.findItem(R.id.bottom_action_notification).isVisible = vectorPreferences.labAddNotificationTab() + views.bottomNavigationView.menu.findItem(R.id.bottom_action_people).isVisible = !combinedOverview + views.bottomNavigationView.menu.findItem(R.id.bottom_action_rooms).isVisible = !combinedOverview + views.bottomNavigationView.menu.findItem(R.id.bottom_action_all).isVisible = combinedOverview + if (combinedOverviewWasVisible != combinedOverview) { + // As we hide it check if it's not the current item! + withState(viewModel) { + val menuId = it.displayMode.toMenuId() + if (combinedOverview) { + if (menuId == R.id.bottom_action_people || menuId == R.id.bottom_action_rooms) { + viewModel.handle(HomeDetailAction.SwitchDisplayMode(RoomListDisplayMode.ALL)) + } + } else { + if (menuId == R.id.bottom_action_all) { + viewModel.handle(HomeDetailAction.SwitchDisplayMode(RoomListDisplayMode.PEOPLE)) + } + } + } + } if (wasVisible && !vectorPreferences.labAddNotificationTab()) { // As we hide it check if it's not the current item! withState(viewModel) { if (it.displayMode.toMenuId() == R.id.bottom_action_notification) { - if (vectorPreferences.singleOverview()) { + if (combinedOverview) { viewModel.handle(HomeDetailAction.SwitchDisplayMode(RoomListDisplayMode.ALL)) } else { viewModel.handle(HomeDetailAction.SwitchDisplayMode(RoomListDisplayMode.PEOPLE)) @@ -169,6 +186,10 @@ class HomeDetailFragment @Inject constructor( } } } + val wasBottomBarVisible = views.bottomNavigationView.isVisible + if (wasBottomBarVisible != vectorPreferences.enableOverviewTabs()) { + loadNavigationView() + } } private fun promptForNewUnknownDevices(uid: String, state: UnknownDevicesState, newest: DeviceInfo) { @@ -269,7 +290,11 @@ class HomeDetailFragment @Inject constructor( } private fun setupBottomNavigationView() { + val combinedOverview = vectorPreferences.combinedOverview() views.bottomNavigationView.menu.findItem(R.id.bottom_action_notification).isVisible = vectorPreferences.labAddNotificationTab() + views.bottomNavigationView.menu.findItem(R.id.bottom_action_people).isVisible = !combinedOverview + views.bottomNavigationView.menu.findItem(R.id.bottom_action_rooms).isVisible = !combinedOverview + views.bottomNavigationView.menu.findItem(R.id.bottom_action_all).isVisible = combinedOverview views.bottomNavigationView.setOnNavigationItemSelectedListener { val displayMode = when (it.itemId) { R.id.bottom_action_people -> RoomListDisplayMode.PEOPLE @@ -333,6 +358,7 @@ class HomeDetailFragment @Inject constructor( 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.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_all).render(it.notificationCountCatchup, it.notificationHighlightCatchup) views.syncStateView.render(it.syncState) } @@ -351,6 +377,7 @@ class HomeDetailFragment @Inject constructor( private fun RoomListDisplayMode.toMenuId() = when (this) { RoomListDisplayMode.PEOPLE -> R.id.bottom_action_people RoomListDisplayMode.ROOMS -> R.id.bottom_action_rooms + RoomListDisplayMode.ALL -> R.id.bottom_action_all else -> R.id.bottom_action_notification } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 0ec7c2833b..f959f249ab 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -27,7 +27,6 @@ import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.features.disclaimer.SHARED_PREF_KEY import im.vector.app.features.homeserver.ServerUrlsRepository import im.vector.app.features.themes.ThemeUtils -import io.realm.annotations.Ignore import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.room.model.RoomSummary import timber.log.Timber @@ -888,9 +887,12 @@ class VectorPreferences @Inject constructor(private val context: Context) { } // SC addition - fun singleOverview(): Boolean { + fun combinedOverview(): Boolean { return defaultPrefs.getBoolean(SETTINGS_SINGLE_OVERVIEW, true) } + fun enableOverviewTabs(): Boolean { + return labAddNotificationTab() || !combinedOverview() + } // SC addition private fun roomUnreadKind(key: String): Int { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt index 8bd2d47ead..3a85e47733 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt @@ -33,12 +33,6 @@ class VectorSettingsLabsFragment @Inject constructor( override fun bindPref() { // Lab - findPreference(VectorPreferences.SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB)?.let { - if (vectorPreferences.singleOverview()) { - it.parent?.removePreference(it) - } - } - val systemDarkThemePreTenPref = findPreference(ThemeUtils.SYSTEM_DARK_THEME_PRE_TEN) systemDarkThemePreTenPref?.let { if (ThemeUtils.darkThemeDefinitivelyPossible()) { diff --git a/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt b/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt index 9a55455085..4cf45545f2 100644 --- a/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt +++ b/vector/src/main/java/im/vector/app/features/ui/SharedPreferencesUiStateRepository.kt @@ -37,19 +37,26 @@ class SharedPreferencesUiStateRepository @Inject constructor( } override fun getDisplayMode(): RoomListDisplayMode { - return if (vectorPreferences.singleOverview()) { - RoomListDisplayMode.ALL - } else { - when (sharedPreferences.getInt(KEY_DISPLAY_MODE, VALUE_DISPLAY_MODE_CATCHUP)) { - VALUE_DISPLAY_MODE_PEOPLE -> RoomListDisplayMode.PEOPLE - VALUE_DISPLAY_MODE_ROOMS -> RoomListDisplayMode.ROOMS - else -> if (vectorPreferences.labAddNotificationTab()) { - RoomListDisplayMode.NOTIFICATIONS - } else { - RoomListDisplayMode.PEOPLE - } + val result = when (sharedPreferences.getInt(KEY_DISPLAY_MODE, VALUE_DISPLAY_MODE_CATCHUP)) { + VALUE_DISPLAY_MODE_PEOPLE -> RoomListDisplayMode.PEOPLE + VALUE_DISPLAY_MODE_ROOMS -> RoomListDisplayMode.ROOMS + VALUE_DISPLAY_MODE_ALL -> RoomListDisplayMode.ALL + else -> if (vectorPreferences.labAddNotificationTab()) { + RoomListDisplayMode.NOTIFICATIONS + } else { + RoomListDisplayMode.PEOPLE } } + if (vectorPreferences.combinedOverview()) { + if (result == RoomListDisplayMode.PEOPLE || result == RoomListDisplayMode.ROOMS) { + return RoomListDisplayMode.ALL + } + } else { + if (result == RoomListDisplayMode.ALL) { + return RoomListDisplayMode.PEOPLE + } + } + return result } override fun storeDisplayMode(displayMode: RoomListDisplayMode) { @@ -58,6 +65,7 @@ class SharedPreferencesUiStateRepository @Inject constructor( when (displayMode) { RoomListDisplayMode.PEOPLE -> VALUE_DISPLAY_MODE_PEOPLE RoomListDisplayMode.ROOMS -> VALUE_DISPLAY_MODE_ROOMS + RoomListDisplayMode.ALL -> VALUE_DISPLAY_MODE_ALL else -> VALUE_DISPLAY_MODE_CATCHUP }) } @@ -68,5 +76,6 @@ class SharedPreferencesUiStateRepository @Inject constructor( private const val VALUE_DISPLAY_MODE_CATCHUP = 0 private const val VALUE_DISPLAY_MODE_PEOPLE = 1 private const val VALUE_DISPLAY_MODE_ROOMS = 2 + private const val VALUE_DISPLAY_MODE_ALL = 42 } } diff --git a/vector/src/main/res/menu/home_bottom_navigation.xml b/vector/src/main/res/menu/home_bottom_navigation.xml index d52c8afab3..34de70cd93 100644 --- a/vector/src/main/res/menu/home_bottom_navigation.xml +++ b/vector/src/main/res/menu/home_bottom_navigation.xml @@ -13,6 +13,12 @@ android:icon="@drawable/ic_home_bottom_group" android:title="@string/bottom_action_rooms" /> + +