diff --git a/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt b/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt index 3ceceb2dd..1c6438d7b 100644 --- a/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt +++ b/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt @@ -76,6 +76,7 @@ object NonSettingsPrefs { const val HIDDEN_FEATURES = "hidden_features" const val GITHUB = "github" const val SAVE_LOG = "save_log" + const val CUSTOM_KEY_CODES = "customize_key_codes" } @JvmField diff --git a/app/src/main/java/helium314/keyboard/settings/Preference.kt b/app/src/main/java/helium314/keyboard/settings/Preference.kt index ed4b7c4b0..31b8e6fda 100644 --- a/app/src/main/java/helium314/keyboard/settings/Preference.kt +++ b/app/src/main/java/helium314/keyboard/settings/Preference.kt @@ -173,7 +173,6 @@ fun SwitchPreference( fun SwitchPreference( def: PrefDef, default: Boolean, - modifier: Modifier = Modifier, allowCheckedChange: (Boolean) -> Boolean = { true }, onCheckedChange: (Boolean) -> Unit = { } ) { @@ -182,7 +181,6 @@ fun SwitchPreference( description = def.description, pref = def.key, default = default, - modifier = modifier, allowCheckedChange = allowCheckedChange, onCheckedChange = onCheckedChange ) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index ed419b0ba..6b8bc2c82 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -14,11 +14,11 @@ import helium314.keyboard.latin.utils.DeviceProtectedUtils import kotlinx.coroutines.flow.MutableStateFlow // todo -// add reorder / enable dialog -// maybe a more generic / reusable wrapper dialog -// need to adjust icons, because compose refuses to work with rotated drawables (arrows) -// drag handle should have "dimmed" color, iirc there are some theme defaults with the localCompositionProvider? -// more pref screens, and other super-custom things +// need to adjust icons, because compose refuses to work with rotated drawables (arrows on toolbar keys) +// more pref screens +// other super-custom things +// toolbar key customizer (missing from toolbar screen) +// icon selector // consider IME insets when searching // improve performance when loading screens with many settings (lazyColumn?) // screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/ReorderDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/ReorderDialog.kt index f6c5a1ea0..81f366f8e 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/ReorderDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/ReorderDialog.kt @@ -79,8 +79,13 @@ fun ReorderDialog( val elevation by animateDpAsState(if (dragging) 4.dp else 0.dp) Surface(shadowElevation = elevation) { Row(modifier = Modifier.longPressDraggableHandle(), verticalAlignment = Alignment.CenterVertically) { - Icon(painterResource(R.drawable.ic_drag_indicator), "Reorder", Modifier.padding(end = 8.dp)) - displayItem(item) + Icon( + painterResource(R.drawable.ic_drag_indicator), + "Reorder", + Modifier.padding(end = 8.dp), + MaterialTheme.colorScheme.onSurfaceVariant + ) + displayItem(item) } } } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/ToolbarScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/ToolbarScreen.kt index e4234ed55..7bd28e01e 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/ToolbarScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/ToolbarScreen.kt @@ -23,14 +23,17 @@ import androidx.compose.ui.unit.dp import helium314.keyboard.keyboard.internal.KeyboardIconsSet import helium314.keyboard.latin.R import helium314.keyboard.latin.settings.Settings -import helium314.keyboard.latin.utils.Log +import helium314.keyboard.latin.utils.defaultClipboardToolbarPref import helium314.keyboard.latin.utils.defaultPinnedToolbarPref +import helium314.keyboard.latin.utils.defaultToolbarPref import helium314.keyboard.latin.utils.getStringResourceOrName import helium314.keyboard.settings.AllPrefs +import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.Preference import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SettingsActivity2 +import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.Theme import helium314.keyboard.settings.dialogs.ReorderDialog import helium314.keyboard.settings.prefs @@ -44,11 +47,32 @@ fun ToolbarScreen( onClickBack = onClickBack, title = stringResource(R.string.settings_screen_toolbar), ) { + SettingsActivity2.allPrefs.map[Settings.PREF_TOOLBAR_KEYS]!!.Preference() SettingsActivity2.allPrefs.map[Settings.PREF_PINNED_TOOLBAR_KEYS]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_CLIPBOARD_TOOLBAR_KEYS]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_TOOLBAR_CUSTOM_KEY_CODES]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_QUICK_PIN_TOOLBAR_KEYS]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_AUTO_SHOW_TOOLBAR]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_AUTO_HIDE_TOOLBAR]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_VARIABLE_TOOLBAR_DIRECTION]!!.Preference() } } fun createToolbarPrefs(context: Context) = listOf( + PrefDef(context, Settings.PREF_TOOLBAR_KEYS, R.string.toolbar_keys) { def -> + var showDialog by remember { mutableStateOf(false) } + Preference( + name = def.title, + onClick = { showDialog = true }, + ) + if (showDialog) { + ToolbarKeyReorderDialog( + def.key, + defaultToolbarPref, + def.title, + ) { showDialog = false } + } + }, PrefDef(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) { def -> var showDialog by remember { mutableStateOf(false) } Preference( @@ -56,45 +80,108 @@ fun createToolbarPrefs(context: Context) = listOf( onClick = { showDialog = true }, ) if (showDialog) { - val ctx = LocalContext.current - val prefs = ctx.prefs() - val items = prefs.getString(def.key, defaultPinnedToolbarPref)!!.split(";").mapTo(ArrayList()) { - val both = it.split(",") - KeyAndState(both.first(), both.last().toBoolean()) - } - ReorderDialog( - onConfirmed = { reorderedItems -> - val value = reorderedItems.joinToString(";") { it.name + "," + it.state } - prefs.edit().putString(def.key, value).apply() - themeChanged = true - }, - onDismissRequest = { showDialog = false }, - items = items, - title = { Text(def.title)}, - displayItem = { item -> - var checked by remember { mutableStateOf(item.state) } - Row(verticalAlignment = Alignment.CenterVertically) { - Box(modifier = Modifier.width(40.dp)) { - val iconId = KeyboardIconsSet.instance.iconIds[item.name.lowercase()] - if (iconId != null) // using ids makes having user-provided icons more difficult... - Icon(painterResource(iconId), null) - } - val text = item.name.lowercase().getStringResourceOrName("", context).toString() - Text(text, Modifier.weight(1f)) - Switch( - checked = checked, - onCheckedChange = { item.state = it; checked = it } - ) - } - }, - getKey = { it.hashCode() } - ) + ToolbarKeyReorderDialog( + def.key, + defaultPinnedToolbarPref, + def.title, + ) { showDialog = false } } }, + PrefDef(context, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, R.string.clipboard_toolbar_keys) { def -> + var showDialog by remember { mutableStateOf(false) } + Preference( + name = def.title, + onClick = { showDialog = true }, + ) + if (showDialog) { + ToolbarKeyReorderDialog( + def.key, + defaultClipboardToolbarPref, + def.title, + ) { showDialog = false } + } + }, + PrefDef(context, NonSettingsPrefs.CUSTOM_KEY_CODES, R.string.customize_toolbar_key_codes) { def -> + var showDialog by remember { mutableStateOf(false) } + Preference( + name = def.title, + onClick = { showDialog = true }, + ) + // todo: needs the dialog! + // which actually changes a different pref key... see if we can avoid it without too much work + }, + PrefDef(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary) { def -> + SwitchPreference( + def, + false, + ) { themeChanged = true } + }, + PrefDef(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary) { def -> + SwitchPreference( + def, + false, + ) + }, + PrefDef(context, Settings.PREF_AUTO_HIDE_TOOLBAR, R.string.auto_hide_toolbar, R.string.auto_hide_toolbar_summary) { def -> + SwitchPreference( + def, + false, + ) + }, + PrefDef(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary) { def -> + SwitchPreference( + def, + true, + ) + } ) private class KeyAndState(var name: String, var state: Boolean) +@Composable +fun ToolbarKeyReorderDialog( + prefKey: String, + default: String, + title: String, + onDismiss: () -> Unit +) { + val ctx = LocalContext.current + val prefs = ctx.prefs() + val items = prefs.getString(prefKey, default)!!.split(";").mapTo(ArrayList()) { + val both = it.split(",") + KeyAndState(both.first(), both.last().toBoolean()) + } + ReorderDialog( + onConfirmed = { reorderedItems -> + val value = reorderedItems.joinToString(";") { it.name + "," + it.state } + prefs.edit().putString(prefKey, value).apply() + themeChanged = true + }, + onDismissRequest = { onDismiss }, + items = items, + title = { Text(title)}, + displayItem = { item -> + var checked by remember { mutableStateOf(item.state) } + Row(verticalAlignment = Alignment.CenterVertically) { + Box(modifier = Modifier.width(40.dp)) { + val iconId = KeyboardIconsSet.instance.iconIds[item.name.lowercase()] + if (iconId != null) + // using ids makes having user-provided icons more difficult + // probably best would be some KeyboardIconsSet.getComposable that does "the right thing" + Icon(painterResource(iconId), null) + } + val text = item.name.lowercase().getStringResourceOrName("", ctx).toString() + Text(text, Modifier.weight(1f)) + Switch( + checked = checked, + onCheckedChange = { item.state = it; checked = it } + ) + } + }, + getKey = { it.name } + ) +} + @Preview @Composable private fun Preview() {