From 80f8cc77b665651eac050a8735ba5d2e97bc18b5 Mon Sep 17 00:00:00 2001 From: mezhendosina Date: Wed, 21 Jun 2023 14:33:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=92=20SensorsScreen=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=D0=B0=20=D0=B2=20SettingsScreen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/sensorsScreen/SensorsScreen.kt | 221 +++++++++--------- 1 file changed, 108 insertions(+), 113 deletions(-) diff --git a/app/src/main/java/ru/nm17/narodmon/ui/sensorsScreen/SensorsScreen.kt b/app/src/main/java/ru/nm17/narodmon/ui/sensorsScreen/SensorsScreen.kt index d40161b..60ec870 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/sensorsScreen/SensorsScreen.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/sensorsScreen/SensorsScreen.kt @@ -14,13 +14,16 @@ import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons 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.Check import androidx.compose.material.icons.rounded.Person +import androidx.compose.material.icons.rounded.Settings import androidx.compose.material3.BottomSheetScaffold import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FilterChip import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField 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.SensorSortingUiEntity 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.toChipTitle @OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @Composable -fun SensorsScreen(navController: NavController) { +fun SensorsScreen(navController: NavController, onSettingsClick: () -> Unit) { val coroutineScope = rememberCoroutineScope() var searchQuery by remember { mutableStateOf("") } @@ -119,108 +123,100 @@ fun SensorsScreen(navController: NavController) { mutableStateOf(SheetHeight.ExtraExpanded) } - BottomSheetScaffold( - modifier = Modifier.fillMaxSize(), - sheetPeekHeight = when (sheetHeight) { - SheetHeight.ExtraExpanded -> 256.dp - SheetHeight.Expanded -> 128.dp - SheetHeight.Hidden -> 0.dp - }, - scaffoldState = scaffoldState, - sheetContent = { - AnimatedVisibility(visible = scaffoldState.bottomSheetState.currentValue == SheetValue.Expanded) { - OutlinedTextField( - value = searchQuery, - onValueChange = { searchQuery = it }, - placeholder = { Text(stringResource(R.string.search)) }, - shape = SearchBarDefaults.inputFieldShape, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp, vertical = 8.dp) - ) - } - - LazyRow( - horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally), + BottomSheetScaffold(modifier = Modifier.fillMaxSize(), sheetPeekHeight = when (sheetHeight) { + SheetHeight.ExtraExpanded -> 256.dp + SheetHeight.Expanded -> 128.dp + SheetHeight.Hidden -> 0.dp + }, scaffoldState = scaffoldState, sheetContent = { + AnimatedVisibility(visible = scaffoldState.bottomSheetState.currentValue == SheetValue.Expanded) { + OutlinedTextField( + value = searchQuery, + onValueChange = { searchQuery = it }, + placeholder = { Text(stringResource(R.string.search)) }, + shape = SearchBarDefaults.inputFieldShape, modifier = Modifier .fillMaxWidth() - .padding(horizontal = 16.dp), - ) { - item { - FilterChip( - selected = false, - onClick = { filterShow = true }, - leadingIcon = { - Icon( - painter = painterResource(id = R.drawable.ic_filter), - contentDescription = stringResource(id = R.string.sensors_filter) - ) - }, - trailingIcon = { -// Icon( -// Icons.Filled.ArrowDropDown, -// "", -// tint = MaterialTheme.colorScheme.onBackground -// ) - }, + .padding(horizontal = 8.dp, vertical = 8.dp) + ) + } - label = { Text(text = stringResource(R.string.sensors_filter)) }, - ) - } - item { - FilterChip( - selected = sortingType.sortingType != SortingTypes.DISTANCE, - onClick = { sortingShow = true }, - leadingIcon = { - Icon( - painter = painterResource(id = R.drawable.ic_sort), - contentDescription = stringResource(id = R.string.sensors_sorting) - ) - }, - trailingIcon = { + LazyRow( + horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + ) { + item { + FilterChip( + selected = false, + onClick = { filterShow = true }, + leadingIcon = { + Icon( + painter = painterResource(id = R.drawable.ic_filter), + contentDescription = stringResource(id = R.string.sensors_filter) + ) + }, + trailingIcon = { // Icon( // Icons.Filled.ArrowDropDown, // "", // tint = MaterialTheme.colorScheme.onBackground // ) - }, - label = { - Text( - text = stringResource( - if (sortingType.sortingType == SortingTypes.DISTANCE) R.string.sensors_sorting - else sortingType.stringRes - ).toChipTitle(), + }, + + label = { Text(text = stringResource(R.string.sensors_filter)) }, + ) + } + item { + FilterChip(selected = sortingType.sortingType != SortingTypes.DISTANCE, + onClick = { sortingShow = true }, + leadingIcon = { + Icon( + painter = painterResource(id = R.drawable.ic_sort), + contentDescription = stringResource(id = R.string.sensors_sorting) + ) + }, + trailingIcon = { +// Icon( +// Icons.Filled.ArrowDropDown, +// "", +// tint = MaterialTheme.colorScheme.onBackground +// ) + }, + label = { + Text( + text = stringResource( + if (sortingType.sortingType == SortingTypes.DISTANCE) R.string.sensors_sorting + else sortingType.stringRes + ).toChipTitle(), + ) + }) + } + + item { + FilterChip( + selected = filterMine, + onClick = { filterMine = !filterMine }, + leadingIcon = { + if (filterMine) { + Icon( + Icons.Rounded.Check, contentDescription = "" ) } - ) - } - - item { - FilterChip( - selected = filterMine, - onClick = { filterMine = !filterMine }, - leadingIcon = { - if (filterMine) { - Icon( - Icons.Rounded.Check, - contentDescription = "" - ) - } - }, - label = { Text(text = stringResource(R.string.sensors_mine)) }, - ) - } - } - - LazyColumn( - modifier = Modifier.fillMaxHeight(), - ) { - items(sensorEntities) { sensor -> - SensorItem(sensor) - } + }, + label = { Text(text = stringResource(R.string.sensors_mine)) }, + ) } } - ) { + + LazyColumn( + modifier = Modifier.fillMaxHeight(), + ) { + items(sensorEntities) { sensor -> + SensorItem(sensor) + } + } + }) { Box(modifier = Modifier.fillMaxSize()) { SearchBar( query = searchQuery, @@ -231,18 +227,24 @@ fun SensorsScreen(navController: NavController) { }, onQueryChange = { query -> searchQuery = query }, 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 .fillMaxWidth() .padding( horizontal = if (!searchActive) 8.dp else 0.dp, - vertical = if (!searchActive) 16.dp else 0.dp ) ) {} TileMap( - modifier = Modifier - .fillMaxSize() + modifier = Modifier.fillMaxSize() ) { sheetHeight = SheetHeight.Expanded // TODO придумать, чтобы менялось на SheetHeight.ExtraExpanded после взаимодействия с картой @@ -251,25 +253,18 @@ fun SensorsScreen(navController: NavController) { } } if (sortingShow) { - SortSensorsDialog( - sortingType, - onApply = { - sortingType = it - sortingShow = false - }, - onDismissRequest = { - sortingShow = false - } - ) + SortSensorsDialog(sortingType, onApply = { + sortingType = it + sortingShow = false + }, onDismissRequest = { + sortingShow = false + }) } if (filterShow) { - FilterSensorsDialog( - onApply = { - // TODO применение фильтров - filterShow = false - }, - onDismissRequest = { filterShow = false } - ) + FilterSensorsDialog(onApply = { + // TODO применение фильтров + filterShow = false + }, onDismissRequest = { filterShow = false }) } } @@ -277,6 +272,6 @@ fun SensorsScreen(navController: NavController) { @Composable fun PreviewNewSensors() { NarodMonTheme { - SensorsScreen(rememberNavController()) + SensorsScreen(rememberNavController()) {} } }