Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sample/android-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckoutVariant>())
ConfigValues(localProvider = localProvider)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,7 @@ public fun FeaturedSample(
Column(
modifier =
modifier
.statusBarsPadding()
.padding(16.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(16.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading