From dba6784487d6d1326b3ee8b599f4d90909f841d8 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 26 Apr 2021 10:13:33 +0200 Subject: [PATCH] Remove space lab flags --- .../app/features/home/HomeDetailFragment.kt | 16 ++--- .../app/features/home/HomeDrawerFragment.kt | 6 +- .../home/UnreadMessagesSharedViewModel.kt | 68 ++++++++++++------- .../features/settings/VectorPreferences.kt | 14 ---- .../settings/VectorSettingsLabsFragment.kt | 10 +-- vector/src/main/res/values/strings.xml | 3 - .../src/main/res/xml/vector_settings_labs.xml | 7 -- 7 files changed, 50 insertions(+), 74 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 7b989b9bf8..69395b2386 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 @@ -159,16 +159,12 @@ class HomeDetailFragment @Inject constructor( } unreadMessagesSharedViewModel.subscribe { state -> - if (vectorPreferences.labSpaces()) { - views.drawerUnreadCounterBadgeView.render( - UnreadCounterBadgeView.State( - count = state.otherSpacesUnread.totalCount, - highlighted = state.otherSpacesUnread.isHighlight - ) - ) - } else { - views.drawerUnreadCounterBadgeView.isVisible = false - } + views.drawerUnreadCounterBadgeView.render( + UnreadCounterBadgeView.State( + count = state.otherSpacesUnread.totalCount, + highlighted = state.otherSpacesUnread.isHighlight + ) + ) } sharedCallActionViewModel diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt index e935b71604..9ff865b9d1 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt @@ -59,11 +59,7 @@ class HomeDrawerFragment @Inject constructor( sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) if (savedInstanceState == null) { -// if (vectorPreferences.labSpaces()) { - replaceChildFragment(R.id.homeDrawerGroupListContainer, SpaceListFragment::class.java) -// } else { -// replaceChildFragment(R.id.homeDrawerGroupListContainer, GroupListFragment::class.java) -// } + replaceChildFragment(R.id.homeDrawerGroupListContainer, SpaceListFragment::class.java) } session.getUserLive(session.myUserId).observeK(viewLifecycleOwner) { optionalUser -> val user = optionalUser?.getOrNull() diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index ab4e9f4f60..cfafd1f103 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -25,10 +25,10 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.AppStateHandler +import im.vector.app.RoomGroupingMethod import im.vector.app.core.platform.EmptyAction import im.vector.app.core.platform.EmptyViewEvents import im.vector.app.core.platform.VectorViewModel -import im.vector.app.features.settings.VectorPreferences import io.reactivex.Observable import io.reactivex.functions.BiFunction import io.reactivex.schedulers.Schedulers @@ -53,8 +53,7 @@ data class CountInfo( class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initialState: UnreadMessagesState, session: Session, - appStateHandler: AppStateHandler, - private val vectorPreferences: VectorPreferences) + appStateHandler: AppStateHandler) : VectorViewModel(initialState) { @AssistedFactory @@ -119,30 +118,47 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia .throttleFirst(300, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) }, - BiFunction { _, _ -> - val selectedSpace = appStateHandler.safeActiveSpaceId() - val counts = session.getNotificationCountForRooms( - roomSummaryQueryParams { - this.memberships = listOf(Membership.JOIN) - this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) - } - ) - val rootCounts = session.spaceService().getRootSpaceSummaries() - .filter { - // filter out current selection - it.roomId != selectedSpace - } - CountInfo( - homeCount = counts, - otherCount = RoomAggregateNotificationCount( - rootCounts.fold(0, { acc, rs -> - acc + rs.notificationCount - }) + (counts.notificationCount.takeIf { selectedSpace != null } ?: 0), - rootCounts.fold(0, { acc, rs -> - acc + rs.highlightCount - }) + (counts.highlightCount.takeIf { selectedSpace != null } ?: 0) + BiFunction { groupingMethod, _ -> + when (groupingMethod.orNull()) { + is RoomGroupingMethod.ByLegacyGroup -> { + // currently not supported + CountInfo( + RoomAggregateNotificationCount(0, 0), + RoomAggregateNotificationCount(0, 0) ) - ) + } + is RoomGroupingMethod.BySpace -> { + val selectedSpace = appStateHandler.safeActiveSpaceId() + val counts = session.getNotificationCountForRooms( + roomSummaryQueryParams { + this.memberships = listOf(Membership.JOIN) + this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) + } + ) + val rootCounts = session.spaceService().getRootSpaceSummaries() + .filter { + // filter out current selection + it.roomId != selectedSpace + } + CountInfo( + homeCount = counts, + otherCount = RoomAggregateNotificationCount( + rootCounts.fold(0, { acc, rs -> + acc + rs.notificationCount + }) + (counts.notificationCount.takeIf { selectedSpace != null } ?: 0), + rootCounts.fold(0, { acc, rs -> + acc + rs.highlightCount + }) + (counts.highlightCount.takeIf { selectedSpace != null } ?: 0) + ) + ) + } + null -> { + CountInfo( + RoomAggregateNotificationCount(0, 0), + RoomAggregateNotificationCount(0, 0) + ) + } + } } ).execute { copy( 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 b2b609d714..2754d3fab0 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 @@ -20,12 +20,10 @@ import android.media.RingtoneManager import android.net.Uri import android.provider.MediaStore import androidx.core.content.edit -import androidx.lifecycle.LiveData import com.squareup.seismic.ShakeDetector import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.di.DefaultSharedPreferences -import im.vector.app.core.platform.livedata.SharedPreferenceLiveData import im.vector.app.features.disclaimer.SHARED_PREF_KEY import im.vector.app.features.homeserver.ServerUrlsRepository import im.vector.app.features.themes.ThemeUtils @@ -310,18 +308,6 @@ class VectorPreferences @Inject constructor(private val context: Context) { return defaultPrefs.getBoolean(SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB, false) } - fun labSpaces(): Boolean { - return defaultPrefs.getBoolean(SETTINGS_LABS_USE_SPACES, false) - } - - fun labSpacesLive(): LiveData { - return SharedPreferenceLiveData.booleanLiveData( - defaultPrefs, - SETTINGS_LABS_USE_SPACES, - false - ) - } - fun failFast(): Boolean { return BuildConfig.DEBUG || (developerMode() && defaultPrefs.getBoolean(SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY, false)) } 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 cc2ca4eb4d..6a4ea83d68 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 @@ -17,9 +17,6 @@ package im.vector.app.features.settings import im.vector.app.R -import im.vector.app.core.preference.VectorSwitchPreference -import im.vector.app.features.MainActivity -import im.vector.app.features.MainActivityArgs import javax.inject.Inject class VectorSettingsLabsFragment @Inject constructor( @@ -30,11 +27,6 @@ class VectorSettingsLabsFragment @Inject constructor( override val preferenceXmlRes = R.xml.vector_settings_labs override fun bindPref() { - findPreference(VectorPreferences.SETTINGS_LABS_USE_SPACES)!!.let { pref -> - pref.setOnPreferenceChangeListener { _, _ -> - MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = false)) - true - } - } + // Nothing to do } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 46cd57ee5a..0bbf293587 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2198,9 +2198,6 @@ Enable swipe to reply in timeline Add a dedicated tab for unread notifications on main screen. - Spaces prototype - Spaces are the new way to group people and rooms for work, fun or just yourself. You can try them out now on Android, or from your computer. - Link copied to clipboard Add by matrix ID diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index aa55a3c5ec..fef5a2fe9d 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -45,11 +45,4 @@ android:title="@string/labs_show_unread_notifications_as_tab" /> - - - \ No newline at end of file