Compare commits
6 commits
5639ebd4cd
...
9c6be5d8c5
Author | SHA1 | Date | |
---|---|---|---|
9c6be5d8c5 | |||
12db4ba8df | |||
95e849e27a | |||
965533c8cc | |||
ebd8dadf7f | |||
e6f7ff8238 |
3 changed files with 138 additions and 24 deletions
|
@ -14,13 +14,14 @@ import androidx.compose.material3.Checkbox
|
|||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.SearchBar
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -40,13 +41,39 @@ data class SensorFilter(
|
|||
var enabled: MutableState<Boolean> = mutableStateOf(false),
|
||||
)
|
||||
|
||||
data class SensorSortingItem(
|
||||
val stringRes: Int,
|
||||
val sortingType: SortingType,
|
||||
)
|
||||
|
||||
enum class SortingType {
|
||||
DISTANCE, TYPE, UPD_TIME,
|
||||
NAME, VALUE,
|
||||
}
|
||||
|
||||
@ExperimentalMaterial3Api
|
||||
@Composable
|
||||
fun SensorsPage(navController: NavController) {
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
var searchActive by remember { mutableStateOf(false) }
|
||||
|
||||
var filterShown by remember { mutableStateOf(false) }
|
||||
var sortingShow by remember { mutableStateOf(false) }
|
||||
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 {
|
||||
listOf(
|
||||
SensorSortingItem(R.string.sort_distance, SortingType.DISTANCE),
|
||||
SensorSortingItem(R.string.sort_type, SortingType.TYPE),
|
||||
SensorSortingItem(R.string.sort_update_time, SortingType.UPD_TIME),
|
||||
SensorSortingItem(R.string.sort_name, SortingType.NAME),
|
||||
SensorSortingItem(R.string.sort_value, SortingType.VALUE),
|
||||
)
|
||||
}
|
||||
|
||||
var filterShow by remember { mutableStateOf(false) }
|
||||
var filterMine by remember { mutableStateOf(false) }
|
||||
|
||||
val filterItems = remember {
|
||||
|
@ -106,12 +133,12 @@ fun SensorsPage(navController: NavController) {
|
|||
modifier = Modifier.padding(horizontal = 8.dp),
|
||||
) {
|
||||
AssistChip(
|
||||
onClick = { filterShown = true },
|
||||
onClick = { filterShow = true },
|
||||
label = { Text(text = stringResource(R.string.sensors_filter)) },
|
||||
)
|
||||
|
||||
AssistChip(
|
||||
onClick = { },
|
||||
onClick = { sortingShow = true },
|
||||
label = { Text(text = stringResource(R.string.sensors_sorting)) },
|
||||
)
|
||||
|
||||
|
@ -124,8 +151,8 @@ fun SensorsPage(navController: NavController) {
|
|||
}
|
||||
}
|
||||
|
||||
if (filterShown) {
|
||||
ModalBottomSheet(onDismissRequest = { filterShown = false }) {
|
||||
if (filterShow) {
|
||||
ModalBottomSheet(onDismissRequest = { filterShow = false }) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
@ -138,27 +165,105 @@ fun SensorsPage(navController: NavController) {
|
|||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.padding(horizontal = 4.dp),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
.fillMaxWidth(),
|
||||
) {
|
||||
items(filterItems) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Checkbox(
|
||||
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
|
||||
}
|
||||
)
|
||||
}
|
||||
FilterCheckbox(
|
||||
checked = it.enabled.value,
|
||||
onCheckedChange = { it.enabled.value = !it.enabled.value },
|
||||
stringRes = it.stringRes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sortingShow) {
|
||||
ModalBottomSheet(onDismissRequest = { sortingShow = false }) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.sensors_sort_title),
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight(500),
|
||||
)
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
.fillMaxWidth(),
|
||||
) {
|
||||
items(sortingTypes) {
|
||||
FilterRadioButton(
|
||||
selected = (sortingType == it.sortingType),
|
||||
onClick = { sortingType = it.sortingType },
|
||||
stringRes = it.stringRes,
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
FilterCheckbox(
|
||||
checked = sortingDesc,
|
||||
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() },
|
||||
)
|
||||
}
|
||||
}
|
|
@ -43,4 +43,13 @@
|
|||
<string name="filter_water_meter">Счётчик воды</string>
|
||||
<string name="filter_time">Время работы</string>
|
||||
<string name="sensors_filter_title">Тип датчиков</string>
|
||||
<string name="sort_distance">Расстояние</string>
|
||||
<string name="sort_type">Тип датчика</string>
|
||||
<string name="sort_update_time">Время последнего обновления</string>
|
||||
<string name="sort_name">Название</string>
|
||||
<string name="sort_value">Данные</string>
|
||||
<string name="sort_option_desc">По убыванию</string>
|
||||
<string name="sort_option_fav">Избранные сверху</string>
|
||||
<string name="sort_option_mine">Мои датчики сверху</string>
|
||||
<string name="sensors_sort_title">Сортировка</string>
|
||||
</resources>
|
|
@ -1,5 +1,5 @@
|
|||
[versions]
|
||||
agp = "8.2.0-alpha06"
|
||||
agp = "8.2.0-alpha07"
|
||||
kotlin = "1.8.10"
|
||||
core-ktx = "1.9.0"
|
||||
junit = "4.13.2"
|
||||
|
|
Loading…
Add table
Reference in a new issue