mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
(almost) complete toolbar screen
This commit is contained in:
parent
724b292edb
commit
52e0e891fe
5 changed files with 134 additions and 43 deletions
|
@ -76,6 +76,7 @@ object NonSettingsPrefs {
|
||||||
const val HIDDEN_FEATURES = "hidden_features"
|
const val HIDDEN_FEATURES = "hidden_features"
|
||||||
const val GITHUB = "github"
|
const val GITHUB = "github"
|
||||||
const val SAVE_LOG = "save_log"
|
const val SAVE_LOG = "save_log"
|
||||||
|
const val CUSTOM_KEY_CODES = "customize_key_codes"
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
|
|
|
@ -173,7 +173,6 @@ fun SwitchPreference(
|
||||||
fun SwitchPreference(
|
fun SwitchPreference(
|
||||||
def: PrefDef,
|
def: PrefDef,
|
||||||
default: Boolean,
|
default: Boolean,
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
allowCheckedChange: (Boolean) -> Boolean = { true },
|
allowCheckedChange: (Boolean) -> Boolean = { true },
|
||||||
onCheckedChange: (Boolean) -> Unit = { }
|
onCheckedChange: (Boolean) -> Unit = { }
|
||||||
) {
|
) {
|
||||||
|
@ -182,7 +181,6 @@ fun SwitchPreference(
|
||||||
description = def.description,
|
description = def.description,
|
||||||
pref = def.key,
|
pref = def.key,
|
||||||
default = default,
|
default = default,
|
||||||
modifier = modifier,
|
|
||||||
allowCheckedChange = allowCheckedChange,
|
allowCheckedChange = allowCheckedChange,
|
||||||
onCheckedChange = onCheckedChange
|
onCheckedChange = onCheckedChange
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,11 +14,11 @@ import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
// add reorder / enable dialog
|
// need to adjust icons, because compose refuses to work with rotated drawables (arrows on toolbar keys)
|
||||||
// maybe a more generic / reusable wrapper dialog
|
// more pref screens
|
||||||
// need to adjust icons, because compose refuses to work with rotated drawables (arrows)
|
// other super-custom things
|
||||||
// drag handle should have "dimmed" color, iirc there are some theme defaults with the localCompositionProvider?
|
// toolbar key customizer (missing from toolbar screen)
|
||||||
// more pref screens, and other super-custom things
|
// icon selector
|
||||||
// consider IME insets when searching
|
// consider IME insets when searching
|
||||||
// improve performance when loading screens with many settings (lazyColumn?)
|
// 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
|
// screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding
|
||||||
|
|
|
@ -79,7 +79,12 @@ fun <T: Any> ReorderDialog(
|
||||||
val elevation by animateDpAsState(if (dragging) 4.dp else 0.dp)
|
val elevation by animateDpAsState(if (dragging) 4.dp else 0.dp)
|
||||||
Surface(shadowElevation = elevation) {
|
Surface(shadowElevation = elevation) {
|
||||||
Row(modifier = Modifier.longPressDraggableHandle(), verticalAlignment = Alignment.CenterVertically) {
|
Row(modifier = Modifier.longPressDraggableHandle(), verticalAlignment = Alignment.CenterVertically) {
|
||||||
Icon(painterResource(R.drawable.ic_drag_indicator), "Reorder", Modifier.padding(end = 8.dp))
|
Icon(
|
||||||
|
painterResource(R.drawable.ic_drag_indicator),
|
||||||
|
"Reorder",
|
||||||
|
Modifier.padding(end = 8.dp),
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
displayItem(item)
|
displayItem(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,17 @@ import androidx.compose.ui.unit.dp
|
||||||
import helium314.keyboard.keyboard.internal.KeyboardIconsSet
|
import helium314.keyboard.keyboard.internal.KeyboardIconsSet
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.settings.Settings
|
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.defaultPinnedToolbarPref
|
||||||
|
import helium314.keyboard.latin.utils.defaultToolbarPref
|
||||||
import helium314.keyboard.latin.utils.getStringResourceOrName
|
import helium314.keyboard.latin.utils.getStringResourceOrName
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.AllPrefs
|
||||||
|
import helium314.keyboard.settings.NonSettingsPrefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.PrefDef
|
||||||
import helium314.keyboard.settings.Preference
|
import helium314.keyboard.settings.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity2
|
||||||
|
import helium314.keyboard.settings.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import helium314.keyboard.settings.dialogs.ReorderDialog
|
import helium314.keyboard.settings.dialogs.ReorderDialog
|
||||||
import helium314.keyboard.settings.prefs
|
import helium314.keyboard.settings.prefs
|
||||||
|
@ -44,11 +47,32 @@ fun ToolbarScreen(
|
||||||
onClickBack = onClickBack,
|
onClickBack = onClickBack,
|
||||||
title = stringResource(R.string.settings_screen_toolbar),
|
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_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(
|
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 ->
|
PrefDef(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) { def ->
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
Preference(
|
Preference(
|
||||||
|
@ -56,30 +80,97 @@ fun createToolbarPrefs(context: Context) = listOf(
|
||||||
onClick = { showDialog = true },
|
onClick = { showDialog = true },
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
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 ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val items = prefs.getString(def.key, defaultPinnedToolbarPref)!!.split(";").mapTo(ArrayList()) {
|
val items = prefs.getString(prefKey, default)!!.split(";").mapTo(ArrayList()) {
|
||||||
val both = it.split(",")
|
val both = it.split(",")
|
||||||
KeyAndState(both.first(), both.last().toBoolean())
|
KeyAndState(both.first(), both.last().toBoolean())
|
||||||
}
|
}
|
||||||
ReorderDialog(
|
ReorderDialog(
|
||||||
onConfirmed = { reorderedItems ->
|
onConfirmed = { reorderedItems ->
|
||||||
val value = reorderedItems.joinToString(";") { it.name + "," + it.state }
|
val value = reorderedItems.joinToString(";") { it.name + "," + it.state }
|
||||||
prefs.edit().putString(def.key, value).apply()
|
prefs.edit().putString(prefKey, value).apply()
|
||||||
themeChanged = true
|
themeChanged = true
|
||||||
},
|
},
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { onDismiss },
|
||||||
items = items,
|
items = items,
|
||||||
title = { Text(def.title)},
|
title = { Text(title)},
|
||||||
displayItem = { item ->
|
displayItem = { item ->
|
||||||
var checked by remember { mutableStateOf(item.state) }
|
var checked by remember { mutableStateOf(item.state) }
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
Box(modifier = Modifier.width(40.dp)) {
|
Box(modifier = Modifier.width(40.dp)) {
|
||||||
val iconId = KeyboardIconsSet.instance.iconIds[item.name.lowercase()]
|
val iconId = KeyboardIconsSet.instance.iconIds[item.name.lowercase()]
|
||||||
if (iconId != null) // using ids makes having user-provided icons more difficult...
|
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)
|
Icon(painterResource(iconId), null)
|
||||||
}
|
}
|
||||||
val text = item.name.lowercase().getStringResourceOrName("", context).toString()
|
val text = item.name.lowercase().getStringResourceOrName("", ctx).toString()
|
||||||
Text(text, Modifier.weight(1f))
|
Text(text, Modifier.weight(1f))
|
||||||
Switch(
|
Switch(
|
||||||
checked = checked,
|
checked = checked,
|
||||||
|
@ -87,13 +178,9 @@ fun createToolbarPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getKey = { it.hashCode() }
|
getKey = { it.name }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
private class KeyAndState(var name: String, var state: Boolean)
|
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue