Settings: remove search field
- Settings list is small; search added noise - Drop OutlinedTextField + query filtering from ViewModel
This commit is contained in:
parent
1887256fbe
commit
ffea797eba
2 changed files with 3 additions and 26 deletions
|
|
@ -65,7 +65,7 @@ import kotlinx.serialization.json.jsonPrimitive
|
|||
/**
|
||||
* Generic settings screen: every control is rendered from the setting's
|
||||
* [SettingType] — no per-setting UI code. Users can add/edit/delete custom
|
||||
* settings, reset to defaults, search, and export/import JSON.
|
||||
* settings, reset to defaults, and export/import JSON.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -109,16 +109,6 @@ fun SettingsScreen(onBack: () -> Unit) {
|
|||
)
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.search,
|
||||
onValueChange = vm::setSearch,
|
||||
placeholder = { Text("Search settings") },
|
||||
singleLine = true,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
|
||||
LazyColumn(Modifier.fillMaxWidth()) {
|
||||
state.categories.forEach { section ->
|
||||
item {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import kotlinx.coroutines.launch
|
|||
|
||||
data class SettingsUiState(
|
||||
val categories: List<CategorySection> = emptyList(),
|
||||
val search: String = "",
|
||||
val busy: Boolean = false,
|
||||
val message: String? = null,
|
||||
) {
|
||||
|
|
@ -34,7 +33,6 @@ data class SettingsUiState(
|
|||
class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
|
||||
|
||||
val settings: SettingsManager = app.settingsManager
|
||||
private val searchFlow = MutableStateFlow("")
|
||||
private val messageFlow = MutableStateFlow<String?>(null)
|
||||
|
||||
// combine's transform is suspend, so value reads stay coroutine-native
|
||||
|
|
@ -42,9 +40,8 @@ class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
|
|||
val state: StateFlow<SettingsUiState> = combine(
|
||||
settings.definitions,
|
||||
settings.valuesChanged,
|
||||
searchFlow,
|
||||
messageFlow,
|
||||
) { defs, _, query, message ->
|
||||
) { defs, _, message ->
|
||||
val gateValue = mutableMapOf<String, Boolean>()
|
||||
suspend fun gate(id: String): Boolean =
|
||||
gateValue.getOrPut(id) { settings.bool(id) }
|
||||
|
|
@ -54,12 +51,7 @@ class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
|
|||
val g = def.visibleIfSettingId ?: return@filter true
|
||||
gate(g)
|
||||
}
|
||||
val filtered = if (query.isBlank()) visible else visible.filter {
|
||||
it.name.contains(query, ignoreCase = true) ||
|
||||
it.id.contains(query, ignoreCase = true) ||
|
||||
it.description.contains(query, ignoreCase = true)
|
||||
}
|
||||
val byCat = filtered.groupBy { it.category }
|
||||
val byCat = visible.groupBy { it.category }
|
||||
SettingsUiState(
|
||||
categories = byCat.entries
|
||||
.sortedBy { it.key }
|
||||
|
|
@ -89,15 +81,10 @@ class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
|
|||
},
|
||||
)
|
||||
},
|
||||
search = query,
|
||||
message = message,
|
||||
)
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SettingsUiState())
|
||||
|
||||
fun setSearch(q: String) {
|
||||
searchFlow.value = q
|
||||
}
|
||||
|
||||
/** Build-stamped version (versionName), not a stored setting. */
|
||||
private fun appVersionName(): String? {
|
||||
val pm = app.packageManager
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue