Skip to content

Commit da06108

Browse files
committed
spotless
1 parent 883bde0 commit da06108

File tree

11 files changed

+508
-609
lines changed

11 files changed

+508
-609
lines changed

feature/map/src/fdroid/kotlin/org/meshtastic/feature/map/MapView.kt

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package org.meshtastic.feature.map
1919

2020
import android.Manifest // Added for Accompanist
2121
import androidx.appcompat.content.res.AppCompatResources
22+
import androidx.compose.animation.Crossfade
23+
import androidx.compose.animation.core.tween
2224
import androidx.compose.foundation.background
2325
import androidx.compose.foundation.layout.Arrangement
2426
import androidx.compose.foundation.layout.Box
@@ -32,10 +34,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
3234
import androidx.compose.foundation.layout.wrapContentWidth
3335
import androidx.compose.foundation.rememberScrollState
3436
import androidx.compose.foundation.verticalScroll
35-
import androidx.compose.animation.Crossfade
36-
import androidx.compose.animation.core.tween
3737
import androidx.compose.material.icons.Icons
38-
import androidx.compose.material.icons.filled.Close
3938
import androidx.compose.material.icons.filled.Lens
4039
import androidx.compose.material.icons.filled.LocationDisabled
4140
import androidx.compose.material.icons.filled.PinDrop
@@ -52,7 +51,6 @@ import androidx.compose.material3.DropdownMenuItem
5251
import androidx.compose.material3.ExperimentalMaterial3Api
5352
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
5453
import androidx.compose.material3.Icon
55-
import androidx.compose.material3.IconButton
5654
import androidx.compose.material3.MaterialTheme
5755
import androidx.compose.material3.Scaffold
5856
import androidx.compose.material3.Surface
@@ -76,7 +74,6 @@ import androidx.compose.ui.platform.LocalDensity
7674
import androidx.compose.ui.platform.LocalHapticFeedback
7775
import androidx.compose.ui.unit.dp
7876
import androidx.compose.ui.viewinterop.AndroidView
79-
import androidx.compose.ui.window.DialogProperties
8077
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
8178
import androidx.lifecycle.compose.collectAsStateWithLifecycle
8279
import com.google.accompanist.permissions.ExperimentalPermissionsApi // Added for Accompanist
@@ -427,8 +424,7 @@ fun MapView(
427424
Timber.d("mapStyleId from prefs: $id")
428425
return CustomTileSource.getTileSource(id).also {
429426
zoomLevelMax = it.maximumZoomLevel.toDouble()
430-
showDownloadButton =
431-
if (it is OnlineTileSourceBase) it.tileSourcePolicy.acceptsBulkDownload() else false
427+
showDownloadButton = if (it is OnlineTileSourceBase) it.tileSourcePolicy.acceptsBulkDownload() else false
432428
}
433429
}
434430

@@ -464,18 +460,12 @@ fun MapView(
464460
MyLocationNewOverlay(this).apply {
465461
enableMyLocation()
466462
enableFollowLocation()
467-
getBitmapFromVectorDrawable(
468-
context,
469-
org.meshtastic.core.ui.R.drawable.ic_map_location_dot_24
470-
)
463+
getBitmapFromVectorDrawable(context, org.meshtastic.core.ui.R.drawable.ic_map_location_dot_24)
471464
?.let {
472465
setPersonIcon(it)
473466
setPersonAnchor(0.5f, 0.5f)
474467
}
475-
getBitmapFromVectorDrawable(
476-
context,
477-
org.meshtastic.core.ui.R.drawable.ic_map_navigation_24
478-
)?.let {
468+
getBitmapFromVectorDrawable(context, org.meshtastic.core.ui.R.drawable.ic_map_navigation_24)?.let {
479469
setDirectionIcon(it)
480470
setDirectionAnchor(0.5f, 0.5f)
481471
}
@@ -503,18 +493,14 @@ fun MapView(
503493
val waypoints by mapViewModel.waypoints.collectAsStateWithLifecycle(emptyMap())
504494

505495
val markerIcon = remember {
506-
AppCompatResources.getDrawable(
507-
context,
508-
org.meshtastic.core.ui.R.drawable.ic_baseline_location_on_24
509-
)
496+
AppCompatResources.getDrawable(context, org.meshtastic.core.ui.R.drawable.ic_baseline_location_on_24)
510497
}
511498

512499
fun MapView.onNodesChanged(nodes: Collection<Node>): List<MarkerWithLabel> {
513500
val nodesWithPosition = nodes.filter { it.validPosition != null }
514501
val ourNode = mapViewModel.ourNodeInfo.value
515502
val displayUnits = mapViewModel.config.display.units
516-
val mapFilterStateValue =
517-
mapViewModel.mapFilterStateFlow.value // Access mapFilterState directly
503+
val mapFilterStateValue = mapViewModel.mapFilterStateFlow.value // Access mapFilterState directly
518504
return nodesWithPosition.mapNotNull { node ->
519505
if (mapFilterStateValue.onlyFavorites && !node.isFavorite && !node.equals(ourNode)) {
520506
return@mapNotNull null
@@ -644,8 +630,7 @@ fun MapView(
644630
MarkerWithLabel(this, label, emoji).apply {
645631
id = "${pt.id}"
646632
title = "${pt.name} (${getUsername(waypoint.data.from)}$lock)"
647-
snippet =
648-
"[$time] ${pt.description} " + stringResource(Res.string.expires) + ": $expireTimeStr"
633+
snippet = "[$time] ${pt.description} " + stringResource(Res.string.expires) + ": $expireTimeStr"
649634
position = GeoPoint(pt.latitudeI * 1e-7, pt.longitudeI * 1e-7)
650635
setVisible(false) // This seems to be always false, was this intended?
651636
setOnLongClickListener {
@@ -697,13 +682,7 @@ fun MapView(
697682

698683
// Only update osmdroid markers when using osmdroid
699684
if (!useMapLibre && map != null) {
700-
with(map) {
701-
UpdateMarkers(
702-
onNodesChanged(nodes),
703-
onWaypointChanged(waypoints.values),
704-
nodeClusterer
705-
)
706-
}
685+
with(map) { UpdateMarkers(onNodesChanged(nodes), onWaypointChanged(waypoints.values), nodeClusterer) }
707686
}
708687

709688
fun MapView.generateBoxOverlay() {
@@ -713,18 +692,13 @@ fun MapView(
713692
downloadRegionBoundingBox = boundingBox.zoomIn(zoomFactor)
714693
val polygon =
715694
Polygon().apply {
716-
points = Polygon.pointsAsRect(downloadRegionBoundingBox)
717-
.map { GeoPoint(it.latitude, it.longitude) }
695+
points = Polygon.pointsAsRect(downloadRegionBoundingBox).map { GeoPoint(it.latitude, it.longitude) }
718696
}
719697
overlays.add(polygon)
720698
invalidate()
721699
val tileCount: Int =
722700
CacheManager(this)
723-
.possibleTilesInArea(
724-
downloadRegionBoundingBox,
725-
zoomLevelMin.toInt(),
726-
zoomLevelMax.toInt()
727-
)
701+
.possibleTilesInArea(downloadRegionBoundingBox, zoomLevelMin.toInt(), zoomLevelMax.toInt())
728702
cacheEstimate = com.meshtastic.core.strings.getString(Res.string.map_cache_tiles, tileCount)
729703
}
730704

@@ -792,11 +766,12 @@ fun MapView(
792766
) { isMapLibre ->
793767
if (isMapLibre) {
794768
// MapLibre implementation
795-
timber.log.Timber.tag("MapView").d(
796-
"Calling MapLibrePOC with focusedNodeNum=%s, nodeTracks count=%d",
797-
focusedNodeNum ?: "null",
798-
nodeTracks?.size ?: 0
799-
)
769+
timber.log.Timber.tag("MapView")
770+
.d(
771+
"Calling MapLibrePOC with focusedNodeNum=%s, nodeTracks count=%d",
772+
focusedNodeNum ?: "null",
773+
nodeTracks?.size ?: 0,
774+
)
800775
org.meshtastic.feature.map.maplibre.ui.MapLibrePOC(
801776
mapViewModel = mapViewModel,
802777
onNavigateToNodeDetails = navigateToNodeDetails,
@@ -834,8 +809,7 @@ fun MapView(
834809
)
835810
} else {
836811
Column(
837-
modifier = Modifier.padding(top = 16.dp, end = 16.dp)
838-
.align(Alignment.TopEnd),
812+
modifier = Modifier.padding(top = 16.dp, end = 16.dp).align(Alignment.TopEnd),
839813
verticalArrangement = Arrangement.spacedBy(8.dp),
840814
) {
841815
MapButton(
@@ -939,11 +913,11 @@ fun MapView(
939913
if (hasGps) {
940914
MapButton(
941915
icon =
942-
if (myLocationOverlay == null) {
943-
Icons.Outlined.MyLocation
944-
} else {
945-
Icons.Default.LocationDisabled
946-
},
916+
if (myLocationOverlay == null) {
917+
Icons.Outlined.MyLocation
918+
} else {
919+
Icons.Default.LocationDisabled
920+
},
947921
contentDescription = stringResource(Res.string.toggle_my_position),
948922
onClick = {
949923
if (locationPermissionsState.allPermissionsGranted) {
@@ -1002,7 +976,6 @@ fun MapView(
1002976
}
1003977
}
1004978

1005-
1006979
showEditWaypointDialog?.let { waypoint ->
1007980
EditWaypointDialog(
1008981
waypoint = waypoint,
@@ -1011,12 +984,10 @@ fun MapView(
1011984
showEditWaypointDialog = null
1012985
mapViewModel.sendWaypoint(
1013986
waypoint.copy {
1014-
if (id == 0) id =
1015-
mapViewModel.generatePacketId() ?: return@EditWaypointDialog
987+
if (id == 0) id = mapViewModel.generatePacketId() ?: return@EditWaypointDialog
1016988
if (name == "") name = "Dropped Pin"
1017989
if (expire == 0) expire = Int.MAX_VALUE
1018-
lockedTo =
1019-
if (waypoint.lockedTo != 0) mapViewModel.myNodeNum ?: 0 else 0
990+
lockedTo = if (waypoint.lockedTo != 0) mapViewModel.myNodeNum ?: 0 else 0
1020991
if (waypoint.icon == 0) icon = 128205
1021992
},
1022993
)
@@ -1033,4 +1004,4 @@ fun MapView(
10331004
)
10341005
}
10351006
}
1036-
}
1007+
}

feature/map/src/fdroid/kotlin/org/meshtastic/feature/map/component/TileCacheManagementSheet.kt

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@ import androidx.compose.foundation.layout.PaddingValues
2222
import androidx.compose.foundation.layout.fillMaxWidth
2323
import androidx.compose.foundation.layout.padding
2424
import androidx.compose.foundation.lazy.LazyColumn
25-
import androidx.compose.foundation.lazy.items
26-
import androidx.compose.material.icons.Icons
27-
import androidx.compose.material.icons.filled.Delete
2825
import androidx.compose.material3.Button
2926
import androidx.compose.material3.ExperimentalMaterial3Api
3027
import androidx.compose.material3.HorizontalDivider
31-
import androidx.compose.material3.Icon
32-
import androidx.compose.material3.IconButton
33-
import androidx.compose.material3.ListItem
3428
import androidx.compose.material3.MaterialTheme
3529
import androidx.compose.material3.Text
3630
import androidx.compose.runtime.Composable
37-
import androidx.compose.runtime.LaunchedEffect
3831
import androidx.compose.runtime.getValue
3932
import androidx.compose.runtime.mutableStateOf
4033
import androidx.compose.runtime.remember
@@ -50,19 +43,12 @@ import timber.log.Timber
5043

5144
@Composable
5245
@OptIn(ExperimentalMaterial3Api::class)
53-
fun TileCacheManagementSheet(
54-
cacheManager: MapLibreTileCacheManager,
55-
onDismiss: () -> Unit,
56-
) {
46+
fun TileCacheManagementSheet(cacheManager: MapLibreTileCacheManager, onDismiss: () -> Unit) {
5747
var isClearing by remember { mutableStateOf(false) }
5848

5949
LazyColumn(contentPadding = PaddingValues(bottom = 16.dp)) {
6050
item {
61-
Text(
62-
modifier = Modifier.padding(16.dp),
63-
text = "Map Cache",
64-
style = MaterialTheme.typography.headlineSmall,
65-
)
51+
Text(modifier = Modifier.padding(16.dp), text = "Map Cache", style = MaterialTheme.typography.headlineSmall)
6652
HorizontalDivider()
6753
}
6854

@@ -74,7 +60,8 @@ fun TileCacheManagementSheet(
7460
modifier = Modifier.padding(bottom = 8.dp),
7561
)
7662
Text(
77-
text = "Map tiles are automatically cached by MapLibre as you view the map. " +
63+
text =
64+
"Map tiles are automatically cached by MapLibre as you view the map. " +
7865
"This improves performance and allows limited offline viewing of previously visited areas.",
7966
style = MaterialTheme.typography.bodyMedium,
8067
color = MaterialTheme.colorScheme.onSurfaceVariant,
@@ -97,7 +84,8 @@ fun TileCacheManagementSheet(
9784
modifier = Modifier.padding(bottom = 8.dp),
9885
)
9986
Text(
100-
text = "If you're experiencing issues with outdated map tiles or want to free up storage space, you can clear the cache below.",
87+
text =
88+
"If you're experiencing issues with outdated map tiles or want to free up storage space, you can clear the cache below.",
10189
style = MaterialTheme.typography.bodyMedium,
10290
color = MaterialTheme.colorScheme.onSurfaceVariant,
10391
)
@@ -116,9 +104,7 @@ fun TileCacheManagementSheet(
116104
} catch (e: Exception) {
117105
Timber.tag("TileCacheManagementSheet").e(e, "Error clearing cache: ${e.message}")
118106
} finally {
119-
withContext(Dispatchers.Main) {
120-
isClearing = false
121-
}
107+
withContext(Dispatchers.Main) { isClearing = false }
122108
}
123109
}
124110
},
@@ -138,4 +124,3 @@ fun TileCacheManagementSheet(
138124
}
139125
}
140126
}
141-

feature/map/src/fdroid/kotlin/org/meshtastic/feature/map/maplibre/core/MapLibreDataTransformers.kt

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,47 +162,50 @@ fun escapeJson(input: String): String {
162162
fun positionsToLineStringFeature(positions: List<Position>): Feature? {
163163
if (positions.size < 2) return null
164164

165-
val points = positions.map { pos ->
166-
val lat = pos.latitudeI * DEG_D
167-
val lon = pos.longitudeI * DEG_D
168-
Point.fromLngLat(lon, lat)
169-
}
165+
val points =
166+
positions.map { pos ->
167+
val lat = pos.latitudeI * DEG_D
168+
val lon = pos.longitudeI * DEG_D
169+
Point.fromLngLat(lon, lat)
170+
}
170171

171172
return Feature.fromGeometry(LineString.fromLngLats(points))
172173
}
173174

174175
/** Converts a list of positions to a GeoJSON FeatureCollection for track point markers */
175176
fun positionsToPointFeatures(positions: List<Position>): FeatureCollection {
176-
val features = positions.mapIndexed { index, pos ->
177-
val lat = pos.latitudeI * DEG_D
178-
val lon = pos.longitudeI * DEG_D
179-
val point = Point.fromLngLat(lon, lat)
180-
val feature = Feature.fromGeometry(point)
177+
val features =
178+
positions.mapIndexed { index, pos ->
179+
val lat = pos.latitudeI * DEG_D
180+
val lon = pos.longitudeI * DEG_D
181+
val point = Point.fromLngLat(lon, lat)
182+
val feature = Feature.fromGeometry(point)
181183

182-
feature.addStringProperty("kind", "track_point")
183-
feature.addNumberProperty("index", index)
184-
feature.addNumberProperty("time", pos.time)
185-
feature.addNumberProperty("altitude", pos.altitude)
186-
feature.addNumberProperty("groundSpeed", pos.groundSpeed)
187-
feature.addNumberProperty("groundTrack", pos.groundTrack)
188-
feature.addNumberProperty("satsInView", pos.satsInView)
189-
feature.addNumberProperty("latitude", lat)
190-
feature.addNumberProperty("longitude", lon)
184+
feature.addStringProperty("kind", "track_point")
185+
feature.addNumberProperty("index", index)
186+
feature.addNumberProperty("time", pos.time)
187+
feature.addNumberProperty("altitude", pos.altitude)
188+
feature.addNumberProperty("groundSpeed", pos.groundSpeed)
189+
feature.addNumberProperty("groundTrack", pos.groundTrack)
190+
feature.addNumberProperty("satsInView", pos.satsInView)
191+
feature.addNumberProperty("latitude", lat)
192+
feature.addNumberProperty("longitude", lon)
191193

192-
feature
193-
}
194+
feature
195+
}
194196

195197
return FeatureCollection.fromFeatures(features)
196198
}
197199

198200
/** Converts nodes to simple GeoJSON FeatureCollection for heatmap */
199201
fun nodesToHeatmapFeatureCollection(nodes: List<Node>): FeatureCollection {
200-
val features = nodes.mapNotNull { node ->
201-
val pos = node.validPosition ?: return@mapNotNull null
202-
val lat = pos.latitudeI * DEG_D
203-
val lon = pos.longitudeI * DEG_D
204-
val point = Point.fromLngLat(lon, lat)
205-
Feature.fromGeometry(point)
206-
}
202+
val features =
203+
nodes.mapNotNull { node ->
204+
val pos = node.validPosition ?: return@mapNotNull null
205+
val lat = pos.latitudeI * DEG_D
206+
val lon = pos.longitudeI * DEG_D
207+
val point = Point.fromLngLat(lon, lat)
208+
Feature.fromGeometry(point)
209+
}
207210
return FeatureCollection.fromFeatures(features)
208211
}

0 commit comments

Comments
 (0)