Compare commits

..

No commits in common. "9c6be5d8c5df82c46b0b712914eae0fc86ea0eab" and "5639ebd4cda2c3f2dd0d16ba48d78f45fa337c58" have entirely different histories.

3 changed files with 24 additions and 138 deletions

View file

@ -14,14 +14,13 @@ 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
@ -41,39 +40,13 @@ 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 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 filterShown by remember { mutableStateOf(false) }
var filterMine by remember { mutableStateOf(false) }
val filterItems = remember {
@ -133,12 +106,12 @@ fun SensorsPage(navController: NavController) {
modifier = Modifier.padding(horizontal = 8.dp),
) {
AssistChip(
onClick = { filterShow = true },
onClick = { filterShown = true },
label = { Text(text = stringResource(R.string.sensors_filter)) },
)
AssistChip(
onClick = { sortingShow = true },
onClick = { },
label = { Text(text = stringResource(R.string.sensors_sorting)) },
)
@ -151,8 +124,8 @@ fun SensorsPage(navController: NavController) {
}
}
if (filterShow) {
ModalBottomSheet(onDismissRequest = { filterShow = false }) {
if (filterShown) {
ModalBottomSheet(onDismissRequest = { filterShown = false }) {
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth(),
@ -165,105 +138,27 @@ fun SensorsPage(navController: NavController) {
}
LazyColumn(
modifier = Modifier
.padding(horizontal = 4.dp)
.fillMaxWidth(),
modifier = Modifier.padding(horizontal = 4.dp),
) {
items(filterItems) {
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,
)
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
}
)
}
}
}
}
}
}
@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

@ -43,13 +43,4 @@
<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>

View file

@ -1,5 +1,5 @@
[versions]
agp = "8.2.0-alpha07"
agp = "8.2.0-alpha06"
kotlin = "1.8.10"
core-ktx = "1.9.0"
junit = "4.13.2"