Добавлена карта на экран сенсоров (пока подгрузка тайлов не работает), фильтр-чипы убраны в отдельный composable
This commit is contained in:
parent
35bd573cb0
commit
96d7819d00
5 changed files with 75 additions and 17 deletions
|
@ -119,5 +119,6 @@ dependencies {
|
||||||
|
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
||||||
|
|
||||||
|
// Map Compose library
|
||||||
|
implementation("ovh.plrapps:mapcompose:2.7.1")
|
||||||
}
|
}
|
|
@ -2,6 +2,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.nm17.narodmon.ui.pages
|
package ru.nm17.narodmon.ui.pages
|
||||||
|
|
||||||
|
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.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
@ -7,40 +8,70 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FilterChip
|
import androidx.compose.material3.FilterChip
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import ru.nm17.narodmon.Greeting
|
import ovh.plrapps.mapcompose.ui.MapUI
|
||||||
import ru.nm17.narodmon.R
|
import ru.nm17.narodmon.R
|
||||||
import ru.nm17.narodmon.ui.elements.GenericNavScaffold
|
import ru.nm17.narodmon.ui.elements.GenericNavScaffold
|
||||||
|
import ru.nm17.narodmon.ui.viewmodel.MapViewModel
|
||||||
|
|
||||||
|
enum class SensorsFilter {
|
||||||
|
All, Thermometer, Camera,
|
||||||
|
}
|
||||||
|
|
||||||
@ExperimentalMaterial3Api
|
@ExperimentalMaterial3Api
|
||||||
@Composable
|
@Composable
|
||||||
fun SensorsPage(navController: NavController) {
|
fun SensorsPage(navController: NavController) {
|
||||||
|
val mapVM by remember { mutableStateOf(MapViewModel()) }
|
||||||
|
var filter by remember { mutableStateOf(SensorsFilter.All) }
|
||||||
|
|
||||||
GenericNavScaffold(
|
GenericNavScaffold(
|
||||||
title = { Text(text = stringResource(R.string.sensors_page_title)) }
|
title = { Text(text = stringResource(R.string.sensors_page_title)) }
|
||||||
) {
|
) {
|
||||||
Column {
|
Column(modifier = Modifier.padding(it)) {
|
||||||
Greeting("Hello sensors")
|
MapUI(state = mapVM.state)
|
||||||
Row {
|
Row(
|
||||||
FilterChip(
|
modifier = Modifier.padding(horizontal = 8.dp),
|
||||||
selected = true,
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
onClick = { },
|
) {
|
||||||
label = { Text("Temp") }
|
SensorsFilterChip(
|
||||||
|
name = stringResource(R.string.sensors_filter_all),
|
||||||
|
checkFilter = { filter == SensorsFilter.All },
|
||||||
|
updateFilter = { filter = SensorsFilter.All },
|
||||||
)
|
)
|
||||||
|
|
||||||
FilterChip(
|
SensorsFilterChip(
|
||||||
selected = false,
|
name = stringResource(R.string.sensors_filter_temp),
|
||||||
onClick = { },
|
checkFilter = { filter == SensorsFilter.Thermometer },
|
||||||
label = { Text("Abc") }
|
updateFilter = { filter = SensorsFilter.Thermometer },
|
||||||
)
|
)
|
||||||
|
|
||||||
FilterChip(
|
SensorsFilterChip(
|
||||||
selected = false,
|
name = stringResource(R.string.sensors_filter_camera),
|
||||||
onClick = { },
|
checkFilter = { filter == SensorsFilter.Camera },
|
||||||
label = { Text("Def") }
|
updateFilter = { filter = SensorsFilter.Camera },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun SensorsFilterChip(
|
||||||
|
name: String,
|
||||||
|
checkFilter: () -> Boolean,
|
||||||
|
updateFilter: () -> Unit,
|
||||||
|
) {
|
||||||
|
FilterChip(
|
||||||
|
selected = checkFilter(),
|
||||||
|
onClick = updateFilter,
|
||||||
|
label = { Text(name) },
|
||||||
|
)
|
||||||
}
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package ru.nm17.narodmon.ui.viewmodel
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import ovh.plrapps.mapcompose.api.addLayer
|
||||||
|
import ovh.plrapps.mapcompose.core.TileStreamProvider
|
||||||
|
import ovh.plrapps.mapcompose.ui.state.MapState
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
|
class MapViewModel : ViewModel() {
|
||||||
|
private val tileStreamProvider = TileStreamProvider { row, col, zoom ->
|
||||||
|
URL("https://tile.openstreetmap.org/${zoom}/${row}/${col}").openStream()
|
||||||
|
}
|
||||||
|
|
||||||
|
val state: MapState by mutableStateOf(
|
||||||
|
MapState(4, 4, 4096).apply {
|
||||||
|
addLayer(tileStreamProvider)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
|
@ -15,4 +15,7 @@
|
||||||
<string name="agreement_dialog_title">Примите необходимые соглашения</string>
|
<string name="agreement_dialog_title">Примите необходимые соглашения</string>
|
||||||
<string name="sensors_page_title">Сенсоры</string>
|
<string name="sensors_page_title">Сенсоры</string>
|
||||||
<string name="waiting_for_user_agreement">Ожидаю соглашение пользователя</string>
|
<string name="waiting_for_user_agreement">Ожидаю соглашение пользователя</string>
|
||||||
|
<string name="sensors_filter_all">Все</string>
|
||||||
|
<string name="sensors_filter_temp">Термометры</string>
|
||||||
|
<string name="sensors_filter_camera">Камеры</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Add table
Reference in a new issue