mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
prepare a little for screens that will not be added in this PR
This commit is contained in:
parent
a92a5fd2c0
commit
e274011a03
3 changed files with 121 additions and 9 deletions
|
@ -135,6 +135,85 @@ fun SearchPrefScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: this is just copy paste from above, could probably share more code
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun <T: Any> SearchScreen(
|
||||||
|
onClickBack: () -> Unit,
|
||||||
|
title: String,
|
||||||
|
items: List<T>,
|
||||||
|
filter: (String, T) -> Boolean,
|
||||||
|
itemContent: @Composable (T) -> Unit,
|
||||||
|
) {
|
||||||
|
var searchText by remember { mutableStateOf(TextFieldValue()) } // must be outside th column to work without messing up cursor position
|
||||||
|
Column(Modifier.fillMaxSize()) {
|
||||||
|
// rememberSaveable would be better, but does not work with TextFieldValue
|
||||||
|
// if we just store the string, the cursor is messed up
|
||||||
|
// hmm... no, sth else is messing up that thing, and I just didn't notice
|
||||||
|
var showSearch by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
fun setShowSearch(value: Boolean) {
|
||||||
|
showSearch = value
|
||||||
|
if (!value) searchText = TextFieldValue()
|
||||||
|
}
|
||||||
|
BackHandler {
|
||||||
|
if (showSearch) setShowSearch(false)
|
||||||
|
else onClickBack()
|
||||||
|
}
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
//shadowElevation = TopAppBarDefaults.??
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(title) },
|
||||||
|
windowInsets = TopAppBarDefaults.windowInsets,
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = {
|
||||||
|
if (showSearch) setShowSearch(false)
|
||||||
|
else onClickBack()
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.ic_arrow_left), // todo: "old" arrow icon existed, so must be somewhere in resources (maybe androidx?)
|
||||||
|
stringResource(R.string.spoken_description_action_previous)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { setShowSearch(!showSearch) }) { Icon(painterResource(R.drawable.sym_keyboard_search_lxx), stringResource(R.string.label_search_key)) }
|
||||||
|
},
|
||||||
|
//elevation = 0.dp
|
||||||
|
)
|
||||||
|
ExpandableSearchField(
|
||||||
|
expanded = showSearch,
|
||||||
|
onDismiss = { setShowSearch(false) },
|
||||||
|
search = searchText,
|
||||||
|
onSearchChange = { searchText = it },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
//colors = TextFieldDefaults.colors(
|
||||||
|
// textColor = MaterialTheme.colorScheme.onSurface,
|
||||||
|
// backgroundColor = MaterialTheme.colorScheme.surface
|
||||||
|
//)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
|
||||||
|
val filteredItems = items.filter { filter(searchText.text, it) }
|
||||||
|
LazyColumn(
|
||||||
|
//state = listState, // better not, remembering scroll state when changing search term feels wrong
|
||||||
|
// todo: scrolling should consider keyboard, but not working, from https://developer.android.com/develop/ui/compose/layouts/insets#ime-animations
|
||||||
|
//modifier = Modifier.imePadding().imeNestedScroll()
|
||||||
|
) {
|
||||||
|
items(filteredItems) {
|
||||||
|
itemContent(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// from StreetComplete
|
// from StreetComplete
|
||||||
/** Expandable text field that can be dismissed and requests focus when it is expanded */
|
/** Expandable text field that can be dismissed and requests focus when it is expanded */
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
@ -13,14 +13,7 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
// test release vs old release for settings start speed
|
// make all prefs actually work
|
||||||
// also when coming from keyboard
|
|
||||||
// good way to measure startup time? e.g. sth in activity, or in composable, compared to settings button
|
|
||||||
// check if there are simple ways to improve it (try kicking out "everything" at start)
|
|
||||||
// more pref screens
|
|
||||||
// colors
|
|
||||||
// personal dictionary (maybe separately)
|
|
||||||
// languages (maybe separately)
|
|
||||||
// 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
|
||||||
|
@ -28,6 +21,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// consider that stuff in composables can get called quite often on any changes -> use remember for things that are slow (maybe add test logging)
|
// consider that stuff in composables can get called quite often on any changes -> use remember for things that are slow (maybe add test logging)
|
||||||
// dialogs should be rememberSaveable to survive display orientation change and stuff?
|
// dialogs should be rememberSaveable to survive display orientation change and stuff?
|
||||||
// default buttons for toolbar key(s) customizer and toolbar reorder dialog
|
// default buttons for toolbar key(s) customizer and toolbar reorder dialog
|
||||||
|
// merge main to implement all the new settings
|
||||||
|
|
||||||
// later
|
// later
|
||||||
// one single place for default values (in composables and settings)
|
// one single place for default values (in composables and settings)
|
||||||
|
@ -59,9 +53,13 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// check dialogs have the same colors
|
// check dialogs have the same colors
|
||||||
// list preference -> we can make auto_correct_threshold a float directly (needs pref upgrade
|
// list preference -> we can make auto_correct_threshold a float directly (needs pref upgrade
|
||||||
// actually test all the settings
|
// actually test all the settings
|
||||||
|
// when starting keyboard from settings, initially there is the "old" background color before compose stuff starts
|
||||||
|
// language settings (separate commit / PR, should change more than just move to compose)
|
||||||
|
// user dictionary settings (separate commit / PR, or maybe leave old state for a while?)
|
||||||
|
// color settings (separate commit / PR, should at least change how colors are stored)
|
||||||
|
|
||||||
// maybe later
|
// maybe later
|
||||||
// weird problem with app sometimes closing on back, but that's related to "old" settings (don't care if all are removed)
|
// weird problem with app sometimes closing on back, but that's related to "old" settings (don't care if all are removed before next release)
|
||||||
// bottom text field (though we have the search now anyway)
|
// bottom text field (though we have the search now anyway)
|
||||||
// remove navHost? but probably too useful to have...
|
// remove navHost? but probably too useful to have...
|
||||||
// lazyColumn for prefs (or just in category?)
|
// lazyColumn for prefs (or just in category?)
|
||||||
|
@ -73,6 +71,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// re-organize screens, no need to keep exactly the same arrangement
|
// re-organize screens, no need to keep exactly the same arrangement
|
||||||
// use simple list picker
|
// use simple list picker
|
||||||
// exclude all debug settings from search results if they are not enabled
|
// exclude all debug settings from search results if they are not enabled
|
||||||
|
// rearrange settings screens? now it should be very simple to do (definitely separate PR)
|
||||||
|
|
||||||
// preliminary results:
|
// preliminary results:
|
||||||
// looks ok (ugly M3 switches)
|
// looks ok (ugly M3 switches)
|
||||||
|
@ -81,6 +80,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// gets much better when opening same screen again
|
// gets much better when opening same screen again
|
||||||
// material3 is ~25% faster than material2
|
// material3 is ~25% faster than material2
|
||||||
// debug is MUCH slower than release
|
// debug is MUCH slower than release
|
||||||
|
// much of this is before the app actually starts (before App.onCreate), maybe loading the many compose classes slows down startup
|
||||||
// -> should be fine on reasonably recent phones (imo even still acceptable on S4 mini)
|
// -> should be fine on reasonably recent phones (imo even still acceptable on S4 mini)
|
||||||
// apk size increase
|
// apk size increase
|
||||||
// ca 900 kb with base + material2
|
// ca 900 kb with base + material2
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package helium314.keyboard.settings.screens
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import helium314.keyboard.latin.R
|
||||||
|
import helium314.keyboard.settings.SearchScreen
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ColorsScreen(
|
||||||
|
night: Boolean,
|
||||||
|
onClickBack: () -> Unit
|
||||||
|
) {
|
||||||
|
|
||||||
|
var availableColors by remember { mutableStateOf(emptyList<ColorSetting>()) } // todo: type?
|
||||||
|
// todo: save / load / type selection here? or in ... menu as previously?
|
||||||
|
SearchScreen(
|
||||||
|
title = stringResource(if (night) R.string.select_user_colors_night else R.string.select_user_colors),
|
||||||
|
onClickBack = onClickBack,
|
||||||
|
items = availableColors,
|
||||||
|
filter = { search, color -> color.displayName.contains(search, true) }
|
||||||
|
) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ColorSetting(
|
||||||
|
val pref: String, // old, this should go away
|
||||||
|
val displayName: String,
|
||||||
|
var auto: Boolean, // not for all
|
||||||
|
var color: Int
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue