refactor(metrics/map): DRY up charts, decompose MapView monoliths, add test coverage (#5049)

This commit is contained in:
James Rich 2026-04-10 15:54:09 -05:00 committed by GitHub
parent 56332f4d77
commit 520fa717a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 3464 additions and 2169 deletions

View file

@ -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") }
}

View file

@ -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") }
}

View file

@ -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 }