diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt new file mode 100644 index 00000000..d875f79a --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt @@ -0,0 +1,103 @@ +package com.example.lambda_bbb_events.data + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.local.LocalDatabase +import com.example.lambda_bbb_events.model.local.SqliteRecentlyViewedStore +import com.example.lambda_bbb_events.model.local.SqliteThemePreferenceStore +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Tests [SqliteThemePreferenceStore] against a real SQLite database held in memory, + * and that upgrading [LocalDatabase] from version 1 keeps recently viewed campsites. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within + * the app. it disapears after app resets. Let's save it into the sqlite3 db we already have." + * - "Please make sure to also document and cite your changes." + * - "And then add a third button to the settings as system settings." + */ +@RunWith(AndroidJUnit4::class) +class ThemePreferenceDatabaseTest { + private val context = ApplicationProvider.getApplicationContext() + private lateinit var database: LocalDatabase + private lateinit var store: SqliteThemePreferenceStore + + @Before + fun setUp() { + database = LocalDatabase(context, name = null) + store = SqliteThemePreferenceStore(database) + } + + @After + fun cleanUp() { + database.close() + } + + @Test + fun nothingSavedFollowsSystem() { + assertNull(store.load()) + } + + @Test + fun savesDarkTheme() { + store.save(true) + + assertTrue(store.load()!!) + } + + @Test + fun laterChoiceReplacesEarlierOne() { + store.save(true) + store.save(false) + + assertFalse(store.load()!!) + } + + @Test + fun choosingSystemClearsSavedChoice() { + store.save(true) + store.save(null) + + assertNull(store.load()) + } + + @Test + fun choiceSurvivesReopeningDatabase() { + val name = "theme_test_${System.nanoTime()}.db" + try { + LocalDatabase(context, name).use { SqliteThemePreferenceStore(it).save(true) } + + LocalDatabase(context, name).use { + assertTrue(SqliteThemePreferenceStore(it).load()!!) + } + } finally { + context.deleteDatabase(name) + } + } + + @Test + fun upgradeFromVersionOneKeepsRecentlyViewed() { + SqliteRecentlyViewedStore(database).record("a", viewedAt = 1L, limit = 10) + val db = database.writableDatabase + db.execSQL("DROP TABLE ${LocalDatabase.SETTINGS_TABLE}") + + database.onUpgrade(db, 1, LocalDatabase.DATABASE_VERSION) + store.save(true) + + assertEquals(listOf("a"), SqliteRecentlyViewedStore(database).load(10)) + assertTrue(store.load()!!) + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt b/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt index f4bd9741..25f08abe 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt @@ -92,14 +92,15 @@ import com.example.lambda_bbb_events.view.ui.user_screens.explore.SeeAllCampsite * Manages application startup such as loading, signup, or main application screens. * * @param controllers Shared application controllers. - * @param darkTheme Whether dark mode is enabled. - * @param onDarkThemeChange Updates the application's theme. + * @param darkTheme The theme the user picked: `true` for dark, `false` for light, + * or `null` to follow Android's setting. + * @param onDarkThemeChange Updates the application's theme with the picked option. */ @Composable fun LambdaEventsApp( controllers: AppControllers, - darkTheme: Boolean, - onDarkThemeChange: (Boolean) -> Unit + darkTheme: Boolean?, + onDarkThemeChange: (Boolean?) -> Unit ) { if (!controllers.users.usersFullyLoaded) { // Shown while checking whether this device already has an account @@ -156,14 +157,15 @@ fun LambdaEventsApp( * Defines routes for browsing, bookings, and account management. * * @param controllers Shared application controllers. - * @param darkTheme Whether dark mode is enabled. - * @param onDarkThemeChange Updates the application's theme. + * @param darkTheme The theme the user picked: `true` for dark, `false` for light, + * or `null` to follow Android's setting. + * @param onDarkThemeChange Updates the application's theme with the picked option. */ @Composable private fun MainApp( controllers: AppControllers, - darkTheme: Boolean, - onDarkThemeChange: (Boolean) -> Unit + darkTheme: Boolean?, + onDarkThemeChange: (Boolean?) -> Unit ) { val navController = rememberNavController() val currentUser = controllers.users.currentUser diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt index 72e93968..946a1b44 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt @@ -32,6 +32,7 @@ import com.example.lambda_bbb_events.controller.NotificationController import com.example.lambda_bbb_events.model.local.LocalDatabase import com.example.lambda_bbb_events.model.local.SharedPreferencesSessionStore import com.example.lambda_bbb_events.model.local.SqliteRecentlyViewedStore +import com.example.lambda_bbb_events.model.local.SqliteThemePreferenceStore import com.example.lambda_bbb_events.model.repository.LotteryRepository import com.example.lambda_bbb_events.model.repository.ReservationRepository import com.example.lambda_bbb_events.model.repository.ReviewRepository @@ -80,6 +81,24 @@ class MainActivity : ComponentActivity() { } } + /** + * Builds the repositories and controllers, then shows the app. + * + * Opens one [LocalDatabase] shared by the recently viewed campsites and the + * saved theme. The theme the user picked in the app (light, dark, or System to + * follow Android) is loaded from it before the first frame, and saved to it in + * the background whenever they change it. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Changed with the help of this AI tool (saving the theme choice, System option). + * Prompts: + * - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within + * the app. it disapears after app resets. Let's save it into the sqlite3 db we already have." + * - "Please make sure to also document and cite your changes." + * - "And then add a third button to the settings as system settings." + */ @SuppressLint("HardwareIds") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -104,6 +123,9 @@ class MainActivity : ComponentActivity() { val waitlistEntryRepository = WaitlistEntryRepository() val reviewRepository = ReviewRepository() val imageProcessor = ImageProcessor() + val localDatabase = LocalDatabase(applicationContext) + val themePreferenceStore = SqliteThemePreferenceStore(localDatabase) + val savedDarkTheme = themePreferenceStore.load() val userController = UserController(userRepository, deviceId,SharedPreferencesSessionStore(applicationContext)) val notifications = NotificationController(applicationContext,userController) notifications.createNotificationChannel() @@ -121,9 +143,7 @@ class MainActivity : ComponentActivity() { users = userController, campsites = CampsiteController( campsiteStore, - SqliteRecentlyViewedStore( - LocalDatabase(applicationContext) - ), + SqliteRecentlyViewedStore(localDatabase), lotteriesForCampsite = lotteryRepository::getLotteriesForCampsite ), lotteries = LotteryController(lotteryRepository), @@ -244,10 +264,11 @@ class MainActivity : ComponentActivity() { // Follow Android's dark mode setting, unless the // user picked a theme in the app. - // Only their choice is saved, so changing Android's - // setting still takes effect. + // Only their choice is saved (in the local SQLite + // database), so changing Android's setting still + // takes effect until they pick one. var chosenDarkTheme by rememberSaveable { - mutableStateOf(null) + mutableStateOf(savedDarkTheme) } val darkTheme = @@ -276,9 +297,12 @@ class MainActivity : ComponentActivity() { ) { LambdaEventsApp( controllers = controllers, - darkTheme = darkTheme, - onDarkThemeChange = { - chosenDarkTheme = it + darkTheme = chosenDarkTheme, + onDarkThemeChange = { choice -> + chosenDarkTheme = choice + lifecycleScope.launch(Dispatchers.IO) { + themePreferenceStore.save(choice) + } } ) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt index 17d2c8ff..31335145 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt @@ -64,8 +64,22 @@ class InMemoryRecentlyViewedStore : RecentlyViewedStore { /** * The app's local SQLite database on this device. * + * Tables: + * - [RECENTLY_VIEWED_TABLE]: campsites viewed on this device, used by [SqliteRecentlyViewedStore]. + * - [SETTINGS_TABLE]: device settings as key-value pairs, such as the theme saved by + * [SqliteThemePreferenceStore]. Added in version 2. + * * @param context The application context. * @param name The database file name, or `null` for a database held in memory. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Changed with the help of this AI tool (settings table, version 2 upgrade). + * Prompts: + * - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within + * the app. it disapears after app resets. Let's save it into the sqlite3 db we already have." + * - "Please make sure to also document and cite your changes." */ class LocalDatabase( context: Context, @@ -74,11 +88,15 @@ class LocalDatabase( companion object { const val DATABASE_NAME = "lambda_local.db" - const val DATABASE_VERSION = 1 + const val DATABASE_VERSION = 2 const val RECENTLY_VIEWED_TABLE = "recently_viewed" const val COLUMN_CAMPSITE_ID = "campsite_id" const val COLUMN_VIEWED_AT = "viewed_at" + + const val SETTINGS_TABLE = "settings" + const val COLUMN_KEY = "key" + const val COLUMN_VALUE = "value" } override fun onCreate(db: SQLiteDatabase) { @@ -90,11 +108,33 @@ class LocalDatabase( ) """.trimIndent() ) + createSettingsTable(db) } + /** + * Adds the settings table to databases made before version 2, + * keeping the recently viewed campsites already saved. + */ override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { - db.execSQL("DROP TABLE IF EXISTS $RECENTLY_VIEWED_TABLE") - onCreate(db) + if (oldVersion < 2) { + createSettingsTable(db) + } + } + + /** + * Creates the table of device settings, one value per key. + * + * @param db The database to create the table in. + */ + private fun createSettingsTable(db: SQLiteDatabase) { + db.execSQL( + """ + CREATE TABLE IF NOT EXISTS $SETTINGS_TABLE ( + $COLUMN_KEY TEXT PRIMARY KEY NOT NULL, + $COLUMN_VALUE TEXT NOT NULL + ) + """.trimIndent() + ) } } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt new file mode 100644 index 00000000..8f48fcd4 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt @@ -0,0 +1,98 @@ +package com.example.lambda_bbb_events.model.local + +import android.content.ContentValues +import android.database.sqlite.SQLiteDatabase + +/** + * Saves the theme the user picked in the app in the [LocalDatabase], + * so it survives app restarts. + * + * When nothing is saved, the app follows Android's dark mode setting. + * The choice is one row in the [LocalDatabase.SETTINGS_TABLE], stored as + * "dark" or "light" under [DARK_THEME_KEY]. + * + * Calls read and write the disk. [load] is one small query, made once at + * startup so the first frame already uses the saved theme; [save] should be + * made off the main thread. + * + * @param database The local database to store the choice in. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within + * the app. it disapears after app resets. Let's save it into the sqlite3 db we already have." + * - "Please make sure to also document and cite your changes." + * - "And then add a third button to the settings as system settings." + */ +class SqliteThemePreferenceStore( + private val database: LocalDatabase +) { + + companion object { + const val DARK_THEME_KEY = "dark_theme" + private const val DARK = "dark" + private const val LIGHT = "light" + } + + /** + * Loads the saved theme choice. + * + * @return `true` for dark mode, `false` for light mode, + * or `null` if the user never picked one. + */ + fun load(): Boolean? { + val cursor = database.readableDatabase.query( + LocalDatabase.SETTINGS_TABLE, + arrayOf(LocalDatabase.COLUMN_VALUE), + "${LocalDatabase.COLUMN_KEY} = ?", + arrayOf(DARK_THEME_KEY), + null, + null, + null + ) + val value = cursor.use { + if (it.moveToFirst()) it.getString(0) else null + } + return when (value) { + DARK -> true + LIGHT -> false + else -> null + } + } + + /** + * Saves the user's theme choice, replacing any earlier choice. + * + * @param darkTheme `true` for dark mode, `false` for light mode, + * or `null` to clear the choice and follow Android's setting again. + */ + fun save(darkTheme: Boolean?) { + if (darkTheme == null) { + clear() + return + } + val values = ContentValues() + values.put(LocalDatabase.COLUMN_KEY, DARK_THEME_KEY) + values.put(LocalDatabase.COLUMN_VALUE, if (darkTheme) DARK else LIGHT) + database.writableDatabase.insertWithOnConflict( + LocalDatabase.SETTINGS_TABLE, + null, + values, + SQLiteDatabase.CONFLICT_REPLACE + ) + } + + /** + * Removes the saved choice, so the app follows Android's setting. + */ + private fun clear() { + database.writableDatabase.delete( + LocalDatabase.SETTINGS_TABLE, + "${LocalDatabase.COLUMN_KEY} = ?", + arrayOf(DARK_THEME_KEY) + ) + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt index c84e0bb3..eb40185f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt @@ -14,11 +14,13 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.semantics.Role +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp /* -Provides togglable button to be re-used throughout the app to switch between two options +Provides togglable buttons to be re-used throughout the app to switch between options */ /** @@ -37,6 +39,39 @@ fun ToggleButton( modifier: Modifier = Modifier, onText: String, offText: String, +) { + ChoiceToggle( + options = listOf(true to onText, false to offText), + selected = isOn, + onSelect = onToggle, + modifier = modifier + ) +} + +/** + * Displays a pill-shaped row of options where exactly one is selected. + * The selected option is highlighted and shows a check mark. + * + * @param options Each option's value and the text shown on its button, in display order. + * @param selected The value of the selected option. + * @param onSelect Called with an option's value when it is tapped. + * @param modifier Modifier applied to the row. + * @param optionPadding Horizontal padding inside each option; smaller fits more options. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Changed with the help of this AI tool (generalized from two options to any number). + * Prompts: + * - "And then add a third button to the settings as system settings." + */ +@Composable +fun ChoiceToggle( + options: List>, + selected: T, + onSelect: (T) -> Unit, + modifier: Modifier = Modifier, + optionPadding: Dp = 28.dp ) { val shape = RoundedCornerShape(50) @@ -47,46 +82,66 @@ fun ToggleButton( .border(1.dp, MaterialTheme.colorScheme.outlineVariant, shape), verticalAlignment = Alignment.CenterVertically ) { - // create two toggle options and checks which one is selected. - listOf(true to onText, false to offText).forEach { (value, title) -> - val selected = isOn == value - // checks if current state of button is equal to truth value of button - - // button row where icon and text are housed - Row( - modifier = Modifier - .clip(shape) - .background( - if (selected) MaterialTheme.colorScheme.primaryContainer - else Color.Transparent // highlight the button if selected - ) - .selectable( - selected = selected, - role = Role.RadioButton, - onClick = { onToggle(value) } - ) - .padding(horizontal = 28.dp, vertical = 14.dp), - verticalAlignment = Alignment.CenterVertically - ) { - // add check-mark icon if selected - if (selected) { - Icon( - imageVector = Icons.Default.Check, - contentDescription = null, - modifier = Modifier.size(14.dp), - tint = MaterialTheme.colorScheme.onPrimaryContainer - ) - Spacer(modifier = Modifier.width(4.dp)) - } + options.forEach { (value, title) -> + ChoiceOption( + title = title, + isSelected = selected == value, + onClick = { onSelect(value) }, + shape = shape, + horizontalPadding = optionPadding + ) + } + } +} - Text( - text = title, - style = MaterialTheme.typography.labelSmall, - color = if (selected) - MaterialTheme.colorScheme.onPrimaryContainer - else MaterialTheme.colorScheme.onSurface - ) - } +/** + * Displays one option of a [ChoiceToggle]. + * + * @param title The text shown on the option. + * @param isSelected Whether this option is the selected one. + * @param onClick Called when the option is tapped. + * @param shape The shape of the option's highlight. + * @param horizontalPadding Horizontal padding inside the option. + */ +@Composable +private fun ChoiceOption( + title: String, + isSelected: Boolean, + onClick: () -> Unit, + shape: Shape, + horizontalPadding: Dp +) { + Row( + modifier = Modifier + .clip(shape) + .background( + if (isSelected) MaterialTheme.colorScheme.primaryContainer + else Color.Transparent + ) + .selectable( + selected = isSelected, + role = Role.RadioButton, + onClick = onClick + ) + .padding(horizontal = horizontalPadding, vertical = 14.dp), + verticalAlignment = Alignment.CenterVertically + ) { + if (isSelected) { + Icon( + imageVector = Icons.Default.Check, + contentDescription = null, + modifier = Modifier.size(14.dp), + tint = MaterialTheme.colorScheme.onPrimaryContainer + ) + Spacer(modifier = Modifier.width(4.dp)) } + + Text( + text = title, + style = MaterialTheme.typography.labelSmall, + color = if (isSelected) + MaterialTheme.colorScheme.onPrimaryContainer + else MaterialTheme.colorScheme.onSurface + ) } } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt index fa5f6230..5c7b7e44 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt @@ -40,6 +40,21 @@ import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture * * TODO: no test tags for log out or delete dialogs yet */ + +/** + * Settings routes for account actions that are shown in the error colour, + * matching the Logout icon on the profile screen. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "One thing is that in the edit profile screen vs settings screen the logout colour for icon + * is different. we want to make them the same also to set the same colour for delete account." + */ +private val DESTRUCTIVE_ROUTES = setOf("log_out", "delete_account") + /** * Displays user information and app settings. * @@ -187,7 +202,11 @@ fun Settings( modifier = Modifier .size(38.dp) .background( - MaterialTheme.colorScheme.primaryContainer, + if (route in DESTRUCTIVE_ROUTES) { + MaterialTheme.colorScheme.errorContainer + } else { + MaterialTheme.colorScheme.primaryContainer + }, CircleShape ), contentAlignment = Alignment.Center @@ -196,7 +215,11 @@ fun Settings( imageVector = icon, contentDescription = null, modifier = Modifier.size(20.dp), - tint = MaterialTheme.colorScheme.primary + tint = if (route in DESTRUCTIVE_ROUTES) { + MaterialTheme.colorScheme.error + } else { + MaterialTheme.colorScheme.primary + } ) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt index 1460c4ce..9fb80085 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt @@ -11,25 +11,34 @@ import androidx.navigation.NavController import com.example.lambda_bbb_events.controller.AppControllers import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigationBar -import com.example.lambda_bbb_events.view.ui.components.profile.ToggleButton +import com.example.lambda_bbb_events.view.ui.components.profile.ChoiceToggle /* -Provides togglable button to switch between dark and light mode throughout the app +Provides togglable buttons to switch between light mode, dark mode, and Android's setting */ /** - * Displays togglable appearance settings for switching themes. + * Displays togglable appearance settings for switching themes: light, dark, + * or System, which follows Android's dark mode setting. * * @param navController Handles navigation. * @param controllers Application controllers. - * @param darkTheme Whether dark mode is enabled. - * @param onDarkThemeChange Updates the app theme. + * @param darkTheme The theme the user picked: `true` for dark, `false` for light, + * or `null` to follow Android's setting. + * @param onDarkThemeChange Updates the app theme with the picked option. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Changed with the help of this AI tool (added the System option). + * Prompts: + * - "And then add a third button to the settings as system settings." */ @Composable fun Theme_Toggle( navController: NavController, controllers: AppControllers, - darkTheme: Boolean, - onDarkThemeChange: (Boolean) -> Unit + darkTheme: Boolean?, + onDarkThemeChange: (Boolean?) -> Unit ) { Scaffold( containerColor = MaterialTheme.colorScheme.background, @@ -52,14 +61,11 @@ fun Theme_Toggle( ) Spacer(modifier = Modifier.height(24.dp)) - // use button function, default value set to light-mode on - ToggleButton( - isOn = !darkTheme, - onToggle = { isLightMode -> - onDarkThemeChange(!isLightMode) - }, - onText = "Light Mode", - offText = "Dark Mode", + ChoiceToggle( + options = listOf(false to "Light", true to "Dark", null to "System"), + selected = darkTheme, + onSelect = onDarkThemeChange, + optionPadding = 20.dp, modifier = Modifier.testTag("toggle_theme") ) }