From 9739d1cdfe50c5320e75e1f8f65b30e907fbb7ef Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Wed, 7 Jun 2023 21:07:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=20UI=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B4=D0=B0=D1=82=D1=87=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/nm17/narodmon/ui/pages/Sensors.kt | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/app/src/main/java/ru/nm17/narodmon/ui/pages/Sensors.kt b/app/src/main/java/ru/nm17/narodmon/ui/pages/Sensors.kt index 5b104ab..3c2938a 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/pages/Sensors.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/pages/Sensors.kt @@ -4,18 +4,24 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material3.AssistChip +import androidx.compose.material3.Card import androidx.compose.material3.Checkbox +import androidx.compose.material3.Divider +import androidx.compose.material3.ElevatedCard import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FilterChip +import androidx.compose.material3.ListItem import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.RadioButton import androidx.compose.material3.SearchBar +import androidx.compose.material3.Shapes import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState @@ -25,17 +31,39 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController import ru.nm17.narodmon.R +import ru.nm17.narodmon.db.entities.SensorType import ru.nm17.narodmon.ui.elements.GenericNavScaffold import ru.nm17.narodmon.ui.elements.TileMap +data class Sensor( + // TODO: Вынести в отдельный класс, и явно не в директорию `ui` + val id: Int, + val type: SensorType, + val deviceName: String, + val deviceOwner: Int, + val name: String, + val favorite: Boolean, + val public: Boolean, + val mine: Boolean, + val location: String, + val distance: Double, // километры + val value: Double, + val unit: String, + val changed: Int, +) + data class SensorFilter( + // TODO: Можно попробовать объединить с db/SensorType.kt val stringRes: Int, val code: Int, var enabled: MutableState = mutableStateOf(false), @@ -108,6 +136,39 @@ fun SensorsPage(navController: NavController) { ) } + val sensors = remember { + mutableListOf( + // TODO: загружать датчики с сервера. Этот список -- для макета + Sensor( + 0, + SensorType(0, "temp", "C"), + "device0", 0, + "sensor0", favorite = true, + public = true, mine = false, + "Москва", 0.4, + 20.0, "C", 1686142800, + ), + Sensor( + 1, + SensorType(4, "humidity", "%"), + "device1", 0, + "sensor1", favorite = true, + public = false, mine = false, + "Подмосковье", 1.1, + 39.0, "%", 1686142800, + ), + Sensor( + 2, + SensorType(11, "wind speed", "m/s"), + "device2", 1, + "sensor2", favorite = false, + public = true, mine = true, + "Москва", 0.01, + 3.2, "m/s", 1686142800, + ), + ) + } + val scrConfig = LocalConfiguration.current val mapHeight = scrConfig.screenHeightDp / 3 @@ -148,6 +209,16 @@ fun SensorsPage(navController: NavController) { label = { Text(text = stringResource(R.string.sensors_mine)) }, ) } + + Divider() + + LazyColumn( + modifier = Modifier.fillMaxHeight(), + ) { + items(sensors) { sensor -> + SensorItem(sensor) + } + } } } @@ -234,6 +305,33 @@ fun SensorsPage(navController: NavController) { } } +@ExperimentalMaterial3Api +@Composable +fun SensorItem(sensor: Sensor) { + ListItem( + overlineContent = { Text(text = "${sensor.deviceName} от ${sensor.deviceOwner}") }, + headlineContent = { Text(text = sensor.type.name) }, + supportingContent = { Text(text = sensor.name) }, + trailingContent = { + Column( + horizontalAlignment = Alignment.End, + ) { + Text(text = "${sensor.distance} km") + ElevatedCard( + shape = RectangleShape, + ) { + Text( + text = "${sensor.value} ${sensor.unit}", + fontFamily = FontFamily.Monospace, + fontSize = 14.sp, + modifier = Modifier.padding(horizontal = 3.dp, vertical = 1.dp) + ) + } + } + } + ) +} + @ExperimentalMaterial3Api @Composable fun FilterCheckbox(checked: Boolean, onCheckedChange: () -> Unit, stringRes: Int) {