From 35bd573cb036a2ace2741eaad112ab4017e51f1e Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 5 Jun 2023 18:41:02 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D1=8B,=20hadlineT?= =?UTF-8?q?ext->Content=20(=D0=B8=D0=BD=D0=B0=D1=87=D0=B5=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=BB=D0=B4=D0=B8=D1=82=D1=81=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt | 9 ++------- .../main/java/ru/nm17/narodmon/ui/elements/Scaffolds.kt | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt b/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt index a525644..8085739 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/elements/AgreementDialog.kt @@ -2,9 +2,6 @@ package ru.nm17.narodmon.ui.elements -import android.content.Context -import android.content.Intent -import android.net.Uri import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding @@ -22,9 +19,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.activity.ComponentActivity import androidx.compose.ui.platform.LocalUriHandler -import androidx.core.content.ContextCompat.startActivity import ru.nm17.narodmon.R import kotlin.system.exitProcess @@ -40,7 +35,7 @@ fun AgreementDialog(onClick: () -> Unit) { Text(text = stringResource(id = R.string.agreement_dialog_text)) Divider(Modifier.padding(vertical = 8.dp)) ListItem( - headlineText = { + headlineContent = { Text( text = stringResource(id = R.string.privacy_policy), style = MaterialTheme.typography.titleSmall @@ -56,7 +51,7 @@ fun AgreementDialog(onClick: () -> Unit) { ) ListItem( - headlineText = { + headlineContent = { Text( text = stringResource(id = R.string.user_agreement), style = MaterialTheme.typography.titleSmall diff --git a/app/src/main/java/ru/nm17/narodmon/ui/elements/Scaffolds.kt b/app/src/main/java/ru/nm17/narodmon/ui/elements/Scaffolds.kt index f4b2e70..ac1aa09 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/elements/Scaffolds.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/elements/Scaffolds.kt @@ -27,7 +27,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import androidx.navigation.compose.NavHost import androidx.navigation.compose.rememberNavController import kotlinx.coroutines.launch -- 2.45.2 From 96d7819d00ee84d1ec9fb2ffb10b60a96bdf83d4 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 5 Jun 2023 18:43:51 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=20=D1=81=D0=B5=D0=BD=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20(=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0=20=D1=82=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D1=82),=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82?= =?UTF-8?q?=D1=80-=D1=87=D0=B8=D0=BF=D1=8B=20=D1=83=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20composable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 3 +- app/src/main/AndroidManifest.xml | 2 + .../java/ru/nm17/narodmon/ui/pages/Sensors.kt | 63 ++++++++++++++----- .../narodmon/ui/viewmodel/MapViewModel.kt | 21 +++++++ app/src/main/res/values/strings.xml | 3 + 5 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 217e093..0f882c9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -119,5 +119,6 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") - + // Map Compose library + implementation("ovh.plrapps:mapcompose:2.7.1") } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5f5c06a..5c7e740 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + Boolean, + updateFilter: () -> Unit, +) { + FilterChip( + selected = checkFilter(), + onClick = updateFilter, + label = { Text(name) }, + ) } \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt new file mode 100644 index 0000000..b95270d --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt @@ -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) + } + ) +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 50cd33f..e6c67e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,4 +15,7 @@ Примите необходимые соглашения Сенсоры Ожидаю соглашение пользователя + Все + Термометры + Камеры \ No newline at end of file -- 2.45.2 From 266e2001f2f8fc79984ed184dc6edcc104c8ab9a Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 5 Jun 2023 18:59:23 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9D=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=87?= =?UTF-8?q?=D0=B8=D0=B9=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=BA=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt index b95270d..7c89bd4 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt @@ -10,7 +10,8 @@ import java.net.URL class MapViewModel : ViewModel() { private val tileStreamProvider = TileStreamProvider { row, col, zoom -> - URL("https://tile.openstreetmap.org/${zoom}/${row}/${col}").openStream() + URL("https://tile.openstreetmap.org/${zoom}/${row}/${col}.png").openStream() + //URL("https://tile2.maps.2gis.com/poi?x=${row}&y=${col}&z=${zoom}&v=1&ts=online_sd").openStream() } val state: MapState by mutableStateOf( -- 2.45.2 From 03a758673bc449c1213e1f5aee363c8050a0fa92 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 5 Jun 2023 20:11:42 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9A=D0=B0=D1=80=D1=82=D0=B0=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D1=83=D1=80?= =?UTF-8?q?=D0=B0!=20`URL.openStream`=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=91=D0=BD=20=D0=BD=D0=B0=20Ktor,=20=D0=BF=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=80=D0=B0=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D1=80=D1=8B=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B0=20=D1=81=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 5 +++++ .../java/ru/nm17/narodmon/ui/pages/Sensors.kt | 9 ++++++++- .../nm17/narodmon/ui/viewmodel/MapViewModel.kt | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0f882c9..f7f7827 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -119,6 +119,11 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") + // Ktor + val ktor_version = "2.3.1" + implementation("io.ktor:ktor-client-core:$ktor_version") + implementation("io.ktor:ktor-client-cio:$ktor_version") + // Map Compose library implementation("ovh.plrapps:mapcompose:2.7.1") } \ No newline at end of file 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 d0b0d76..b8037b9 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 @@ -3,6 +3,7 @@ package ru.nm17.narodmon.ui.pages import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FilterChip @@ -13,6 +14,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.navigation.NavController @@ -31,11 +33,16 @@ fun SensorsPage(navController: NavController) { val mapVM by remember { mutableStateOf(MapViewModel()) } var filter by remember { mutableStateOf(SensorsFilter.All) } + val scrConfig = LocalConfiguration.current + val scrHalfHeight = scrConfig.screenHeightDp / 2 + GenericNavScaffold( title = { Text(text = stringResource(R.string.sensors_page_title)) } ) { Column(modifier = Modifier.padding(it)) { - MapUI(state = mapVM.state) + + MapUI(state = mapVM.state, modifier = Modifier.height(scrHalfHeight.dp)) + Row( modifier = Modifier.padding(horizontal = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), diff --git a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt index 7c89bd4..e04f52c 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt @@ -3,20 +3,32 @@ package ru.nm17.narodmon.ui.viewmodel import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel +import io.ktor.client.HttpClient +import io.ktor.client.engine.cio.CIO +import io.ktor.client.request.get +import io.ktor.client.statement.bodyAsChannel +import io.ktor.utils.io.jvm.javaio.toInputStream import ovh.plrapps.mapcompose.api.addLayer import ovh.plrapps.mapcompose.core.TileStreamProvider import ovh.plrapps.mapcompose.ui.state.MapState +import java.io.InputStream import java.net.URL class MapViewModel : ViewModel() { + private val client = HttpClient(CIO) + private val tileStreamProvider = TileStreamProvider { row, col, zoom -> - URL("https://tile.openstreetmap.org/${zoom}/${row}/${col}.png").openStream() - //URL("https://tile2.maps.2gis.com/poi?x=${row}&y=${col}&z=${zoom}&v=1&ts=online_sd").openStream() + requestTile(row, col, zoom) } val state: MapState by mutableStateOf( - MapState(4, 4, 4096).apply { + MapState(4, 4096, 4096).apply { addLayer(tileStreamProvider) } ) + + private suspend fun requestTile(row: Int, col: Int, zoom: Int): InputStream { + val response = client.get("https://tile.openstreetmap.org/${zoom}/${col}/${row}.png") + return response.bodyAsChannel().toInputStream() + } } \ No newline at end of file -- 2.45.2 From 8a9ddbc27ce3cafca98ea93a6b4af0d47970dffe Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 5 Jun 2023 22:15:40 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=20=D0=BA=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B8=20=D0=B7=D1=83=D0=BC,=20=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D1=80=20=D1=83=D1=81=D0=BA=D0=BE=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=20100500=20=D1=80=D0=B0=D0=B7=20=D0=B7=D0=B0=20?= =?UTF-8?q?=D1=81=D1=87=D1=91=D1=82=20`workerCount`,=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=B4=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B0=D0=B2=D1=82=D0=BE=D1=83=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B7=D0=B8=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=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 | 17 +++++++++++++++-- .../nm17/narodmon/ui/viewmodel/MapViewModel.kt | 9 +++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) 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 b8037b9..6bd37c1 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 @@ -9,15 +9,19 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FilterChip import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect 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.geometry.Offset import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.navigation.NavController +import ovh.plrapps.mapcompose.api.scale +import ovh.plrapps.mapcompose.api.setScroll import ovh.plrapps.mapcompose.ui.MapUI import ru.nm17.narodmon.R import ru.nm17.narodmon.ui.elements.GenericNavScaffold @@ -34,14 +38,20 @@ fun SensorsPage(navController: NavController) { var filter by remember { mutableStateOf(SensorsFilter.All) } val scrConfig = LocalConfiguration.current - val scrHalfHeight = scrConfig.screenHeightDp / 2 + val mapHeight = scrConfig.screenHeightDp / 3 + + LaunchedEffect(mapVM) { + // TODO: Подгружать сохранённую позицию + mapVM.state.setScroll(Offset(28702.6F, 14787.6F)) + mapVM.state.scale = 1.4658884F + } GenericNavScaffold( title = { Text(text = stringResource(R.string.sensors_page_title)) } ) { Column(modifier = Modifier.padding(it)) { - MapUI(state = mapVM.state, modifier = Modifier.height(scrHalfHeight.dp)) + MapUI(state = mapVM.state, modifier = Modifier.height(mapHeight.dp)) Row( modifier = Modifier.padding(horizontal = 8.dp), @@ -65,6 +75,9 @@ fun SensorsPage(navController: NavController) { updateFilter = { filter = SensorsFilter.Camera }, ) } + + //Text(mapVM.state.scroll.toString()) + //Text(mapVM.state.scale.toString()) } } } diff --git a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt index e04f52c..4d330ba 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/viewmodel/MapViewModel.kt @@ -12,7 +12,6 @@ import ovh.plrapps.mapcompose.api.addLayer import ovh.plrapps.mapcompose.core.TileStreamProvider import ovh.plrapps.mapcompose.ui.state.MapState import java.io.InputStream -import java.net.URL class MapViewModel : ViewModel() { private val client = HttpClient(CIO) @@ -21,8 +20,14 @@ class MapViewModel : ViewModel() { requestTile(row, col, zoom) } + private val mapSize = 32768 val state: MapState by mutableStateOf( - MapState(4, 4096, 4096).apply { + MapState( + levelCount = 8, + fullWidth = mapSize, + fullHeight = mapSize, + workerCount = 16, + ).apply { addLayer(tileStreamProvider) } ) -- 2.45.2