Changes vector override to vector feature

This commit is contained in:
ericdecanini 2022-07-19 10:43:55 +02:00
parent b769eafcc3
commit 2f408656a7
10 changed files with 18 additions and 38 deletions

View file

@ -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
),
)
)
}

View file

@ -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 <T> override(value: T?, key: Preferences.Key<T>) = 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")
}

View file

@ -31,7 +31,6 @@ import org.matrix.android.sdk.api.extensions.orFalse
private val Context.dataStore: DataStore<Preferences> 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 ->

View file

@ -46,9 +46,6 @@ class DebugPrivateSettingsFragment : VectorBaseFragment<FragmentDebugPrivateSett
views.forceLoginFallback.setOnCheckedChangeListener { _, isChecked ->
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<FragmentDebugPrivateSett
viewModel.handle(DebugPrivateSettingsViewActions.SetAvatarCapabilityOverride(option))
}
views.forceLoginFallback.isChecked = it.forceLoginFallback
views.newAppLayoutEnabled.isChecked = it.newAppLayoutEnabled
}
}

View file

@ -21,7 +21,6 @@ import im.vector.app.core.platform.VectorViewModelAction
sealed interface DebugPrivateSettingsViewActions : VectorViewModelAction {
data class SetDialPadVisibility(val force: Boolean) : DebugPrivateSettingsViewActions
data class SetForceLoginFallbackEnabled(val force: Boolean) : DebugPrivateSettingsViewActions
data class SetNewAppLayoutEnabled(val enabled: Boolean) : DebugPrivateSettingsViewActions
data class SetDisplayNameCapabilityOverride(val option: BooleanHomeserverCapabilitiesOverride?) : DebugPrivateSettingsViewActions
data class SetAvatarCapabilityOverride(val option: BooleanHomeserverCapabilitiesOverride?) : DebugPrivateSettingsViewActions
}

View file

@ -47,21 +47,22 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor(
private fun observeVectorOverrides() {
debugVectorOverrides.forceDialPad.setOnEach {
copy(dialPadVisible = it)
copy(
dialPadVisible = it
)
}
debugVectorOverrides.forceLoginFallback.setOnEach {
copy(forceLoginFallback = it)
}
debugVectorOverrides.newAppLayoutEnabled.setOnEach {
copy(newAppLayoutEnabled = it)
}
debugVectorOverrides.forceHomeserverCapabilities.setOnEach {
val activeDisplayNameOption = BooleanHomeserverCapabilitiesOverride.from(it.canChangeDisplayName)
val activeAvatarOption = BooleanHomeserverCapabilitiesOverride.from(it.canChangeAvatar)
copy(homeserverCapabilityOverrides = homeserverCapabilityOverrides.copy(
copy(
homeserverCapabilityOverrides = homeserverCapabilityOverrides.copy(
displayName = homeserverCapabilityOverrides.displayName.copy(activeOption = activeDisplayNameOption),
avatar = homeserverCapabilityOverrides.avatar.copy(activeOption = activeAvatarOption),
))
)
)
}
}
@ -69,7 +70,6 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor(
when (action) {
is DebugPrivateSettingsViewActions.SetDialPadVisibility -> 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()

View file

@ -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

View file

@ -49,12 +49,6 @@
android:layout_marginEnd="16dp"
android:layout_marginBottom="4dp" />
<CheckBox
android:id="@+id/newAppLayoutEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable new app layout" />
</LinearLayout>
</ScrollView>

View file

@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.flowOf
interface VectorOverrides {
val forceDialPad: Flow<Boolean>
val forceLoginFallback: Flow<Boolean>
val newAppLayoutEnabled: Flow<Boolean>
val forceHomeserverCapabilities: Flow<HomeserverCapabilitiesOverride>?
}
@ -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<HomeserverCapabilitiesOverride>? = null
}

View file

@ -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
}