dc09-sensors2 #5

Merged
nm17 merged 28 commits from dc09-sensors2 into master 2023-06-18 13:15:53 +03:00
2 changed files with 74 additions and 30 deletions
Showing only changes of commit 95e849e27a - Show all commits

View file

@ -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() },
)
}
} }

View file

@ -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>