mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-18 07:11:58 +03:00
Adds new app layout enabled feature flag
This commit is contained in:
parent
069c0c7cb4
commit
fbd1763dcf
7 changed files with 38 additions and 7 deletions
|
@ -31,6 +31,7 @@ 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")
|
||||
|
||||
|
@ -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 ->
|
||||
|
|
|
@ -46,6 +46,9 @@ 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) {
|
||||
|
@ -57,5 +60,6 @@ class DebugPrivateSettingsFragment : VectorBaseFragment<FragmentDebugPrivateSett
|
|||
viewModel.handle(DebugPrivateSettingsViewActions.SetAvatarCapabilityOverride(option))
|
||||
}
|
||||
views.forceLoginFallback.isChecked = it.forceLoginFallback
|
||||
views.newAppLayoutEnabled.isChecked = it.newAppLayoutEnabled
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ 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
|
||||
}
|
||||
|
|
|
@ -47,22 +47,21 @@ 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),
|
||||
)
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +69,7 @@ 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,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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -49,6 +49,12 @@
|
|||
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>
|
||||
|
|
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.flowOf
|
|||
interface VectorOverrides {
|
||||
val forceDialPad: Flow<Boolean>
|
||||
val forceLoginFallback: Flow<Boolean>
|
||||
val newAppLayoutEnabled: Flow<Boolean>
|
||||
val forceHomeserverCapabilities: Flow<HomeserverCapabilitiesOverride>?
|
||||
}
|
||||
|
||||
|
@ -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<HomeserverCapabilitiesOverride>? = null
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue