From 38579fd4899e99a79fc4a067744e3195851e5325 Mon Sep 17 00:00:00 2001 From: Mark Injerd Date: Mon, 8 Jan 2024 23:14:02 -0500 Subject: [PATCH] Support light mode (based on system theme) Add search icon to left of app filter text field. Minor UI tweaks. --- .../com/pilot51/voicenotify/AppListScreen.kt | 65 ++++----- .../com/pilot51/voicenotify/MainActivity.kt | 6 +- .../com/pilot51/voicenotify/MainScreen.kt | 38 ++++-- .../com/pilot51/voicenotify/NotifyList.kt | 14 +- .../pilot51/voicenotify/PermissionHelper.kt | 12 +- .../pilot51/voicenotify/PreferenceDialogs.kt | 28 ++-- .../com/pilot51/voicenotify/PreferenceRows.kt | 68 ++++++---- .../pilot51/voicenotify/TextReplaceDialog.kt | 8 +- .../pilot51/voicenotify/TtsConfigScreen.kt | 124 +++++++++--------- 9 files changed, 201 insertions(+), 162 deletions(-) diff --git a/app/src/main/java/com/pilot51/voicenotify/AppListScreen.kt b/app/src/main/java/com/pilot51/voicenotify/AppListScreen.kt index 5a6bd37..4da4ecc 100644 --- a/app/src/main/java/com/pilot51/voicenotify/AppListScreen.kt +++ b/app/src/main/java/com/pilot51/voicenotify/AppListScreen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,14 @@ */ package com.pilot51.voicenotify -import androidx.compose.foundation.clickable +import android.content.res.Configuration import androidx.compose.foundation.focusable -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.selection.toggleable import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.CheckBox import androidx.compose.material.icons.filled.CheckBoxOutlineBlank @@ -27,14 +30,13 @@ import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Search import androidx.compose.material3.* import androidx.compose.runtime.* -import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -62,9 +64,16 @@ fun AppListActions() { }, modifier = Modifier .fillMaxWidth() + .padding(horizontal = 4.dp) .focusRequester(focusRequester), maxLines = 1, singleLine = true, + leadingIcon = { + Icon( + imageVector = Icons.Filled.Search, + contentDescription = null + ) + }, trailingIcon = { IconButton(onClick = { showSearchBar = false @@ -136,46 +145,40 @@ private fun AppList( @Composable private fun AppListItem(app: App, toggleIgnore: (app: App) -> Unit) { - Row(modifier = Modifier - .fillMaxWidth() - .clickable { toggleIgnore(app) } - .padding( - horizontal = 20.dp, - vertical = 10.dp - ) - ) { - Column(modifier = Modifier.weight(1f)) { + ListItem( + modifier = Modifier.toggleable( + value = app.enabled, + role = Role.Checkbox, + onValueChange = { toggleIgnore(app) } + ), + headlineContent = { Text( text = app.label, - modifier = Modifier.fillMaxWidth(), - color = Color.White, fontSize = 24.sp ) - Text( - text = app.packageName, - modifier = Modifier.fillMaxWidth(), - color = Color.White + }, + supportingContent = { + Text(app.packageName) + }, + trailingContent = { + Checkbox( + checked = app.enabled, + modifier = Modifier.focusable(false), + onCheckedChange = { toggleIgnore(app) } ) } - Checkbox( - checked = app.enabled, - modifier = Modifier - .size(40.dp) - .align(Alignment.CenterVertically) - .focusable(false), - onCheckedChange = null - ) - } + ) } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun AppListPreview() { val apps = listOf( App(1, "package.name.one", "App Name 1", true), App(2, "package.name.two", "App Name 2", false) ) - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { AppList(apps, true) {} } } diff --git a/app/src/main/java/com/pilot51/voicenotify/MainActivity.kt b/app/src/main/java/com/pilot51/voicenotify/MainActivity.kt index fa7374e..d8c5a99 100644 --- a/app/src/main/java/com/pilot51/voicenotify/MainActivity.kt +++ b/app/src/main/java/com/pilot51/voicenotify/MainActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import android.content.SharedPreferences import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.darkColorScheme import com.pilot51.voicenotify.PreferenceHelper.KEY_TTS_STREAM import com.pilot51.voicenotify.PreferenceHelper.prefs @@ -29,7 +27,7 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh super.onCreate(savedInstanceState) Common.setVolumeStream(this) setContent { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { AppMain() } } diff --git a/app/src/main/java/com/pilot51/voicenotify/MainScreen.kt b/app/src/main/java/com/pilot51/voicenotify/MainScreen.kt index 3dfbaab..cd2ae15 100644 --- a/app/src/main/java/com/pilot51/voicenotify/MainScreen.kt +++ b/app/src/main/java/com/pilot51/voicenotify/MainScreen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,11 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.content.res.Configuration import android.os.Build import android.widget.Toast import androidx.annotation.StringRes +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -32,13 +34,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext @@ -64,14 +60,27 @@ import com.pilot51.voicenotify.PreferenceHelper.KEY_IGNORE_EMPTY import com.pilot51.voicenotify.PreferenceHelper.KEY_IGNORE_GROUPS import com.pilot51.voicenotify.PreferenceHelper.KEY_QUIET_END import com.pilot51.voicenotify.PreferenceHelper.KEY_QUIET_START +import kotlinx.coroutines.flow.MutableStateFlow import java.util.* -enum class Screen(@StringRes val title: Int) { +private enum class Screen(@StringRes val title: Int) { MAIN(R.string.app_name), APP_LIST(R.string.app_list), TTS(R.string.tts) } +@Composable +fun AppTheme(content: @Composable () -> Unit) { + MaterialTheme( + colorScheme = if (isSystemInDarkTheme()) { + darkColorScheme(primary = Color(0xFF1CB7D5), primaryContainer = Color(0xFF1E4696)) + } else { + lightColorScheme(primary = Color(0xFF2A54A5), primaryContainer = Color(0xFF64F0FF)) + }, + content = content + ) +} + @Composable fun AppMain() { val navController = rememberNavController() @@ -136,7 +145,7 @@ private fun AppBar( } }, colors = TopAppBarDefaults.mediumTopAppBarColors( - containerColor = Color(0xFF333333) + containerColor = MaterialTheme.colorScheme.primaryContainer ) ) } @@ -164,8 +173,8 @@ private fun MainScreen( statusTitle = context.getString(R.string.service_running) statusSummary = context.getString(R.string.status_summary_notification_access_enabled) } - val isRunning by Service.isRunning.collectAsState() - val isSuspended by Service.isSuspended.collectAsState() + val isRunning by (if (isPreview) MutableStateFlow(false) else Service.isRunning).collectAsState() + val isSuspended by (if (isPreview) MutableStateFlow(false) else Service.isSuspended).collectAsState() if (isSuspended && isRunning) { statusTitle = stringResource(R.string.service_suspended) statusSummary = stringResource(R.string.status_summary_suspended) @@ -392,10 +401,11 @@ private fun runTestNotification(context: Context) { }, 5000) } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun AppPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { AppMain() } } diff --git a/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt b/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt index 0450506..d716f87 100644 --- a/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt +++ b/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,10 @@ package com.pilot51.voicenotify import android.app.Notification +import android.content.res.Configuration import android.widget.Toast import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -30,6 +32,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -130,10 +133,12 @@ private fun Item(item: NotificationInfo) { ) } if (item.ignoreReasons.isNotEmpty()) { + val interruptedColor = if (isSystemInDarkTheme()) Color.Yellow else Color(0xFFBBBB00) Text( text = item.getIgnoreReasonsAsText(), modifier = Modifier.fillMaxWidth(), - color = if (item.isInterrupted) Color.Yellow else Color.Red, + color = if (item.isInterrupted) interruptedColor else Color.Red, + fontWeight = FontWeight.Bold, textAlign = TextAlign.Center ) } @@ -182,7 +187,8 @@ private fun Item(item: NotificationInfo) { } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun NotificationLogDialogPreview() { val previewNotification = Notification().apply { @@ -198,7 +204,7 @@ private fun NotificationLogDialogPreview() { NotificationInfo(app = App(1, "package.name.one", "App Name 1", true), previewNotification), NotificationInfo(app = App(2, "package.name.two", "App Name 2", false), previewNotification) ) - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { NotificationLogDialog(list) {} } } diff --git a/app/src/main/java/com/pilot51/voicenotify/PermissionHelper.kt b/app/src/main/java/com/pilot51/voicenotify/PermissionHelper.kt index bb3ec03..cf84bf3 100644 --- a/app/src/main/java/com/pilot51/voicenotify/PermissionHelper.kt +++ b/app/src/main/java/com/pilot51/voicenotify/PermissionHelper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,11 @@ package com.pilot51.voicenotify import android.Manifest import android.content.Context import android.content.pm.PackageManager.PERMISSION_GRANTED +import android.content.res.Configuration import androidx.annotation.StringRes -import androidx.compose.material3.* +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -89,7 +92,8 @@ object PermissionHelper { } @OptIn(ExperimentalPermissionsApi::class) -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun RationaleDialogPreview() { val permissionState = object : PermissionState { @@ -97,7 +101,7 @@ private fun RationaleDialogPreview() { override val status = PermissionStatus.Granted override fun launchPermissionRequest() {} } - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { RationaleDialog( permissionState = permissionState, rationaleMsgId = R.string.permission_rationale_read_phone_state diff --git a/app/src/main/java/com/pilot51/voicenotify/PreferenceDialogs.kt b/app/src/main/java/com/pilot51/voicenotify/PreferenceDialogs.kt index 0925a3b..9f2b838 100644 --- a/app/src/main/java/com/pilot51/voicenotify/PreferenceDialogs.kt +++ b/app/src/main/java/com/pilot51/voicenotify/PreferenceDialogs.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.pilot51.voicenotify import android.content.ActivityNotFoundException import android.content.Intent +import android.content.res.Configuration import android.media.AudioManager import android.net.Uri import android.os.Build @@ -592,10 +593,11 @@ private fun LazyListScope.supportItem( } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun TextEditDialogPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { TextEditDialog( titleRes = R.string.ignore_strings, messageRes = R.string.require_ignore_strings_dialog_msg, @@ -605,34 +607,38 @@ private fun TextEditDialogPreview() { } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun TtsStreamDialogPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { TtsStreamDialog {} } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun DeviceStatesDialogPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { DeviceStatesDialog {} } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun QuietTimeDialogPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { QuietTimeDialog(KEY_QUIET_START) {} } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun SupportDialogPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { SupportDialog {} } } diff --git a/app/src/main/java/com/pilot51/voicenotify/PreferenceRows.kt b/app/src/main/java/com/pilot51/voicenotify/PreferenceRows.kt index 29951f1..77522d8 100644 --- a/app/src/main/java/com/pilot51/voicenotify/PreferenceRows.kt +++ b/app/src/main/java/com/pilot51/voicenotify/PreferenceRows.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,16 @@ */ package com.pilot51.voicenotify +import android.content.res.Configuration import androidx.annotation.StringRes import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.selection.toggleable -import androidx.compose.material3.* +import androidx.compose.material3.Checkbox +import androidx.compose.material3.ListItem +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue @@ -29,6 +33,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role import androidx.compose.ui.tooling.preview.Preview @@ -43,40 +48,40 @@ import kotlin.reflect.KProperty fun PreferenceRowLink( @StringRes title: Int, @StringRes subtitle: Int, + enabled: Boolean = true, onClick: () -> Unit ) = PreferenceRowLink( title = stringResource(title), subtitle = stringResource(subtitle), + enabled = enabled, onClick = onClick ) @OptIn(ExperimentalFoundationApi::class) @Composable fun PreferenceRowLink( - enabled: Boolean = true, title: String, subtitle: String, + enabled: Boolean = true, onClick: () -> Unit, onLongClick: (() -> Unit)? = null ) { - Surface { - Row( - modifier = Modifier - .fillMaxWidth() - .height(IntrinsicSize.Min) - .combinedClickable( - enabled = enabled, - onClick = onClick, - onLongClick = onLongClick - ), - verticalAlignment = Alignment.CenterVertically - ) { - PreferenceRowScaffold( - title = title, + Row( + modifier = Modifier + .fillMaxWidth() + .height(IntrinsicSize.Min) + .combinedClickable( enabled = enabled, - subtitle = subtitle - ) - } + onClick = onClick, + onLongClick = onLongClick + ), + verticalAlignment = Alignment.CenterVertically + ) { + PreferenceRowScaffold( + title = title, + enabled = enabled, + subtitle = subtitle + ) } } @@ -87,8 +92,9 @@ fun PreferenceRowCheckbox( key: String, default: Boolean ) { + val isPreview = LocalInspectionMode.current var prefValue by remember { - PreferenceBooleanState(key = key, defaultValue = default) + PreferenceBooleanState(key = if (isPreview) "isPreview" else key, defaultValue = default) } Row( modifier = Modifier @@ -189,22 +195,25 @@ private inline operator fun PreferenceBooleanState.setValue( this.value = value } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun SettingsMenuLinkPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { PreferenceRowLink( - title = R.string.service_running, - subtitle = R.string.status_summary_notification_access_enabled, + title = R.string.tts_settings, + subtitle = R.string.tts_settings_summary_fail, + enabled = false, onClick = {} ) } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun SettingsCheckboxCheckedPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { PreferenceRowCheckbox( title = R.string.ignore_groups, subtitle = R.string.ignore_groups_summary_on, @@ -214,10 +223,11 @@ private fun SettingsCheckboxCheckedPreview() { } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun SettingsCheckboxUncheckedPreview() { - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { PreferenceRowCheckbox( title = R.string.ignore_groups, subtitle = R.string.ignore_groups_summary_off, diff --git a/app/src/main/java/com/pilot51/voicenotify/TextReplaceDialog.kt b/app/src/main/java/com/pilot51/voicenotify/TextReplaceDialog.kt index 86fae4e..e7f782f 100644 --- a/app/src/main/java/com/pilot51/voicenotify/TextReplaceDialog.kt +++ b/app/src/main/java/com/pilot51/voicenotify/TextReplaceDialog.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.pilot51.voicenotify +import android.content.res.Configuration import android.util.Pair import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn @@ -219,7 +220,8 @@ private fun TextReplaceListItem( } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun TextReplaceListPreview() { val replaceList = mutableListOf( @@ -227,7 +229,7 @@ private fun TextReplaceListPreview() { Pair("this", "that"), null ) - MaterialTheme(colorScheme = darkColorScheme()) { + AppTheme { TextReplaceDialog( replaceList = replaceList, onSave = {}, diff --git a/app/src/main/java/com/pilot51/voicenotify/TtsConfigScreen.kt b/app/src/main/java/com/pilot51/voicenotify/TtsConfigScreen.kt index 0ffba06..68d1eb9 100644 --- a/app/src/main/java/com/pilot51/voicenotify/TtsConfigScreen.kt +++ b/app/src/main/java/com/pilot51/voicenotify/TtsConfigScreen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2011-2023 Mark Injerd + * Copyright 2011-2024 Mark Injerd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,9 @@ package com.pilot51.voicenotify import android.content.Intent +import android.content.res.Configuration import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.darkColorScheme import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -47,68 +46,69 @@ fun TtsConfigScreen() { var showTtsStream by remember { mutableStateOf(false) } var showTtsDelay by remember { mutableStateOf(false) } var showTtsRepeat by remember { mutableStateOf(false) } - MaterialTheme(colorScheme = darkColorScheme()) { - Column(modifier = Modifier.fillMaxSize()) { - PreferenceRowLink( - enabled = ttsEnabled, - title = stringResource(R.string.tts_settings), - subtitle = ttsSummary, - onClick = { ttsIntent?.let { context.startActivity(it) } } - ) - PreferenceRowLink( - title = R.string.tts_message, - subtitle = R.string.tts_message_summary, - onClick = { showTtsMessage = true } - ) - PreferenceRowLink( - title = R.string.tts_text_replace, - subtitle = R.string.tts_text_replace_summary, - onClick = { showTextReplaceDialog = true } - ) - PreferenceRowLink( - title = R.string.max_length, - subtitle = R.string.max_length_summary, - onClick = { showMaxMessage = true } - ) - PreferenceRowLink( - title = R.string.tts_stream, - subtitle = R.string.tts_stream_summary, - onClick = { showTtsStream = true } - ) - PreferenceRowLink( - title = R.string.tts_delay, - subtitle = R.string.tts_delay_summary, - onClick = { showTtsDelay = true } - ) - PreferenceRowLink( - title = R.string.tts_repeat, - subtitle = R.string.tts_repeat_summary, - onClick = { showTtsRepeat = true } - ) - } - if (showTtsMessage) { - TtsMessageDialog { showTtsMessage = false } - } - if (showTextReplaceDialog) { - TextReplaceDialog { showTextReplaceDialog = false } - } - if (showMaxMessage) { - TtsMaxLengthDialog { showMaxMessage = false } - } - if (showTtsStream) { - TtsStreamDialog { showTtsStream = false } - } - if (showTtsDelay) { - TtsDelayDialog { showTtsDelay = false } - } - if (showTtsRepeat) { - TtsRepeatDialog { showTtsRepeat = false } - } + Column(modifier = Modifier.fillMaxSize()) { + PreferenceRowLink( + title = stringResource(R.string.tts_settings), + subtitle = ttsSummary, + enabled = ttsEnabled, + onClick = { ttsIntent?.let { context.startActivity(it) } } + ) + PreferenceRowLink( + title = R.string.tts_message, + subtitle = R.string.tts_message_summary, + onClick = { showTtsMessage = true } + ) + PreferenceRowLink( + title = R.string.tts_text_replace, + subtitle = R.string.tts_text_replace_summary, + onClick = { showTextReplaceDialog = true } + ) + PreferenceRowLink( + title = R.string.max_length, + subtitle = R.string.max_length_summary, + onClick = { showMaxMessage = true } + ) + PreferenceRowLink( + title = R.string.tts_stream, + subtitle = R.string.tts_stream_summary, + onClick = { showTtsStream = true } + ) + PreferenceRowLink( + title = R.string.tts_delay, + subtitle = R.string.tts_delay_summary, + onClick = { showTtsDelay = true } + ) + PreferenceRowLink( + title = R.string.tts_repeat, + subtitle = R.string.tts_repeat_summary, + onClick = { showTtsRepeat = true } + ) + } + if (showTtsMessage) { + TtsMessageDialog { showTtsMessage = false } + } + if (showTextReplaceDialog) { + TextReplaceDialog { showTextReplaceDialog = false } + } + if (showMaxMessage) { + TtsMaxLengthDialog { showMaxMessage = false } + } + if (showTtsStream) { + TtsStreamDialog { showTtsStream = false } + } + if (showTtsDelay) { + TtsDelayDialog { showTtsDelay = false } + } + if (showTtsRepeat) { + TtsRepeatDialog { showTtsRepeat = false } } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable private fun TtsConfigScreenPreview() { - TtsConfigScreen() + AppTheme { + TtsConfigScreen() + } }