mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-01 19:56:47 +01:00
Support notification tab with unified overview
Closes https://github.com/SchildiChat/SchildiChat-android/issues/27. Change-Id: I828f522264aa8a3cae2becfe52805320235002dd
This commit is contained in:
parent
ed2ed5bef4
commit
6624bd4bad
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -33,12 +33,6 @@ class VectorSettingsLabsFragment @Inject constructor(
|
||||
override fun bindPref() {
|
||||
// Lab
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB)?.let {
|
||||
if (vectorPreferences.singleOverview()) {
|
||||
it.parent?.removePreference(it)
|
||||
}
|
||||
}
|
||||
|
||||
val systemDarkThemePreTenPref = findPreference<VectorSwitchPreference>(ThemeUtils.SYSTEM_DARK_THEME_PRE_TEN)
|
||||
systemDarkThemePreTenPref?.let {
|
||||
if (ThemeUtils.darkThemeDefinitivelyPossible()) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,12 @@
|
||||
android:icon="@drawable/ic_home_bottom_group"
|
||||
android:title="@string/bottom_action_rooms" />
|
||||
|
||||
<item
|
||||
android:id="@+id/bottom_action_all"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_home_bottom_chat"
|
||||
android:title="@string/bottom_action_all" />
|
||||
|
||||
<item
|
||||
android:id="@+id/bottom_action_notification"
|
||||
android:enabled="true"
|
||||
|
Loading…
x
Reference in New Issue
Block a user