From 2f408656a7f6d593428836e95918b68c1b14d41e Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 19 Jul 2022 10:43:55 +0200 Subject: [PATCH] Changes vector override to vector feature --- .../features/DebugFeaturesStateFactory.kt | 5 +++++ .../debug/features/DebugVectorFeatures.kt | 4 ++++ .../debug/features/DebugVectorOverrides.kt | 11 ---------- .../settings/DebugPrivateSettingsFragment.kt | 4 ---- .../DebugPrivateSettingsViewActions.kt | 1 - .../settings/DebugPrivateSettingsViewModel.kt | 20 +++++++------------ .../settings/DebugPrivateSettingsViewState.kt | 1 - .../fragment_debug_private_settings.xml | 6 ------ .../app/features/DefaultVectorOverrides.kt | 2 -- .../im/vector/app/features/VectorFeatures.kt | 2 ++ 10 files changed, 18 insertions(+), 38 deletions(-) diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index 9533e93ed1..8fe65bd387 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -80,6 +80,11 @@ class DebugFeaturesStateFactory @Inject constructor( key = DebugFeatureKeys.startDmOnFirstMsg, factory = VectorFeatures::shouldStartDmOnFirstMessage ), + createBooleanFeature( + label = "Enable New App Layout", + key = DebugFeatureKeys.newAppLayoutEnabled, + factory = VectorFeatures::isNewAppLayoutEnabled + ), ) ) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index 1b178b5f48..23aad65653 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -72,6 +72,9 @@ class DebugVectorFeatures( override fun shouldStartDmOnFirstMessage(): Boolean = read(DebugFeatureKeys.startDmOnFirstMsg) ?: vectorFeatures.shouldStartDmOnFirstMessage() + override fun isNewAppLayoutEnabled(): Boolean = read(DebugFeatureKeys.newAppLayoutEnabled) + ?: vectorFeatures.isNewAppLayoutEnabled() + fun override(value: T?, key: Preferences.Key) = updatePreferences { if (value == null) { it.remove(key) @@ -131,4 +134,5 @@ object DebugFeatureKeys { val screenSharing = booleanPreferencesKey("screen-sharing") val forceUsageOfOpusEncoder = booleanPreferencesKey("force-usage-of-opus-encoder") val startDmOnFirstMsg = booleanPreferencesKey("start-dm-on-first-msg") + val newAppLayoutEnabled = booleanPreferencesKey("new-app-layout-enabled") } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorOverrides.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorOverrides.kt index 2729e8bd3a..5e16182f3c 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorOverrides.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorOverrides.kt @@ -31,7 +31,6 @@ import org.matrix.android.sdk.api.extensions.orFalse private val Context.dataStore: DataStore by preferencesDataStore(name = "vector_overrides") private val keyForceDialPadDisplay = booleanPreferencesKey("force_dial_pad_display") private val keyForceLoginFallback = booleanPreferencesKey("force_login_fallback") -private val keyNewAppLayoutEnabled = booleanPreferencesKey("new_app_layout_enabled") private val forceCanChangeDisplayName = booleanPreferencesKey("force_can_change_display_name") private val forceCanChangeAvatar = booleanPreferencesKey("force_can_change_avatar") @@ -45,10 +44,6 @@ class DebugVectorOverrides(private val context: Context) : VectorOverrides { preferences[keyForceLoginFallback].orFalse() } - override val newAppLayoutEnabled = context.dataStore.data.map { preferences -> - preferences[keyNewAppLayoutEnabled].orFalse() - } - override val forceHomeserverCapabilities = context.dataStore.data.map { preferences -> HomeserverCapabilitiesOverride( canChangeDisplayName = preferences[forceCanChangeDisplayName], @@ -68,12 +63,6 @@ class DebugVectorOverrides(private val context: Context) : VectorOverrides { } } - suspend fun setNewAppLayoutEnabled(enabled: Boolean) { - context.dataStore.edit { settings -> - settings[keyNewAppLayoutEnabled] = enabled - } - } - suspend fun setHomeserverCapabilities(block: HomeserverCapabilitiesOverride.() -> HomeserverCapabilitiesOverride) { val capabilitiesOverride = block(forceHomeserverCapabilities.firstOrNull() ?: HomeserverCapabilitiesOverride(null, null)) context.dataStore.edit { settings -> diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt index ec32de9bbd..38253fe7c2 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt @@ -46,9 +46,6 @@ class DebugPrivateSettingsFragment : VectorBaseFragment viewModel.handle(DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled(isChecked)) } - views.newAppLayoutEnabled.setOnCheckedChangeListener { _, isChecked -> - viewModel.handle(DebugPrivateSettingsViewActions.SetNewAppLayoutEnabled(isChecked)) - } } override fun invalidate() = withState(viewModel) { @@ -60,6 +57,5 @@ class DebugPrivateSettingsFragment : VectorBaseFragment handleSetDialPadVisibility(action) is DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled -> handleSetForceLoginFallbackEnabled(action) - is DebugPrivateSettingsViewActions.SetNewAppLayoutEnabled -> handleSetNewAppLayoutEnabled(action) is SetDisplayNameCapabilityOverride -> handleSetDisplayNameCapabilityOverride(action) is SetAvatarCapabilityOverride -> handleSetAvatarCapabilityOverride(action) } @@ -87,12 +87,6 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( } } - private fun handleSetNewAppLayoutEnabled(action: DebugPrivateSettingsViewActions.SetNewAppLayoutEnabled) { - viewModelScope.launch { - debugVectorOverrides.setNewAppLayoutEnabled(action.enabled) - } - } - private fun handleSetDisplayNameCapabilityOverride(action: SetDisplayNameCapabilityOverride) { viewModelScope.launch { val forceDisplayName = action.option.toBoolean() diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt index daa695c6ee..749b11a744 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt @@ -22,7 +22,6 @@ import im.vector.app.features.debug.settings.OverrideDropdownView.OverrideDropdo data class DebugPrivateSettingsViewState( val dialPadVisible: Boolean = false, val forceLoginFallback: Boolean = false, - val newAppLayoutEnabled: Boolean = false, val homeserverCapabilityOverrides: HomeserverCapabilityOverrides = HomeserverCapabilityOverrides() ) : MavericksState diff --git a/vector/src/debug/res/layout/fragment_debug_private_settings.xml b/vector/src/debug/res/layout/fragment_debug_private_settings.xml index 9a5f8e7845..c42ad68dce 100644 --- a/vector/src/debug/res/layout/fragment_debug_private_settings.xml +++ b/vector/src/debug/res/layout/fragment_debug_private_settings.xml @@ -49,12 +49,6 @@ android:layout_marginEnd="16dp" android:layout_marginBottom="4dp" /> - - diff --git a/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt b/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt index 3b7f13b2ac..daa0d9e0bd 100644 --- a/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt +++ b/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt @@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.flowOf interface VectorOverrides { val forceDialPad: Flow val forceLoginFallback: Flow - val newAppLayoutEnabled: Flow val forceHomeserverCapabilities: Flow? } @@ -34,6 +33,5 @@ data class HomeserverCapabilitiesOverride( class DefaultVectorOverrides : VectorOverrides { override val forceDialPad = flowOf(false) override val forceLoginFallback = flowOf(false) - override val newAppLayoutEnabled = flowOf(false) override val forceHomeserverCapabilities: Flow? = null } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index eaacb0498e..b48fb62a3a 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -32,6 +32,7 @@ interface VectorFeatures { fun isScreenSharingEnabled(): Boolean fun forceUsageOfOpusEncoder(): Boolean fun shouldStartDmOnFirstMessage(): Boolean + fun isNewAppLayoutEnabled(): Boolean enum class OnboardingVariant { LEGACY, @@ -52,4 +53,5 @@ class DefaultVectorFeatures : VectorFeatures { override fun isScreenSharingEnabled(): Boolean = true override fun forceUsageOfOpusEncoder(): Boolean = false override fun shouldStartDmOnFirstMessage(): Boolean = false + override fun isNewAppLayoutEnabled(): Boolean = false }