Compare commits
No commits in common. "9c6be5d8c5df82c46b0b712914eae0fc86ea0eab" and "5639ebd4cda2c3f2dd0d16ba48d78f45fa337c58" have entirely different histories.
9c6be5d8c5
...
5639ebd4cd
3 changed files with 24 additions and 138 deletions
|
@ -14,14 +14,13 @@ import androidx.compose.material3.Checkbox
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FilterChip
|
import androidx.compose.material3.FilterChip
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.RadioButton
|
|
||||||
import androidx.compose.material3.SearchBar
|
import androidx.compose.material3.SearchBar
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
@ -41,39 +40,13 @@ data class SensorFilter(
|
||||||
var enabled: MutableState<Boolean> = mutableStateOf(false),
|
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
|
@ExperimentalMaterial3Api
|
||||||
@Composable
|
@Composable
|
||||||
fun SensorsPage(navController: NavController) {
|
fun SensorsPage(navController: NavController) {
|
||||||
var searchQuery by remember { mutableStateOf("") }
|
var searchQuery by remember { mutableStateOf("") }
|
||||||
var searchActive by remember { mutableStateOf(false) }
|
var searchActive by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
var sortingShow by remember { mutableStateOf(false) }
|
var filterShown 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) }
|
var filterMine by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val filterItems = remember {
|
val filterItems = remember {
|
||||||
|
@ -133,12 +106,12 @@ fun SensorsPage(navController: NavController) {
|
||||||
modifier = Modifier.padding(horizontal = 8.dp),
|
modifier = Modifier.padding(horizontal = 8.dp),
|
||||||
) {
|
) {
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = { filterShow = true },
|
onClick = { filterShown = true },
|
||||||
label = { Text(text = stringResource(R.string.sensors_filter)) },
|
label = { Text(text = stringResource(R.string.sensors_filter)) },
|
||||||
)
|
)
|
||||||
|
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = { sortingShow = true },
|
onClick = { },
|
||||||
label = { Text(text = stringResource(R.string.sensors_sorting)) },
|
label = { Text(text = stringResource(R.string.sensors_sorting)) },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -151,8 +124,8 @@ fun SensorsPage(navController: NavController) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filterShow) {
|
if (filterShown) {
|
||||||
ModalBottomSheet(onDismissRequest = { filterShow = false }) {
|
ModalBottomSheet(onDismissRequest = { filterShown = false }) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
@ -165,105 +138,27 @@ fun SensorsPage(navController: NavController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier.padding(horizontal = 4.dp),
|
||||||
.padding(horizontal = 4.dp)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
) {
|
) {
|
||||||
items(filterItems) {
|
items(filterItems) {
|
||||||
FilterCheckbox(
|
Row(
|
||||||
checked = it.enabled.value,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
onCheckedChange = { it.enabled.value = !it.enabled.value },
|
) {
|
||||||
stringRes = it.stringRes,
|
Checkbox(
|
||||||
)
|
checked = it.enabled.value,
|
||||||
}
|
onCheckedChange = { checked ->
|
||||||
}
|
it.enabled.value = checked
|
||||||
}
|
},
|
||||||
}
|
)
|
||||||
|
Text(
|
||||||
if (sortingShow) {
|
text = stringResource(id = it.stringRes),
|
||||||
ModalBottomSheet(onDismissRequest = { sortingShow = false }) {
|
modifier = Modifier.clickable {
|
||||||
Row(
|
it.enabled.value = !it.enabled.value
|
||||||
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,13 +43,4 @@
|
||||||
<string name="filter_water_meter">Счётчик воды</string>
|
<string name="filter_water_meter">Счётчик воды</string>
|
||||||
<string name="filter_time">Время работы</string>
|
<string name="filter_time">Время работы</string>
|
||||||
<string name="sensors_filter_title">Тип датчиков</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>
|
</resources>
|
|
@ -1,5 +1,5 @@
|
||||||
[versions]
|
[versions]
|
||||||
agp = "8.2.0-alpha07"
|
agp = "8.2.0-alpha06"
|
||||||
kotlin = "1.8.10"
|
kotlin = "1.8.10"
|
||||||
core-ktx = "1.9.0"
|
core-ktx = "1.9.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
|
|
Loading…
Add table
Reference in a new issue