Settings: remove search field

- Settings list is small; search added noise
- Drop OutlinedTextField + query filtering from ViewModel
This commit is contained in:
avi 2026-09-15 11:34:48 -05:00
commit ffea797eba
2 changed files with 3 additions and 26 deletions

View file

@ -65,7 +65,7 @@ import kotlinx.serialization.json.jsonPrimitive
/** /**
* Generic settings screen: every control is rendered from the setting's * Generic settings screen: every control is rendered from the setting's
* [SettingType] — no per-setting UI code. Users can add/edit/delete custom * [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) @OptIn(ExperimentalMaterial3Api::class)
@Composable @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()) { LazyColumn(Modifier.fillMaxWidth()) {
state.categories.forEach { section -> state.categories.forEach { section ->
item { item {

View file

@ -16,7 +16,6 @@ import kotlinx.coroutines.launch
data class SettingsUiState( data class SettingsUiState(
val categories: List<CategorySection> = emptyList(), val categories: List<CategorySection> = emptyList(),
val search: String = "",
val busy: Boolean = false, val busy: Boolean = false,
val message: String? = null, val message: String? = null,
) { ) {
@ -34,7 +33,6 @@ data class SettingsUiState(
class SettingsViewModel(private val app: ShonarApplication) : ViewModel() { class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
val settings: SettingsManager = app.settingsManager val settings: SettingsManager = app.settingsManager
private val searchFlow = MutableStateFlow("")
private val messageFlow = MutableStateFlow<String?>(null) private val messageFlow = MutableStateFlow<String?>(null)
// combine's transform is suspend, so value reads stay coroutine-native // 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( val state: StateFlow<SettingsUiState> = combine(
settings.definitions, settings.definitions,
settings.valuesChanged, settings.valuesChanged,
searchFlow,
messageFlow, messageFlow,
) { defs, _, query, message -> ) { defs, _, message ->
val gateValue = mutableMapOf<String, Boolean>() val gateValue = mutableMapOf<String, Boolean>()
suspend fun gate(id: String): Boolean = suspend fun gate(id: String): Boolean =
gateValue.getOrPut(id) { settings.bool(id) } gateValue.getOrPut(id) { settings.bool(id) }
@ -54,12 +51,7 @@ class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
val g = def.visibleIfSettingId ?: return@filter true val g = def.visibleIfSettingId ?: return@filter true
gate(g) gate(g)
} }
val filtered = if (query.isBlank()) visible else visible.filter { val byCat = visible.groupBy { it.category }
it.name.contains(query, ignoreCase = true) ||
it.id.contains(query, ignoreCase = true) ||
it.description.contains(query, ignoreCase = true)
}
val byCat = filtered.groupBy { it.category }
SettingsUiState( SettingsUiState(
categories = byCat.entries categories = byCat.entries
.sortedBy { it.key } .sortedBy { it.key }
@ -89,15 +81,10 @@ class SettingsViewModel(private val app: ShonarApplication) : ViewModel() {
}, },
) )
}, },
search = query,
message = message, message = message,
) )
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SettingsUiState()) }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SettingsUiState())
fun setSearch(q: String) {
searchFlow.value = q
}
/** Build-stamped version (versionName), not a stored setting. */ /** Build-stamped version (versionName), not a stored setting. */
private fun appVersionName(): String? { private fun appVersionName(): String? {
val pm = app.packageManager val pm = app.packageManager