В SensorsScreen добавлена кнопка для перехода в SettingsScreen

This commit is contained in:
mezhendosina 2023-06-21 14:33:17 +05:00
parent 628b168bcf
commit 80f8cc77b6

View file

@ -14,13 +14,16 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.rounded.ArrowDropDown import androidx.compose.material.icons.rounded.ArrowDropDown
import androidx.compose.material.icons.rounded.Check import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.Person import androidx.compose.material.icons.rounded.Person
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material3.BottomSheetScaffold import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.SearchBar import androidx.compose.material3.SearchBar
@ -59,13 +62,14 @@ import ru.nm17.narodmon.ui.elements.TileMap
import ru.nm17.narodmon.ui.entities.SensorEntity import ru.nm17.narodmon.ui.entities.SensorEntity
import ru.nm17.narodmon.ui.entities.SensorSortingUiEntity import ru.nm17.narodmon.ui.entities.SensorSortingUiEntity
import ru.nm17.narodmon.ui.entities.SortingTypes import ru.nm17.narodmon.ui.entities.SortingTypes
import ru.nm17.narodmon.ui.navHost.MainScreenSealed
import ru.nm17.narodmon.ui.theme.NarodMonTheme import ru.nm17.narodmon.ui.theme.NarodMonTheme
import ru.nm17.narodmon.ui.toChipTitle import ru.nm17.narodmon.ui.toChipTitle
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
@Composable @Composable
fun SensorsScreen(navController: NavController) { fun SensorsScreen(navController: NavController, onSettingsClick: () -> Unit) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
var searchQuery by remember { mutableStateOf("") } var searchQuery by remember { mutableStateOf("") }
@ -119,15 +123,11 @@ fun SensorsScreen(navController: NavController) {
mutableStateOf(SheetHeight.ExtraExpanded) mutableStateOf(SheetHeight.ExtraExpanded)
} }
BottomSheetScaffold( BottomSheetScaffold(modifier = Modifier.fillMaxSize(), sheetPeekHeight = when (sheetHeight) {
modifier = Modifier.fillMaxSize(),
sheetPeekHeight = when (sheetHeight) {
SheetHeight.ExtraExpanded -> 256.dp SheetHeight.ExtraExpanded -> 256.dp
SheetHeight.Expanded -> 128.dp SheetHeight.Expanded -> 128.dp
SheetHeight.Hidden -> 0.dp SheetHeight.Hidden -> 0.dp
}, }, scaffoldState = scaffoldState, sheetContent = {
scaffoldState = scaffoldState,
sheetContent = {
AnimatedVisibility(visible = scaffoldState.bottomSheetState.currentValue == SheetValue.Expanded) { AnimatedVisibility(visible = scaffoldState.bottomSheetState.currentValue == SheetValue.Expanded) {
OutlinedTextField( OutlinedTextField(
value = searchQuery, value = searchQuery,
@ -168,8 +168,7 @@ fun SensorsScreen(navController: NavController) {
) )
} }
item { item {
FilterChip( FilterChip(selected = sortingType.sortingType != SortingTypes.DISTANCE,
selected = sortingType.sortingType != SortingTypes.DISTANCE,
onClick = { sortingShow = true }, onClick = { sortingShow = true },
leadingIcon = { leadingIcon = {
Icon( Icon(
@ -191,8 +190,7 @@ fun SensorsScreen(navController: NavController) {
else sortingType.stringRes else sortingType.stringRes
).toChipTitle(), ).toChipTitle(),
) )
} })
)
} }
item { item {
@ -202,8 +200,7 @@ fun SensorsScreen(navController: NavController) {
leadingIcon = { leadingIcon = {
if (filterMine) { if (filterMine) {
Icon( Icon(
Icons.Rounded.Check, Icons.Rounded.Check, contentDescription = ""
contentDescription = ""
) )
} }
}, },
@ -219,8 +216,7 @@ fun SensorsScreen(navController: NavController) {
SensorItem(sensor) SensorItem(sensor)
} }
} }
} }) {
) {
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
SearchBar( SearchBar(
query = searchQuery, query = searchQuery,
@ -231,18 +227,24 @@ fun SensorsScreen(navController: NavController) {
}, },
onQueryChange = { query -> searchQuery = query }, onQueryChange = { query -> searchQuery = query },
onSearch = { searchActive = false }, onSearch = { searchActive = false },
placeholder = { Text(stringResource(R.string.search)) }, placeholder = { Text(stringResource(R.string.search_sensors)) },
trailingIcon = {
IconButton(onClick = { onSettingsClick.invoke() }) {
Icon(
Icons.Outlined.Settings,
contentDescription = stringResource(R.string.settings)
)
}
},
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding( .padding(
horizontal = if (!searchActive) 8.dp else 0.dp, horizontal = if (!searchActive) 8.dp else 0.dp,
vertical = if (!searchActive) 16.dp else 0.dp
) )
) {} ) {}
TileMap( TileMap(
modifier = Modifier modifier = Modifier.fillMaxSize()
.fillMaxSize()
) { ) {
sheetHeight = sheetHeight =
SheetHeight.Expanded // TODO придумать, чтобы менялось на SheetHeight.ExtraExpanded после взаимодействия с картой SheetHeight.Expanded // TODO придумать, чтобы менялось на SheetHeight.ExtraExpanded после взаимодействия с картой
@ -251,25 +253,18 @@ fun SensorsScreen(navController: NavController) {
} }
} }
if (sortingShow) { if (sortingShow) {
SortSensorsDialog( SortSensorsDialog(sortingType, onApply = {
sortingType,
onApply = {
sortingType = it sortingType = it
sortingShow = false sortingShow = false
}, }, onDismissRequest = {
onDismissRequest = {
sortingShow = false sortingShow = false
} })
)
} }
if (filterShow) { if (filterShow) {
FilterSensorsDialog( FilterSensorsDialog(onApply = {
onApply = {
// TODO применение фильтров // TODO применение фильтров
filterShow = false filterShow = false
}, }, onDismissRequest = { filterShow = false })
onDismissRequest = { filterShow = false }
)
} }
} }
@ -277,6 +272,6 @@ fun SensorsScreen(navController: NavController) {
@Composable @Composable
fun PreviewNewSensors() { fun PreviewNewSensors() {
NarodMonTheme { NarodMonTheme {
SensorsScreen(rememberNavController()) SensorsScreen(rememberNavController()) {}
} }
} }