Skip to content

Commit 835de98

Browse files
authored
test: Add UI and logic to evaluate boolean flags (#305)
## Summary Introduced a text field and button in CustomerApiButtons to input and evaluate a boolean flag key. Added evaluateBooleanFlag method in ViewModel to fetch the flag value and display the result using a Toast message. ## How did you test this change? No tests needed ## Are there any deployment considerations? No <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds UI and logic to input a flag key and evaluate a boolean flag via LDClient, showing the result in a Toast. > > - **Android UI (Compose)**: > - In `CustomerApiButtons`, add `OutlinedTextField` for `flagKey` input and a button to evaluate it via `viewModel.evaluateBooleanFlag`. > - **ViewModel**: > - Add `evaluateBooleanFlag(flagKey)` that uses `LDClient.boolVariation` and displays the result with a `Toast`; validates non-empty key. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a3d020f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6700858 commit 835de98

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

e2e/android/app/src/main/java/com/example/androidobservability/MainActivity.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import androidx.compose.foundation.layout.Arrangement
1818
import androidx.compose.foundation.rememberScrollState
1919
import androidx.compose.foundation.verticalScroll
2020
import androidx.compose.material3.Button
21-
import androidx.compose.material3.ButtonDefaults
2221
import androidx.compose.material3.OutlinedTextField
2322
import androidx.compose.material3.Scaffold
2423
import androidx.compose.material3.Text
@@ -197,7 +196,6 @@ private fun MaskingButtons() {
197196
val context = LocalContext.current
198197

199198

200-
201199
// Three-column layout: Name | XML | Compose
202200
// User Form
203201
Row(
@@ -322,6 +320,7 @@ private fun MaskingButtons() {
322320
private fun CustomerApiButtons(viewModel: ViewModel) {
323321
var customLogText by remember { mutableStateOf("") }
324322
var customSpanText by remember { mutableStateOf("") }
323+
var flagKey by remember { mutableStateOf("") }
325324
var customContextKey by remember { mutableStateOf("") }
326325

327326
Text(
@@ -386,6 +385,23 @@ private fun CustomerApiButtons(viewModel: ViewModel) {
386385

387386
Spacer(modifier = Modifier.height(16.dp))
388387

388+
OutlinedTextField(
389+
value = flagKey,
390+
onValueChange = { flagKey = it },
391+
label = { Text("Flag key") },
392+
modifier = Modifier.padding(8.dp)
393+
)
394+
Button(
395+
onClick = {
396+
viewModel.evaluateBooleanFlag(flagKey)
397+
},
398+
modifier = Modifier.padding(8.dp)
399+
) {
400+
Text("Evaluate boolean flag")
401+
}
402+
403+
Spacer(modifier = Modifier.height(16.dp))
404+
389405
OutlinedTextField(
390406
value = customContextKey,
391407
onValueChange = { customContextKey = it },

e2e/android/app/src/main/java/com/example/androidobservability/ViewModel.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.example.androidobservability
22

33
import android.app.Application
44
import android.content.Intent
5+
import android.widget.Toast
56
import androidx.core.content.ContextCompat
67
import androidx.lifecycle.AndroidViewModel
78
import androidx.lifecycle.viewModelScope
@@ -124,6 +125,15 @@ class ViewModel(application: Application) : AndroidViewModel(application) {
124125
LDClient.get().identify(context)
125126
}
126127

128+
fun evaluateBooleanFlag(flagKey: String) {
129+
if (flagKey.isNotEmpty()) {
130+
val result = LDClient.get().boolVariation(flagKey, false)
131+
Toast.makeText(getApplication(), "Flag $flagKey: $result", Toast.LENGTH_SHORT).show()
132+
} else {
133+
Toast.makeText(getApplication(), "Flag key cannot be empty", Toast.LENGTH_SHORT).show()
134+
}
135+
}
136+
127137
fun startForegroundService() {
128138
val intent = Intent(getApplication(), ObservabilityForegroundService::class.java)
129139
ContextCompat.startForegroundService(getApplication(), intent)

0 commit comments

Comments
 (0)