adding debug feature flag for the splash carousel

This commit is contained in:
Adam Brown 2021-12-13 14:21:00 +00:00
parent 2541c3f6a5
commit 773d335add
3 changed files with 23 additions and 13 deletions

View file

@ -16,8 +16,11 @@
package im.vector.app.features.debug.features
import androidx.datastore.preferences.core.Preferences
import im.vector.app.features.DefaultVectorFeatures
import im.vector.app.features.VectorFeatures
import javax.inject.Inject
import kotlin.reflect.KFunction1
class DebugFeaturesStateFactory @Inject constructor(
private val debugFeatures: DebugVectorFeatures,
@ -31,18 +34,23 @@ class DebugFeaturesStateFactory @Inject constructor(
featureOverride = debugFeatures.onboardingVariant(),
featureDefault = defaultFeatures.onboardingVariant()
),
Feature.BooleanFeature(
createBooleanFeature(
label = "FTUE Splash - I already have an account",
featureOverride = debugFeatures.isAlreadyHaveAccountSplashEnabled().takeIf {
debugFeatures.hasOverride(DebugFeatureKeys.alreadyHaveAnAccount)
},
featureDefault = defaultFeatures.isAlreadyHaveAccountSplashEnabled(),
factory = VectorFeatures::isAlreadyHaveAccountSplashEnabled,
key = DebugFeatureKeys.alreadyHaveAnAccount
)
))
}
private fun createBooleanFeature(key: Preferences.Key<Boolean>, label: String, factory: KFunction1<VectorFeatures, Boolean>): Feature {
return Feature.BooleanFeature(
label = label,
featureOverride = factory.invoke(debugFeatures).takeIf { debugFeatures.hasOverride(key) },
featureDefault = factory.invoke(defaultFeatures),
key = key
)
}
private inline fun <reified T : Enum<T>> createEnumFeature(label: String, featureOverride: T, featureDefault: T): Feature {
return Feature.EnumFeature(
label = label,

View file

@ -43,9 +43,11 @@ class DebugVectorFeatures(
return readPreferences().getEnum<VectorFeatures.OnboardingVariant>() ?: vectorFeatures.onboardingVariant()
}
override fun isAlreadyHaveAccountSplashEnabled(): Boolean = readPreferences()[DebugFeatureKeys.alreadyHaveAnAccount]
override fun isAlreadyHaveAccountSplashEnabled(): Boolean = read(DebugFeatureKeys.alreadyHaveAnAccount)
?: vectorFeatures.isAlreadyHaveAccountSplashEnabled()
override fun isSplashCarouselEnabled(): Boolean = read(DebugFeatureKeys.splashCarousel) ?: vectorFeatures.isSplashCarouselEnabled()
fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences {
if (value == null) {
it.remove(key)
@ -66,6 +68,8 @@ class DebugVectorFeatures(
}
}
private fun read(key: Preferences.Key<Boolean>): Boolean? = readPreferences()[key]
private fun readPreferences() = runBlocking { dataStore.data.first() }
private fun updatePreferences(block: (MutablePreferences) -> Unit) = runBlocking {
@ -92,6 +96,6 @@ private inline fun <reified T : Enum<T>> enumPreferencesKey() = enumPreferencesK
private fun <T : Enum<T>> enumPreferencesKey(type: KClass<T>) = stringPreferencesKey("enum-${type.simpleName}")
object DebugFeatureKeys {
val alreadyHaveAnAccount = booleanPreferencesKey("already-have-an-account")
val splashCarousel = booleanPreferencesKey("splash-carousel")
}

View file

@ -24,19 +24,17 @@ interface VectorFeatures {
fun isAlreadyHaveAccountSplashEnabled(): Boolean
fun isSplashCarouselEnabled(): Boolean
enum class OnboardingVariant {
LEGACY,
LOGIN_2,
FTUE_AUTH
}
enum class NotificationSettingsVersion {
V1,
V2
}
}
class DefaultVectorFeatures : VectorFeatures {
override fun onboardingVariant(): VectorFeatures.OnboardingVariant = BuildConfig.ONBOARDING_VARIANT
override fun isAlreadyHaveAccountSplashEnabled() = true
override fun isSplashCarouselEnabled() = true
}