Skip to content

Commit 70a892d

Browse files
committed
Revert sample app changes
Signed-off-by: penguindan <[email protected]>
1 parent 2305056 commit 70a892d

File tree

2 files changed

+26
-74
lines changed

2 files changed

+26
-74
lines changed

sampleapp/src/main/kotlin/dev/openfeature/kotlin/sdk/sampleapp/ExampleProvider.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
package dev.openfeature.kotlin.sdk.sampleapp
22

33
import dev.openfeature.kotlin.sdk.*
4-
import dev.openfeature.kotlin.sdk.events.OpenFeatureProviderEvents
5-
import dev.openfeature.kotlin.sdk.exceptions.ErrorCode
64
import kotlinx.coroutines.delay
7-
import kotlinx.coroutines.flow.Flow
8-
import kotlinx.coroutines.flow.MutableSharedFlow
9-
import kotlinx.coroutines.flow.asSharedFlow
105

11-
class ExampleProvider(
12-
providerName: String,
13-
private val flags: Map<String, Any>,
14-
override val hooks: List<Hook<*>> = listOf()
15-
) : FeatureProvider {
6+
class ExampleProvider(override val hooks: List<Hook<*>> = listOf()) : FeatureProvider {
7+
168
private var currentContext: EvaluationContext? = ImmutableContext()
179
var delayTime = 1000L
1810
var returnDefaults = false
19-
private val eventFlow = MutableSharedFlow<OpenFeatureProviderEvents>()
20-
21-
override val metadata: ProviderMetadata = object : ProviderMetadata {
22-
override val name: String = providerName
11+
val flags = mutableMapOf<String, Any>().apply {
12+
put("booleanFlag", true)
13+
put("stringFlag", "this is a string")
14+
put("intFlag", 1337)
15+
put("doubleFlag", 42.0)
16+
put(
17+
"objectFlag",
18+
Value.Structure(mapOf("key1" to Value.String("value"), "key2" to Value.Integer(10)))
19+
)
2320
}
2421

22+
override val metadata: ProviderMetadata
23+
get() = object : ProviderMetadata {
24+
override val name: String = "ExampleProvider"
25+
}
26+
2527
override suspend fun initialize(initialContext: EvaluationContext?) {
2628
currentContext = initialContext
2729
// Simulate a delay in the provider initialization
2830
delay(delayTime)
29-
eventFlow.emit(OpenFeatureProviderEvents.ProviderReady)
3031
}
3132

3233
override fun shutdown() {
3334

3435
}
3536

36-
override fun observe(): Flow<OpenFeatureProviderEvents> = eventFlow.asSharedFlow()
37-
3837
override suspend fun onContextSet(
3938
oldContext: EvaluationContext?,
4039
newContext: EvaluationContext
@@ -86,7 +85,7 @@ class ExampleProvider(
8685
} else if (containsKey(key)) {
8786
ProviderEvaluation(defaultValue, null, reason = "invalid type")
8887
} else {
89-
ProviderEvaluation(defaultValue, null, reason = "notfound", errorCode = ErrorCode.FLAG_NOT_FOUND)
88+
ProviderEvaluation(defaultValue, null, reason = "notfound")
9089
}
9190
}
9291
}

sampleapp/src/main/kotlin/dev/openfeature/kotlin/sdk/sampleapp/MainActivity.kt

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,69 +43,38 @@ import dev.openfeature.kotlin.sdk.ImmutableContext
4343
import dev.openfeature.kotlin.sdk.OpenFeatureAPI
4444
import dev.openfeature.kotlin.sdk.OpenFeatureStatus
4545
import dev.openfeature.kotlin.sdk.Value
46-
import dev.openfeature.kotlin.sdk.multiprovider.MultiProvider
4746
import dev.openfeature.kotlin.sdk.sampleapp.ui.theme.OpenFeatureTheme
48-
import kotlinx.coroutines.Dispatchers
4947
import kotlinx.coroutines.flow.Flow
50-
import kotlinx.coroutines.flow.flowOf
48+
import kotlinx.coroutines.flow.emptyFlow
5149
import kotlinx.coroutines.flow.map
5250
import kotlinx.coroutines.launch
5351
import kotlin.random.Random
5452

5553
class MainActivity : ComponentActivity() {
56-
private val exampleProvider1 = ExampleProvider(
57-
"ExampleProvider1",
58-
flags = mapOf(
59-
"stringFlag" to "this is a string",
60-
"intFlag" to 1337,
61-
"doubleFlag" to 42.0
62-
)
63-
)
64-
private val exampleProvider2 = ExampleProvider(
65-
"ExampleProvider2",
66-
flags = mapOf(
67-
"booleanFlag" to true,
68-
"objectFlag" to Value.Structure(
69-
mapOf("key1" to Value.String("value"), "key2" to Value.Integer(10))
70-
)
71-
)
72-
)
54+
private val exampleProvider = ExampleProvider()
7355

7456
override fun onCreate(savedInstanceState: Bundle?) {
7557
super.onCreate(savedInstanceState)
76-
77-
val multiProvider = MultiProvider(listOf(exampleProvider1, exampleProvider2))
78-
lifecycleScope.launch(Dispatchers.IO) {
79-
OpenFeatureAPI.setProviderAndWait(multiProvider)
58+
lifecycleScope.launch {
59+
OpenFeatureAPI.setProviderAndWait(exampleProvider)
8060
OpenFeatureAPI.statusFlow.collect {
8161
Log.i("OpenFeature", "Status: $it")
8262
}
8363
}
84-
8564
val statusFlow = OpenFeatureAPI.statusFlow.map {
8665
if (it is OpenFeatureStatus.Error) {
8766
"Error: ${it.error.errorCode()} - ${it.error.message}"
8867
} else it.javaClass.simpleName
8968
}
90-
91-
val multiProviderEventFlow = multiProvider.statusFlow.map {
92-
it.javaClass.simpleName
93-
}
94-
9569
setContent {
9670
OpenFeatureTheme {
9771
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
9872
MainPage(
9973
modifier = Modifier.padding(innerPadding),
100-
setDelay = {
101-
exampleProvider1.delayTime = it
102-
exampleProvider2.delayTime = it
103-
},
74+
setDelay = { exampleProvider.delayTime = it },
10475
statusFlow = statusFlow,
105-
multiProviderStatusFlow = multiProviderEventFlow,
10676
toggleDefaults = {
107-
exampleProvider1.returnDefaults = !exampleProvider1.returnDefaults
108-
exampleProvider2.returnDefaults = !exampleProvider2.returnDefaults
77+
exampleProvider.returnDefaults = !exampleProvider.returnDefaults
10978
}
11079
)
11180
}
@@ -119,7 +88,6 @@ fun MainPage(
11988
modifier: Modifier = Modifier,
12089
setDelay: (Long) -> Unit,
12190
statusFlow: Flow<String>,
122-
multiProviderStatusFlow: Flow<String>,
12391
defaultTab: Int = 0,
12492
toggleDefaults: () -> Unit
12593
) {
@@ -153,11 +121,7 @@ fun MainPage(
153121

154122
// Content for the currently selected tab
155123
when (selectedTabIndex) {
156-
0 -> ProviderAndStatus(
157-
setDelay = setDelay,
158-
statusFlow = statusFlow,
159-
multiProviderStatusFlow = multiProviderStatusFlow,
160-
)
124+
0 -> ProviderAndStatus(setDelay = setDelay, statusFlow = statusFlow)
161125
1 -> Evaluations(toggleDefaults = toggleDefaults)
162126
2 -> Hooks()
163127
}
@@ -221,14 +185,8 @@ fun Evaluations(toggleDefaults: () -> Unit) {
221185
}
222186

223187
@Composable
224-
fun ProviderAndStatus(
225-
statusFlow: Flow<String>,
226-
multiProviderStatusFlow: Flow<String>,
227-
setDelay: (Long) -> Unit,
228-
) {
188+
fun ProviderAndStatus(statusFlow: Flow<String>, setDelay: (Long) -> Unit) {
229189
val statusState by statusFlow.collectAsState(initial = "initial")
230-
val multiProviderState by multiProviderStatusFlow.collectAsState(initial = "initial")
231-
232190
val coroutineScope = rememberCoroutineScope()
233191
Column(modifier = Modifier.fillMaxSize()) {
234192
var sliderValue by remember { mutableStateOf(0.1f) }
@@ -290,10 +248,6 @@ fun ProviderAndStatus(
290248
Row(Modifier.padding(top = 8.dp)) {
291249
Text(text = "Current SDK status: $statusState")
292250
}
293-
294-
Row(Modifier.padding(top = 8.dp)) {
295-
Text(text = "MultiProvider Latest event: $multiProviderState")
296-
}
297251
}
298252
}
299253

@@ -369,8 +323,7 @@ fun MainPagePreview() {
369323
OpenFeatureTheme {
370324
MainPage(
371325
setDelay = { },
372-
statusFlow = flowOf("initial"),
373-
multiProviderStatusFlow = flowOf("initial"),
326+
statusFlow = emptyFlow(),
374327
defaultTab = 0,
375328
toggleDefaults = { }
376329
)

0 commit comments

Comments
 (0)