diff --git a/sample/android-app/build.gradle.kts b/sample/android-app/build.gradle.kts index dc3e224..3f4c463 100644 --- a/sample/android-app/build.gradle.kts +++ b/sample/android-app/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation(project(":sample:shared")) implementation(project(":featured-debug-ui")) implementation(project(":featured-platform")) + implementation(project(":providers:datastore")) implementation(libs.androidx.activity.compose) implementation(libs.androidx.appcompat) } diff --git a/sample/android-app/src/main/kotlin/dev/androidbroadcast/featured/sample/MainActivity.kt b/sample/android-app/src/main/kotlin/dev/androidbroadcast/featured/sample/MainActivity.kt index e9f0813..7156e6b 100644 --- a/sample/android-app/src/main/kotlin/dev/androidbroadcast/featured/sample/MainActivity.kt +++ b/sample/android-app/src/main/kotlin/dev/androidbroadcast/featured/sample/MainActivity.kt @@ -9,17 +9,30 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import dev.androidbroadcast.featured.CheckoutVariant import dev.androidbroadcast.featured.ConfigValues import dev.androidbroadcast.featured.SampleApp +import dev.androidbroadcast.featured.datastore.DataStoreConfigValueProvider +import dev.androidbroadcast.featured.datastore.registerConverter import dev.androidbroadcast.featured.debugui.FeatureFlagsDebugScreen +import dev.androidbroadcast.featured.enumConverter import dev.androidbroadcast.featured.platform.defaultLocalProvider +import dev.androidbroadcast.featured.registerSampleFlags class MainActivity : ComponentActivity() { // ConfigValues is held at Activity scope for this sample. // In production, move to Application or a DI singleton to avoid // recreating (and re-opening) the DataStore file on every rotation. private val configValues by lazy { - ConfigValues(localProvider = defaultLocalProvider(applicationContext)) + // Populate FlagRegistry so FeatureFlagsDebugScreen can discover all flags via FlagRegistry.all(). + registerSampleFlags() + + val localProvider = defaultLocalProvider(applicationContext) + // DataStore only handles primitives natively; register a converter so that the + // enum-typed checkoutVariant flag can be persisted and observed without throwing. + (localProvider as? DataStoreConfigValueProvider) + ?.registerConverter(enumConverter()) + ConfigValues(localProvider = localProvider) } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/FeaturedSample.kt b/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/FeaturedSample.kt index 18399bb..d54e52d 100644 --- a/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/FeaturedSample.kt +++ b/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/FeaturedSample.kt @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card @@ -51,6 +52,7 @@ public fun FeaturedSample( Column( modifier = modifier + .statusBarsPadding() .padding(16.dp) .fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp), diff --git a/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/SampleApp.kt b/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/SampleApp.kt index 56a9cc0..a91be4c 100644 --- a/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/SampleApp.kt +++ b/sample/shared/src/commonMain/kotlin/dev/androidbroadcast/featured/SampleApp.kt @@ -4,6 +4,22 @@ package dev.androidbroadcast.featured import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import dev.androidbroadcast.featured.registry.FlagRegistry + +/** + * Registers all [SampleFeatureFlags] with [FlagRegistry] so that [FeatureFlagsDebugScreen] + * can discover them via [FlagRegistry.all]. Call once on application start before opening + * the debug UI. Duplicate calls are safe — the registry ignores already-registered params. + */ +public fun registerSampleFlags() { + listOf( + SampleFeatureFlags.mainButtonRed, + SampleFeatureFlags.newFeatureSectionEnabled, + SampleFeatureFlags.newCheckout, + SampleFeatureFlags.promoBannerEnabled, + SampleFeatureFlags.checkoutVariant, + ).forEach(FlagRegistry::register) +} /** * Root composable for the sample application.