From f0f7ef4dd8e59f2f0d91dd166b9b0aacca425059 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 6 Aug 2020 17:18:12 +0200 Subject: [PATCH] Make single overview page optional Allow tabbed layout like element --- .../riotx/features/home/HomeDetailFragment.kt | 16 ++++++++++++-- .../home/room/list/RoomListViewModel.kt | 20 ++++++++++++++---- .../home/room/list/RoomListViewState.kt | 7 +++++-- .../features/settings/VectorPreferences.kt | 5 +++++ .../ui/SharedPreferencesUiStateRepository.kt | 21 ++++++++++--------- vector/src/main/res/values-de/strings_sc.xml | 3 +++ vector/src/main/res/values/strings_sc.xml | 3 +++ .../res/xml/vector_settings_preferences.xml | 8 ++++++- 8 files changed, 64 insertions(+), 19 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt index 202f53de5f..351c5895c8 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt @@ -90,8 +90,12 @@ class HomeDetailFragment @Inject constructor( withState(viewModel) { // Update the navigation view if needed (for when we restore the tabs) - //bottomNavigationView.selectedItemId = it.displayMode.toMenuId() - bottomNavigationView.visibility = View.GONE + if (it.displayMode == RoomListDisplayMode.ALL) { + bottomNavigationView.visibility = View.GONE + } else { + bottomNavigationView.selectedItemId = it.displayMode.toMenuId() + bottomNavigationView.visibility = View.VISIBLE + } } viewModel.selectSubscribe(this, HomeDetailViewState::groupSummary) { groupSummary -> @@ -131,6 +135,14 @@ class HomeDetailFragment @Inject constructor( super.onResume() // update notification tab if needed checkNotificationTabStatus() + // Recreate if single-mode overview status changed + withState(viewModel) { + if ((it.displayMode == RoomListDisplayMode.ALL) != vectorPreferences.singleOverview()) { + Timber.i("Restart due to single-overview setting change") + startActivity(activity?.intent) + activity?.finish() + } + } } private fun checkNotificationTabStatus() { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt index 0416038b92..a41fac9a88 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt @@ -30,6 +30,7 @@ import im.vector.matrix.rx.rx import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.utils.DataSource +import im.vector.riotx.features.home.RoomListDisplayMode import io.reactivex.schedulers.Schedulers import timber.log.Timber import javax.inject.Inject @@ -217,6 +218,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState, val favourites = ArrayList() val directChats = ArrayList(rooms.size) val groupRooms = ArrayList(rooms.size) + val normalPriority = ArrayList(rooms.size) val lowPriorities = ArrayList() val serverNotices = ArrayList() @@ -229,15 +231,25 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState, tags.contains(RoomTag.ROOM_TAG_SERVER_NOTICE) -> serverNotices.add(room) tags.contains(RoomTag.ROOM_TAG_FAVOURITE) -> favourites.add(room) tags.contains(RoomTag.ROOM_TAG_LOW_PRIORITY) -> lowPriorities.add(room) - //room.isDirect -> directChats.add(room) - else -> groupRooms.add(room) + room.isDirect -> { + directChats.add(room) + normalPriority.add(room) + } + else -> { + groupRooms.add(room) + normalPriority.add(room) + } } } return RoomSummaries().apply { put(RoomCategory.INVITE, invites) put(RoomCategory.FAVOURITE, favourites) - put(RoomCategory.DIRECT, directChats) - put(RoomCategory.GROUP, groupRooms) + if (displayMode == RoomListDisplayMode.ALL) { + put(RoomCategory.COMBINED, normalPriority) + } else { + put(RoomCategory.DIRECT, directChats) + put(RoomCategory.GROUP, groupRooms) + } put(RoomCategory.LOW_PRIORITY, lowPriorities) put(RoomCategory.SERVER_NOTICE, serverNotices) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewState.kt index 9e6df53f6b..c468390e80 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewState.kt @@ -36,6 +36,7 @@ data class RoomListViewState( val isFavouriteRoomsExpanded: Boolean = true, val isDirectRoomsExpanded: Boolean = true, val isGroupRoomsExpanded: Boolean = true, + val isCombinedRoomsExpanded: Boolean = true, val isLowPriorityRoomsExpanded: Boolean = true, val isServerNoticeRoomsExpanded: Boolean = true ) : MvRxState { @@ -48,6 +49,7 @@ data class RoomListViewState( RoomCategory.FAVOURITE -> isFavouriteRoomsExpanded RoomCategory.DIRECT -> isDirectRoomsExpanded RoomCategory.GROUP -> isGroupRoomsExpanded + RoomCategory.COMBINED -> isCombinedRoomsExpanded RoomCategory.LOW_PRIORITY -> isLowPriorityRoomsExpanded RoomCategory.SERVER_NOTICE -> isServerNoticeRoomsExpanded } @@ -59,6 +61,7 @@ data class RoomListViewState( RoomCategory.FAVOURITE -> copy(isFavouriteRoomsExpanded = !isFavouriteRoomsExpanded) RoomCategory.DIRECT -> copy(isDirectRoomsExpanded = !isDirectRoomsExpanded) RoomCategory.GROUP -> copy(isGroupRoomsExpanded = !isGroupRoomsExpanded) + RoomCategory.COMBINED -> copy(isCombinedRoomsExpanded = !isCombinedRoomsExpanded) RoomCategory.LOW_PRIORITY -> copy(isLowPriorityRoomsExpanded = !isLowPriorityRoomsExpanded) RoomCategory.SERVER_NOTICE -> copy(isServerNoticeRoomsExpanded = !isServerNoticeRoomsExpanded) } @@ -78,8 +81,8 @@ enum class RoomCategory(@StringRes val titleRes: Int) { INVITE(R.string.invitations_header), FAVOURITE(R.string.bottom_action_favourites), DIRECT(R.string.bottom_action_people_x), - //GROUP(R.string.bottom_action_rooms), - GROUP(R.string.normal_priority_header), + GROUP(R.string.bottom_action_rooms), + COMBINED(R.string.normal_priority_header), LOW_PRIORITY(R.string.low_priority_header), SERVER_NOTICE(R.string.system_alerts_header) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index e29d5bb28e..b095a7106b 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -96,6 +96,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { private const val SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY = "SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY" private const val SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY" private const val SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER" + const val SETTINGS_SINGLE_OVERVIEW = "SETTINGS_SINGLE_OVERVIEW" // Help private const val SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY = "SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY" @@ -812,4 +813,8 @@ class VectorPreferences @Inject constructor(private val context: Context) { fun useFlagSecure(): Boolean { return defaultPrefs.getBoolean(SETTINGS_SECURITY_USE_FLAG_SECURE, false) } + + fun singleOverview(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SINGLE_OVERVIEW, true) + } } diff --git a/vector/src/main/java/im/vector/riotx/features/ui/SharedPreferencesUiStateRepository.kt b/vector/src/main/java/im/vector/riotx/features/ui/SharedPreferencesUiStateRepository.kt index 4ce6e10ee3..5fcb6ee716 100644 --- a/vector/src/main/java/im/vector/riotx/features/ui/SharedPreferencesUiStateRepository.kt +++ b/vector/src/main/java/im/vector/riotx/features/ui/SharedPreferencesUiStateRepository.kt @@ -37,18 +37,19 @@ class SharedPreferencesUiStateRepository @Inject constructor( } override fun getDisplayMode(): RoomListDisplayMode { - return RoomListDisplayMode.ALL - /* - return 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 + 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 + } } } - */ } override fun storeDisplayMode(displayMode: RoomListDisplayMode) { diff --git a/vector/src/main/res/values-de/strings_sc.xml b/vector/src/main/res/values-de/strings_sc.xml index b04f55f468..c2a0e4fcb4 100644 --- a/vector/src/main/res/values-de/strings_sc.xml +++ b/vector/src/main/res/values-de/strings_sc.xml @@ -1,6 +1,9 @@ + Vereinte Chat-Übersicht + Zeige sowohl Direktnachrichten als auch Gruppenchats in einer gemeinsamen Übersicht + Nacht-Design SC Hell SC Schwarz diff --git a/vector/src/main/res/values/strings_sc.xml b/vector/src/main/res/values/strings_sc.xml index 242c6a763c..f543326448 100644 --- a/vector/src/main/res/values/strings_sc.xml +++ b/vector/src/main/res/values/strings_sc.xml @@ -1,6 +1,9 @@ + Combined chat overview + View both direct messages and rooms on one page + Night Theme SC Light SC Black diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 5057e116f7..32d8f797e2 100644 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -39,6 +39,12 @@ android:title="@string/bubble_style" app:iconSpaceReserved="false" /> + + - \ No newline at end of file +