From 1811a22a5a2acca2f9e4366dee1333b71c7cad1e Mon Sep 17 00:00:00 2001 From: mezhendosina Date: Mon, 12 Jun 2023 15:41:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=BE=D1=80=D0=B3=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{elements => dialogs}/AgreementDialog.kt | 14 ++++- .../narodmon/ui/elements/FilterCheckbox.kt | 31 ++++++++++ .../narodmon/ui/elements/FilterRadioButton.kt | 29 ++++++++++ .../nm17/narodmon/ui/elements/SensorItem.kt | 56 +++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) rename app/src/main/java/ru/nm17/narodmon/ui/{elements => dialogs}/AgreementDialog.kt (92%) create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/elements/FilterCheckbox.kt create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/elements/FilterRadioButton.kt create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/elements/SensorItem.kt diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt b/app/src/main/java/ru/nm17/narodmon/ui/dialogs/AgreementDialog.kt similarity index 92% rename from app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt rename to app/src/main/java/ru/nm17/narodmon/ui/dialogs/AgreementDialog.kt index fe97557..0daf706 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/dialogs/AgreementDialog.kt @@ -1,6 +1,6 @@ @file:OptIn(ExperimentalMaterial3Api::class) -package ru.nm17.narodmon.ui.elements +package ru.nm17.narodmon.ui.dialogs import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column @@ -20,7 +20,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.tooling.preview.Preview import ru.nm17.narodmon.R +import ru.nm17.narodmon.ui.theme.NarodMonTheme import kotlin.system.exitProcess @OptIn(ExperimentalMaterial3Api::class) @@ -83,4 +85,14 @@ fun AgreementDialog(modifier: Modifier = Modifier, onClick: () -> Unit) { modifier = modifier ) +} + +@Preview +@Composable +fun PreviewAgreementDialog(){ + NarodMonTheme { + AgreementDialog { + + } + } } \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterCheckbox.kt b/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterCheckbox.kt new file mode 100644 index 0000000..5f39e69 --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterCheckbox.kt @@ -0,0 +1,31 @@ +package ru.nm17.narodmon.ui.elements + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.Checkbox +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource + +@ExperimentalMaterial3Api +@Composable +fun FilterCheckbox(checked: Boolean, stringRes: Int, onCheckedChange: () -> Unit) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .clickable { onCheckedChange() } + ) { + Checkbox( + checked = checked, + onCheckedChange = { onCheckedChange() }, + ) + Text( + text = stringResource(id = stringRes), + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterRadioButton.kt b/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterRadioButton.kt new file mode 100644 index 0000000..86d90a4 --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/elements/FilterRadioButton.kt @@ -0,0 +1,29 @@ +package ru.nm17.narodmon.ui.elements + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.RadioButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource + +@ExperimentalMaterial3Api +@Composable +fun FilterRadioButton(selected: Boolean, onClick: () -> Unit, stringRes: Int) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .clickable { onClick.invoke() } + ) { + RadioButton( + selected = selected, + onClick = onClick, + ) + Text(text = stringResource(id = stringRes)) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/SensorItem.kt b/app/src/main/java/ru/nm17/narodmon/ui/elements/SensorItem.kt new file mode 100644 index 0000000..8662d3f --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/elements/SensorItem.kt @@ -0,0 +1,56 @@ +package ru.nm17.narodmon.ui.elements + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.ElevatedCard +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ListItem +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import ru.nm17.narodmon.ui.entities.SensorEntity +import ru.nm17.narodmon.ui.iosevkaFamily + +@ExperimentalMaterial3Api +@Composable +fun SensorItem(sensorEntity: SensorEntity) { + ListItem( + overlineContent = { Text(text = "${sensorEntity.deviceName} от ${sensorEntity.deviceOwner}") }, + headlineContent = { Text(text = sensorEntity.type.name) }, + supportingContent = { Text(text = sensorEntity.name) }, + trailingContent = { + Column( + horizontalAlignment = Alignment.End, + ) { + Text(text = "${sensorEntity.distance} km") + Spacer(modifier = Modifier.size(2.dp)) + ElevatedCard( + shape = RectangleShape, + ) { + Text( + text = "${sensorEntity.value} ${sensorEntity.unit}", + fontFamily = iosevkaFamily, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + modifier = Modifier.padding(horizontal = 3.dp, vertical = 1.dp) + ) + } + } + } + ) +} + +@OptIn(ExperimentalMaterial3Api::class) +@Preview +@Composable +fun PreviewSensorItem() { +// SensorItem(SensorEntity(0, Se)) +} \ No newline at end of file