From 82dce30739af124b2538ab5eb1bd2e816fe64ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosson?= Date: Fri, 13 Jun 2025 13:50:28 +0200 Subject: [PATCH] feat: show node details by long-pressing a node marker on map (#2104) --- .../geeksville/mesh/navigation/MapRoutes.kt | 52 +++++++++++++++++++ .../geeksville/mesh/navigation/NavGraph.kt | 7 +-- .../main/java/com/geeksville/mesh/ui/Main.kt | 3 +- .../com/geeksville/mesh/ui/map/MapView.kt | 6 +++ 4 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/navigation/MapRoutes.kt diff --git a/app/src/main/java/com/geeksville/mesh/navigation/MapRoutes.kt b/app/src/main/java/com/geeksville/mesh/navigation/MapRoutes.kt new file mode 100644 index 000000000..653d0836b --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/navigation/MapRoutes.kt @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Meshtastic LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.geeksville.mesh.navigation + +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavHostController +import androidx.navigation.compose.composable +import androidx.navigation.compose.navigation +import com.geeksville.mesh.model.UIViewModel +import com.geeksville.mesh.ui.map.MapView +import kotlinx.serialization.Serializable + +sealed class MapRoutes { + @Serializable + data object Map : Route + + @Serializable + data object MapGraph : Graph +} + +fun NavGraphBuilder.mapGraph( + navController: NavHostController, + uiViewModel: UIViewModel, +) { + navigation( + startDestination = MapRoutes.Map, + ) { + composable { + MapView( + model = uiViewModel, + navigateToNodeDetails = { + navController.navigate(NodesRoutes.NodeDetail(it)) + }, + ) + } + } +} diff --git a/app/src/main/java/com/geeksville/mesh/navigation/NavGraph.kt b/app/src/main/java/com/geeksville/mesh/navigation/NavGraph.kt index 186a48cbe..9886ceb9c 100644 --- a/app/src/main/java/com/geeksville/mesh/navigation/NavGraph.kt +++ b/app/src/main/java/com/geeksville/mesh/navigation/NavGraph.kt @@ -31,7 +31,6 @@ import com.geeksville.mesh.R import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.ui.TopLevelDestination.Companion.isTopLevel import com.geeksville.mesh.ui.debug.DebugScreen -import com.geeksville.mesh.ui.map.MapView import kotlinx.serialization.Serializable enum class AdminRoute(@StringRes val title: Int) { @@ -47,10 +46,6 @@ const val DEEP_LINK_BASE_URI = "meshtastic://meshtastic" sealed interface Graph : Route @Serializable sealed interface Route { - - @Serializable - data object Map : Route - @Serializable data object DebugPanel : Route } @@ -92,7 +87,7 @@ fun NavGraph( ) { contactsGraph(navController, uIViewModel) nodesGraph(navController, uIViewModel,) - composable { MapView(uIViewModel) } + mapGraph(navController, uIViewModel) channelsGraph(navController, uIViewModel) connectionsGraph(navController, uIViewModel) composable { DebugScreen() } diff --git a/app/src/main/java/com/geeksville/mesh/ui/Main.kt b/app/src/main/java/com/geeksville/mesh/ui/Main.kt index 4ad55cc17..edb95213b 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/Main.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/Main.kt @@ -77,6 +77,7 @@ import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.navigation.ChannelsRoutes import com.geeksville.mesh.navigation.ConnectionsRoutes import com.geeksville.mesh.navigation.ContactsRoutes +import com.geeksville.mesh.navigation.MapRoutes import com.geeksville.mesh.navigation.NavGraph import com.geeksville.mesh.navigation.NodesRoutes import com.geeksville.mesh.navigation.RadioConfigRoutes @@ -92,7 +93,7 @@ import com.geeksville.mesh.ui.debug.DebugMenuActions enum class TopLevelDestination(@StringRes val label: Int, val icon: ImageVector, val route: Route) { Contacts(R.string.contacts, Icons.AutoMirrored.TwoTone.Chat, ContactsRoutes.Contacts), Nodes(R.string.nodes, Icons.TwoTone.People, NodesRoutes.Nodes), - Map(R.string.map, Icons.TwoTone.Map, Route.Map), + Map(R.string.map, Icons.TwoTone.Map, MapRoutes.Map), Channels(R.string.channels, Icons.TwoTone.Contactless, ChannelsRoutes.Channels), Connections(R.string.connections, Icons.TwoTone.CloudOff, ConnectionsRoutes.Connections), ; diff --git a/app/src/main/java/com/geeksville/mesh/ui/map/MapView.kt b/app/src/main/java/com/geeksville/mesh/ui/map/MapView.kt index 4f436a1fc..afb856560 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/map/MapView.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/map/MapView.kt @@ -211,9 +211,11 @@ private fun Context.purgeTileSource(onResult: (String) -> Unit) { builder.show() } +@Suppress("CyclomaticComplexMethod", "LongMethod") @Composable fun MapView( model: UIViewModel = viewModel(), + navigateToNodeDetails: (Int) -> Unit, ) { var mapFilterExpanded by remember { mutableStateOf(false) } @@ -344,6 +346,10 @@ fun MapView( } else { setPrecisionBits(p.precisionBits) } + setOnLongClickListener { + navigateToNodeDetails(node.num) + true + } } } }