mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-26 02:50:58 +00:00
add menu for switching moreColors
This commit is contained in:
parent
1484d7021e
commit
f8bdd7dd1c
3 changed files with 33 additions and 5 deletions
|
@ -25,6 +25,7 @@ import helium314.keyboard.latin.utils.brightenOrDarken
|
|||
import helium314.keyboard.latin.utils.isBrightColor
|
||||
import helium314.keyboard.latin.utils.isGoodContrast
|
||||
import helium314.keyboard.latin.utils.prefs
|
||||
import helium314.keyboard.settings.keyboardNeedsReload
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.EnumMap
|
||||
|
@ -336,6 +337,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
val key = Settings.PREF_USER_COLORS_PREFIX + themeName
|
||||
val value = Json.encodeToString(colors.filter { it.color != null || it.auto == false })
|
||||
prefs.edit().putString(key, value).apply()
|
||||
keyboardNeedsReload = true
|
||||
}
|
||||
|
||||
fun readUserColors(prefs: SharedPreferences, themeName: String): List<ColorSetting> {
|
||||
|
@ -346,6 +348,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
fun writeUserMoreColors(prefs: SharedPreferences, themeName: String, value: Int) {
|
||||
val key = Settings.PREF_USER_MORE_COLORS_PREFIX + themeName
|
||||
prefs.edit().putInt(key, value).apply()
|
||||
keyboardNeedsReload = true
|
||||
}
|
||||
|
||||
fun readUserMoreColors(prefs: SharedPreferences, themeName: String): Int {
|
||||
|
@ -356,6 +359,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
fun writeUserAllColors(prefs: SharedPreferences, themeName: String, colorMap: EnumMap<ColorType, Int>) {
|
||||
val key = Settings.PREF_USER_ALL_COLORS_PREFIX + themeName
|
||||
prefs.edit().putString(key, colorMap.map { "${it.key},${it.value}" }.joinToString(";")).apply()
|
||||
keyboardNeedsReload = true
|
||||
}
|
||||
|
||||
fun readUserAllColors(prefs: SharedPreferences, themeName: String): EnumMap<ColorType, Int> {
|
||||
|
|
|
@ -3,6 +3,7 @@ package helium314.keyboard.settings
|
|||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
|
@ -17,6 +18,8 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
|
@ -38,6 +41,7 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.painterResource
|
||||
|
@ -104,6 +108,7 @@ fun <T: Any> SearchScreen(
|
|||
title: @Composable () -> Unit,
|
||||
filteredItems: (String) -> List<T>,
|
||||
itemContent: @Composable (T) -> Unit,
|
||||
menu: List<Pair<String, () -> Unit>>? = null,
|
||||
content: @Composable (ColumnScope.() -> Unit)? = null,
|
||||
) {
|
||||
var searchText by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) }
|
||||
|
@ -139,6 +144,24 @@ fun <T: Any> SearchScreen(
|
|||
actions = {
|
||||
IconButton(onClick = { setShowSearch(!showSearch) })
|
||||
{ Icon(painterResource(R.drawable.sym_keyboard_search_lxx), stringResource(R.string.label_search_key)) }
|
||||
if (menu != null)
|
||||
Box {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
IconButton(
|
||||
onClick = { showMenu = true }
|
||||
) { Icon(painterResource(R.drawable.ic_arrow_left,), "menu", Modifier.rotate(-90f)) }
|
||||
DropdownMenu(
|
||||
expanded = showMenu,
|
||||
onDismissRequest = { showMenu = false }
|
||||
) {
|
||||
menu.forEach {
|
||||
DropdownMenuItem(
|
||||
text = { Text(it.first) },
|
||||
onClick = { showMenu = false; it.second() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
ExpandableSearchField(
|
||||
|
|
|
@ -51,7 +51,6 @@ import helium314.keyboard.settings.SearchScreen
|
|||
import helium314.keyboard.settings.SettingsActivity
|
||||
import helium314.keyboard.settings.Theme
|
||||
import helium314.keyboard.settings.dialogs.ColorPickerDialog
|
||||
import helium314.keyboard.settings.keyboardNeedsReload
|
||||
|
||||
@Composable
|
||||
fun ColorsScreen(
|
||||
|
@ -59,11 +58,10 @@ fun ColorsScreen(
|
|||
onClickBack: () -> Unit
|
||||
) {
|
||||
// todo:
|
||||
// allow switching moreColors (three dot menu? dropdown / spinner for visibility?)
|
||||
// need to force opposite theme if necessary!
|
||||
// allow save (load should be in theme selector, maybe here too)
|
||||
// import/export should now also store theme name
|
||||
// handle name collisions on load by simply appending a number
|
||||
// allow editing theme name
|
||||
// make sure import of old colors works
|
||||
|
||||
val ctx = LocalContext.current
|
||||
|
@ -122,6 +120,11 @@ fun ColorsScreen(
|
|||
}
|
||||
}
|
||||
},
|
||||
menu = listOf(
|
||||
stringResource(R.string.main_colors) to { KeyboardTheme.writeUserMoreColors(prefs, newThemeName.text, 0) },
|
||||
stringResource(R.string.more_colors) to { KeyboardTheme.writeUserMoreColors(prefs, newThemeName.text, 1) },
|
||||
stringResource(R.string.all_colors) to { KeyboardTheme.writeUserMoreColors(prefs, newThemeName.text, 2) },
|
||||
),
|
||||
onClickBack = onClickBack,
|
||||
filteredItems = { search -> shownColors.filter {
|
||||
it.displayName.split(" ", "_").any { it.startsWith(search, true) }
|
||||
|
@ -156,7 +159,6 @@ fun ColorsScreen(
|
|||
val newUserColors = (oldUserColors + ColorSetting(colorSetting.name, it, colorSetting.color))
|
||||
.reversed().distinctBy { it.displayName }
|
||||
KeyboardTheme.writeUserColors(prefs, themeName, newUserColors)
|
||||
keyboardNeedsReload = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +180,6 @@ fun ColorsScreen(
|
|||
.reversed().distinctBy { it.displayName }
|
||||
KeyboardTheme.writeUserColors(prefs, themeName, newUserColors)
|
||||
}
|
||||
keyboardNeedsReload = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue