From fbd1763dcface99906b18052c162a313c7ada0f8 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 16:49:42 +0200 Subject: [PATCH 1/3] Adds new app layout enabled feature flag --- .../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 ++ 7 files changed, 38 insertions(+), 7 deletions(-) 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 5e16182f3c..2729e8bd3a 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,6 +31,7 @@ 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") @@ -44,6 +45,10 @@ 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], @@ -63,6 +68,12 @@ 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 38253fe7c2..ec32de9bbd 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,6 +46,9 @@ class DebugPrivateSettingsFragment : VectorBaseFragment viewModel.handle(DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled(isChecked)) } + views.newAppLayoutEnabled.setOnCheckedChangeListener { _, isChecked -> + viewModel.handle(DebugPrivateSettingsViewActions.SetNewAppLayoutEnabled(isChecked)) + } } override fun invalidate() = withState(viewModel) { @@ -57,5 +60,6 @@ class DebugPrivateSettingsFragment : VectorBaseFragment handleSetDialPadVisibility(action) is DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled -> handleSetForceLoginFallbackEnabled(action) + is DebugPrivateSettingsViewActions.SetNewAppLayoutEnabled -> handleSetNewAppLayoutEnabled(action) is SetDisplayNameCapabilityOverride -> handleSetDisplayNameCapabilityOverride(action) is SetAvatarCapabilityOverride -> handleSetAvatarCapabilityOverride(action) } @@ -87,6 +87,12 @@ 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 749b11a744..daa695c6ee 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,6 +22,7 @@ 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 c42ad68dce..9a5f8e7845 100644 --- a/vector/src/debug/res/layout/fragment_debug_private_settings.xml +++ b/vector/src/debug/res/layout/fragment_debug_private_settings.xml @@ -49,6 +49,12 @@ 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 daa0d9e0bd..3b7f13b2ac 100644 --- a/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt +++ b/vector/src/main/java/im/vector/app/features/DefaultVectorOverrides.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.flowOf interface VectorOverrides { val forceDialPad: Flow val forceLoginFallback: Flow + val newAppLayoutEnabled: Flow val forceHomeserverCapabilities: Flow? } @@ -33,5 +34,6 @@ 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 } From b769eafcc305d995e52cd42d33c467f63826f801 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 16:57:54 +0200 Subject: [PATCH 2/3] Adds changelog file --- changelog.d/6584.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6584.misc diff --git a/changelog.d/6584.misc b/changelog.d/6584.misc new file mode 100644 index 0000000000..1b53a8d755 --- /dev/null +++ b/changelog.d/6584.misc @@ -0,0 +1 @@ +Adds NewAppLayoutEnabled feature flag From 2f408656a7f6d593428836e95918b68c1b14d41e Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 19 Jul 2022 10:43:55 +0200 Subject: [PATCH 3/3] 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 }