mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor(metrics/map): DRY up charts, decompose MapView monoliths, add test coverage (#5049)
This commit is contained in:
parent
56332f4d77
commit
520fa717a9
71 changed files with 3464 additions and 2169 deletions
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2025-2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.model
|
||||
|
||||
/**
|
||||
* Represents a traceroute result with forward and return routes as ordered lists of node nums.
|
||||
*
|
||||
* @property requestId The mesh packet request ID that initiated this traceroute.
|
||||
* @property forwardRoute Ordered node nums along the path towards the destination.
|
||||
* @property returnRoute Ordered node nums along the return path back to the originator.
|
||||
*/
|
||||
data class TracerouteOverlay(
|
||||
val requestId: Int,
|
||||
val forwardRoute: List<Int> = emptyList(),
|
||||
val returnRoute: List<Int> = emptyList(),
|
||||
) {
|
||||
/** All unique node nums involved in either route direction. */
|
||||
val relatedNodeNums: Set<Int> = (forwardRoute + returnRoute).toSet()
|
||||
|
||||
/** True if at least one route direction contains nodes. */
|
||||
val hasRoutes: Boolean
|
||||
get() = forwardRoute.isNotEmpty() || returnRoute.isNotEmpty()
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.model.util
|
||||
|
||||
/** Common geographic constants for coordinate conversions. */
|
||||
object GeoConstants {
|
||||
/** Multiplier to convert protobuf integer coordinates (1e-7 degree units) to decimal degrees. */
|
||||
const val DEG_D = 1e-7
|
||||
|
||||
/** Multiplier to convert protobuf integer heading values (1e-5 degree units) to decimal degrees. */
|
||||
const val HEADING_DEG = 1e-5
|
||||
|
||||
/** Mean radius of the Earth in meters, for haversine calculations. */
|
||||
const val EARTH_RADIUS_METERS = 6_371_000.0
|
||||
}
|
||||
|
|
@ -207,7 +207,7 @@ object DeepLinkRouter {
|
|||
private val nodeDetailSubRoutes: Map<String, (Int) -> Route> =
|
||||
mapOf(
|
||||
"device-metrics" to { destNum -> NodeDetailRoute.DeviceMetrics(destNum) },
|
||||
"map" to { destNum -> NodeDetailRoute.NodeMap(destNum) },
|
||||
"map" to { destNum -> NodeDetailRoute.PositionLog(destNum) },
|
||||
"position" to { destNum -> NodeDetailRoute.PositionLog(destNum) },
|
||||
"environment" to { destNum -> NodeDetailRoute.EnvironmentMetrics(destNum) },
|
||||
"signal" to { destNum -> NodeDetailRoute.SignalMetrics(destNum) },
|
||||
|
|
|
|||
|
|
@ -74,8 +74,6 @@ sealed interface NodesRoute : Route {
|
|||
sealed interface NodeDetailRoute : Route {
|
||||
@Serializable data class DeviceMetrics(val destNum: Int) : NodeDetailRoute
|
||||
|
||||
@Serializable data class NodeMap(val destNum: Int) : NodeDetailRoute
|
||||
|
||||
@Serializable data class PositionLog(val destNum: Int) : NodeDetailRoute
|
||||
|
||||
@Serializable data class EnvironmentMetrics(val destNum: Int) : NodeDetailRoute
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ class DeepLinkRouterTest {
|
|||
listOf(
|
||||
NodesRoute.NodesGraph,
|
||||
NodesRoute.NodeDetailGraph(destNum = 5678),
|
||||
NodeDetailRoute.NodeMap(destNum = 5678),
|
||||
NodeDetailRoute.PositionLog(destNum = 5678),
|
||||
),
|
||||
route("/nodes/5678/map"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ class NavigationConfigTest {
|
|||
NodesRoute.NodeDetail(),
|
||||
// NodeDetailRoute
|
||||
NodeDetailRoute.DeviceMetrics(destNum = 100),
|
||||
NodeDetailRoute.NodeMap(destNum = 100),
|
||||
NodeDetailRoute.PositionLog(destNum = 100),
|
||||
NodeDetailRoute.EnvironmentMetrics(destNum = 100),
|
||||
NodeDetailRoute.SignalMetrics(destNum = 100),
|
||||
|
|
|
|||
|
|
@ -889,6 +889,12 @@
|
|||
<string name="type_a_message">Type a message</string>
|
||||
<string name="pax_metrics_log">PAX Metrics</string>
|
||||
<string name="pax">PAX</string>
|
||||
<string name="pax_total_format">PAX: %1$d</string>
|
||||
<string name="pax_ble_format">B:%1$d</string>
|
||||
<string name="pax_wifi_format">W:%1$d</string>
|
||||
<string name="pax_total_marker">PAX: %1$s</string>
|
||||
<string name="pax_ble_marker">BLE: %1$s</string>
|
||||
<string name="pax_wifi_marker">WiFi: %1$s</string>
|
||||
<string name="no_pax_metrics_logs">No PAX metrics available.</string>
|
||||
<string name="wifi_devices">Wi-Fi Provisioning for mPWRD-OS</string>
|
||||
<string name="ble_devices">Bluetooth Devices</string>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.ui.util
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.Modifier
|
||||
import org.meshtastic.core.ui.component.PlaceholderScreen
|
||||
import org.meshtastic.proto.Position
|
||||
|
||||
/**
|
||||
* Provides an embeddable position-track map composable that renders a polyline with markers for the given [positions].
|
||||
* Unlike [LocalNodeMapScreenProvider], this does **not** include a Scaffold or AppBar — it is designed to be embedded
|
||||
* inside another screen layout (e.g. the position-log adaptive layout).
|
||||
*
|
||||
* On Desktop/JVM targets where native maps are not yet available, it falls back to a [PlaceholderScreen].
|
||||
*/
|
||||
@Suppress("Wrapping")
|
||||
val LocalNodeTrackMapProvider =
|
||||
compositionLocalOf<@Composable (destNum: Int, positions: List<Position>, modifier: Modifier) -> Unit> {
|
||||
{ _, _, _ -> PlaceholderScreen("Position Track Map") }
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.ui.util
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.Modifier
|
||||
import org.meshtastic.core.model.TracerouteOverlay
|
||||
import org.meshtastic.core.ui.component.PlaceholderScreen
|
||||
import org.meshtastic.proto.Position
|
||||
|
||||
/**
|
||||
* Provides an embeddable traceroute map composable that renders node markers and forward/return offset polylines for a
|
||||
* traceroute result. Unlike [LocalMapViewProvider], this does **not** include a Scaffold, AppBar, waypoints, location
|
||||
* tracking, custom tiles, or any main-map features — it is designed to be embedded inside `TracerouteMapScreen`'s
|
||||
* scaffold.
|
||||
*
|
||||
* On Desktop/JVM targets where native maps are not yet available, it falls back to a [PlaceholderScreen].
|
||||
*
|
||||
* Parameters:
|
||||
* - `tracerouteOverlay`: The overlay with forward/return route node nums.
|
||||
* - `tracerouteNodePositions`: Map of node num to position snapshots for the route nodes.
|
||||
* - `onMappableCountChanged`: Callback with (shown, total) node counts.
|
||||
* - `modifier`: Compose modifier for the map.
|
||||
*/
|
||||
@Suppress("Wrapping")
|
||||
val LocalTracerouteMapProvider =
|
||||
compositionLocalOf<
|
||||
@Composable (
|
||||
tracerouteOverlay: TracerouteOverlay?,
|
||||
tracerouteNodePositions: Map<Int, Position>,
|
||||
onMappableCountChanged: (Int, Int) -> Unit,
|
||||
modifier: Modifier,
|
||||
) -> Unit,
|
||||
> {
|
||||
{ _, _, _, _ -> PlaceholderScreen("Traceroute Map") }
|
||||
}
|
||||
|
|
@ -22,23 +22,10 @@ import androidx.compose.ui.Modifier
|
|||
|
||||
/**
|
||||
* Interface for providing a flavored MapView. This allows the map feature to be decoupled from specific map
|
||||
* implementations (Google Maps vs osmdroid).
|
||||
* implementations (Google Maps vs OSMDroid). Platform implementations create their own ViewModel via Koin.
|
||||
*/
|
||||
interface MapViewProvider {
|
||||
@Composable
|
||||
fun MapView(
|
||||
modifier: Modifier,
|
||||
// We use Any here to avoid circular dependency with feature:map
|
||||
viewModel: Any,
|
||||
navigateToNodeDetails: (Int) -> Unit,
|
||||
focusedNodeNum: Int? = null,
|
||||
// Using List<Any> to avoid dependency on proto.Position if needed
|
||||
nodeTracks: List<Any>? = null,
|
||||
tracerouteOverlay: Any? = null,
|
||||
tracerouteNodePositions: Map<Int, Any> = emptyMap(),
|
||||
onTracerouteMappableCountChanged: (Int, Int) -> Unit = { _, _ -> },
|
||||
waypointId: Int? = null,
|
||||
)
|
||||
@Composable fun MapView(modifier: Modifier, navigateToNodeDetails: (Int) -> Unit, waypointId: Int? = null)
|
||||
}
|
||||
|
||||
val LocalMapViewProvider = compositionLocalOf<MapViewProvider?> { null }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue