dc09-sensors2 #5
1 changed files with 98 additions and 0 deletions
|
@ -4,18 +4,24 @@ import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.AssistChip
|
import androidx.compose.material3.AssistChip
|
||||||
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.Checkbox
|
import androidx.compose.material3.Checkbox
|
||||||
|
import androidx.compose.material3.Divider
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FilterChip
|
import androidx.compose.material3.FilterChip
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.RadioButton
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.SearchBar
|
import androidx.compose.material3.SearchBar
|
||||||
|
import androidx.compose.material3.Shapes
|
||||||
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
|
||||||
|
@ -25,17 +31,39 @@ 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
|
||||||
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import ru.nm17.narodmon.R
|
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.GenericNavScaffold
|
||||||
import ru.nm17.narodmon.ui.elements.TileMap
|
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(
|
data class SensorFilter(
|
||||||
|
// TODO: Можно попробовать объединить с db/SensorType.kt
|
||||||
val stringRes: Int,
|
val stringRes: Int,
|
||||||
val code: Int,
|
val code: Int,
|
||||||
var enabled: MutableState<Boolean> = mutableStateOf(false),
|
var enabled: MutableState<Boolean> = 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 scrConfig = LocalConfiguration.current
|
||||||
val mapHeight = scrConfig.screenHeightDp / 3
|
val mapHeight = scrConfig.screenHeightDp / 3
|
||||||
|
|
||||||
|
@ -148,6 +209,16 @@ fun SensorsPage(navController: NavController) {
|
||||||
label = { Text(text = stringResource(R.string.sensors_mine)) },
|
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
|
@ExperimentalMaterial3Api
|
||||||
@Composable
|
@Composable
|
||||||
fun FilterCheckbox(checked: Boolean, onCheckedChange: () -> Unit, stringRes: Int) {
|
fun FilterCheckbox(checked: Boolean, onCheckedChange: () -> Unit, stringRes: Int) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue