From fbd1763dcface99906b18052c162a313c7ada0f8 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 16:49:42 +0200 Subject: [PATCH] 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 }