Чекбокс/радио вынесены в отдельный composable, добавлены опции сортировки
This commit is contained in:
parent
965533c8cc
commit
95e849e27a
2 changed files with 74 additions and 30 deletions
|
@ -59,6 +59,9 @@ fun SensorsPage(navController: NavController) {
|
||||||
|
|
||||||
var sortingShow by remember { mutableStateOf(false) }
|
var sortingShow by remember { mutableStateOf(false) }
|
||||||
var sortingType by remember { mutableStateOf(SortingType.DISTANCE) }
|
var sortingType by remember { mutableStateOf(SortingType.DISTANCE) }
|
||||||
|
var sortingDesc by remember { mutableStateOf(false) }
|
||||||
|
var sortingMine by remember { mutableStateOf(false) }
|
||||||
|
var sortingFav by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val sortingTypes = remember {
|
val sortingTypes = remember {
|
||||||
listOf(
|
listOf(
|
||||||
|
@ -165,22 +168,11 @@ fun SensorsPage(navController: NavController) {
|
||||||
modifier = Modifier.padding(horizontal = 4.dp),
|
modifier = Modifier.padding(horizontal = 4.dp),
|
||||||
) {
|
) {
|
||||||
items(filterItems) {
|
items(filterItems) {
|
||||||
Row(
|
FilterCheckbox(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
checked = it.enabled.value,
|
||||||
) {
|
onCheckedChange = { it.enabled.value = !it.enabled.value },
|
||||||
Checkbox(
|
stringRes = it.stringRes,
|
||||||
checked = it.enabled.value,
|
)
|
||||||
onCheckedChange = { checked ->
|
|
||||||
it.enabled.value = checked
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = it.stringRes),
|
|
||||||
modifier = Modifier.clickable {
|
|
||||||
it.enabled.value = !it.enabled.value
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,22 +184,71 @@ fun SensorsPage(navController: NavController) {
|
||||||
modifier = Modifier.padding(horizontal = 4.dp),
|
modifier = Modifier.padding(horizontal = 4.dp),
|
||||||
) {
|
) {
|
||||||
items (sortingTypes) {
|
items (sortingTypes) {
|
||||||
Row (
|
FilterRadioButton(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
selected = (sortingType == it.sortingType),
|
||||||
) {
|
onClick = { sortingType = it.sortingType },
|
||||||
RadioButton(
|
stringRes = it.stringRes,
|
||||||
selected = (sortingType == it.sortingType),
|
)
|
||||||
onClick = { sortingType = it.sortingType },
|
}
|
||||||
)
|
|
||||||
Text(
|
item {
|
||||||
text = stringResource(id = it.stringRes),
|
FilterCheckbox(
|
||||||
modifier = Modifier.clickable {
|
checked = sortingDesc,
|
||||||
sortingType = it.sortingType
|
onCheckedChange = { sortingDesc = !sortingDesc },
|
||||||
}
|
stringRes = R.string.sort_option_desc,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
FilterCheckbox(
|
||||||
|
checked = sortingFav,
|
||||||
|
onCheckedChange = { sortingFav = !sortingFav },
|
||||||
|
stringRes = R.string.sort_option_fav,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
FilterCheckbox(
|
||||||
|
checked = sortingMine,
|
||||||
|
onCheckedChange = { sortingMine = !sortingMine },
|
||||||
|
stringRes = R.string.sort_option_mine,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExperimentalMaterial3Api
|
||||||
|
@Composable
|
||||||
|
fun FilterCheckbox(checked: Boolean, onCheckedChange: () -> Unit, stringRes: Int) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Checkbox(
|
||||||
|
checked = checked,
|
||||||
|
onCheckedChange = { onCheckedChange() },
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = stringRes),
|
||||||
|
modifier = Modifier.clickable { onCheckedChange() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExperimentalMaterial3Api
|
||||||
|
@Composable
|
||||||
|
fun FilterRadioButton(selected: Boolean, onClick: () -> Unit, stringRes: Int) {
|
||||||
|
Row (
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
RadioButton(
|
||||||
|
selected = selected,
|
||||||
|
onClick = onClick,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = stringRes),
|
||||||
|
modifier = Modifier.clickable { onClick() },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -48,4 +48,7 @@
|
||||||
<string name="sort_update_time">Время последнего обновления</string>
|
<string name="sort_update_time">Время последнего обновления</string>
|
||||||
<string name="sort_name">Название</string>
|
<string name="sort_name">Название</string>
|
||||||
<string name="sort_value">Данные</string>
|
<string name="sort_value">Данные</string>
|
||||||
|
<string name="sort_option_desc">По убыванию</string>
|
||||||
|
<string name="sort_option_fav">Избранные сверху</string>
|
||||||
|
<string name="sort_option_mine">Мои датчики сверху</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Add table
Reference in a new issue