Modern Apps git

← Modern-Apps.git

maps: support intermediate waypoints

Commit
8719b035939f4315c78d961c0ecd00d4959e8de2
Author
Vayun Mathur <[email protected]>
When
2026-02-08 00:03 UTC (10 months ago)
Parents
f78136c

Diff

maps/src/main/java/com/vayunmathur/maps/RouteService.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/RouteService.kt b/maps/src/main/java/com/vayunmathur/maps/RouteService.ktindex 4aff2d59ba..14aea3fc78 100644--- a/maps/src/main/java/com/vayunmathur/maps/RouteService.kt+++ b/maps/src/main/java/com/vayunmathur/maps/RouteService.kt@@ -33,9 +33,11 @@ object RouteService {     ): Route? {         val originPos = features.waypoints.first()?.position ?: userPosition         val destPos = features.waypoints.last()?.position ?: userPosition+        val intermediates = features.waypoints.subList(1, features.waypoints.size - 1).map { it?.position ?: userPosition }          val request = API.RoutesRequest(             origin = API.Waypoint(API.Location(API.LatLng(originPos.latitude, originPos.longitude))),+            intermediates = intermediates.map { API.Waypoint(API.Location(API.LatLng(it.latitude, it.longitude))) },             destination = API.Waypoint(API.Location(API.LatLng(destPos.latitude, destPos.longitude))),             travelMode = travelMode,             routingPreference = if (travelMode == TravelMode.DRIVE) "TRAFFIC_AWARE" else null,@@ -105,6 +107,7 @@ object RouteService {         @Serializable         data class RoutesRequest(             val origin: Waypoint,+            val intermediates: List<Waypoint>,             val destination: Waypoint,             val travelMode: TravelMode,             val routingPreference: String?,
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex 7a5bf2edcd..6bdf77b9fa 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -237,6 +237,8 @@ fun MapPage(backStack: NavBackStack<Route>, ds: DataStoreUtils, db: TagDatabase)         println("SUBWAY SEARCH: ${OSM2.search("Galero Grill").map { OSM.getTags(it) }}")     } +    var inactiveNavigation: SpecificFeature.Route? by remember { mutableStateOf(null) }+     // --- ROUTE COMPUTATION ---     var route: Map<RouteService.TravelMode, RouteService.RouteType?>? by remember { mutableStateOf(null) }     LaunchedEffect(selectedFeature) {@@ -272,12 +274,16 @@ fun MapPage(backStack: NavBackStack<Route>, ds: DataStoreUtils, db: TagDatabase)         }     } +    BackHandler(selectedFeature == null && inactiveNavigation != null) {+        inactiveNavigation = null+    }+     var selectedRouteType by remember { mutableStateOf(RouteService.TravelMode.DRIVE) }      // --- RENDER ---     BottomSheetScaffold({         Column(Modifier.padding(horizontal = 16.dp).padding(bottom = 48.dp, top = 8.dp)) {-            BottomSheetContent(selectedFeature, { selectedFeature = it }, route, selectedRouteType, { selectedRouteType = it })+            BottomSheetContent(selectedFeature, { selectedFeature = it }, route, selectedRouteType, { selectedRouteType = it }, inactiveNavigation)         }     }, Modifier, scaffoldState, 170.dp) { paddingValues ->         Scaffold(Modifier.padding(top = paddingValues.calculateTopPadding()), topBar = {@@ -306,6 +312,7 @@ fun MapPage(backStack: NavBackStack<Route>, ds: DataStoreUtils, db: TagDatabase)                             println("LISTED FEATURES: $listedFeatures")                              listedFeatures.firstOrNull()?.let {+                                if(selectedFeature is SpecificFeature.Route) inactiveNavigation = selectedFeature as SpecificFeature.Route                                 selectedFeature = it                                 scaffoldState.bottomSheetState.expand()                             }@@ -324,8 +331,8 @@ fun MapPage(backStack: NavBackStack<Route>, ds: DataStoreUtils, db: TagDatabase)                 }                  // ROUTE OVERLAY HEADERS-                if(selectedFeature is SpecificFeature.Route) {-                    val routeFeature = selectedFeature as SpecificFeature.Route+                if(selectedFeature is SpecificFeature.Route || inactiveNavigation != null) {+                    val routeFeature = if(selectedFeature is SpecificFeature.Route) selectedFeature as SpecificFeature.Route else inactiveNavigation!!                     val listState = rememberLazyListState()                     val state = rememberReorderableLazyListState(listState, onMove = { from, to ->                         // swap their indices in the list
maps/src/main/java/com/vayunmathur/maps/ui/components/BottomSheetContent.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/components/BottomSheetContent.kt b/maps/src/main/java/com/vayunmathur/maps/ui/components/BottomSheetContent.ktindex 7e14ba4724..230a164444 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/components/BottomSheetContent.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/components/BottomSheetContent.kt@@ -39,7 +39,7 @@ import kotlinx.datetime.format.Padding import kotlinx.datetime.toLocalDateTime  @Composable-fun BottomSheetContent(selectedFeature: SpecificFeature?, setSelectedFeature: (SpecificFeature?) -> Unit, route: Map<RouteService.TravelMode, RouteService.RouteType?>?, selectedRouteType: RouteService.TravelMode, setSelectedRouteType: (RouteService.TravelMode) -> Unit) {+fun BottomSheetContent(selectedFeature: SpecificFeature?, setSelectedFeature: (SpecificFeature?) -> Unit, route: Map<RouteService.TravelMode, RouteService.RouteType?>?, selectedRouteType: RouteService.TravelMode, setSelectedRouteType: (RouteService.TravelMode) -> Unit, inactiveNavigation: SpecificFeature.Route?) {     when (selectedFeature) {         is SpecificFeature.Admin0Label -> {             Column {@@ -54,8 +54,12 @@ fun BottomSheetContent(selectedFeature: SpecificFeature?, setSelectedFeature: (S             }         }         is SpecificFeature.Restaurant -> {-            RestaurantBottomSheet(selectedFeature) {-                setSelectedFeature(SpecificFeature.Route(listOf(null, selectedFeature)))+            RestaurantBottomSheet(inactiveNavigation, selectedFeature) {+                if(inactiveNavigation == null) {+                    setSelectedFeature(SpecificFeature.Route(listOf(null, selectedFeature)))+                } else {+                    setSelectedFeature(SpecificFeature.Route(inactiveNavigation.waypoints + listOf(selectedFeature)))+                }             }         }         is SpecificFeature.Route -> {
maps/src/main/java/com/vayunmathur/maps/ui/components/RestaurantBottomSheet.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/components/RestaurantBottomSheet.kt b/maps/src/main/java/com/vayunmathur/maps/ui/components/RestaurantBottomSheet.ktindex 860840ca0e..3099ae71b4 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/components/RestaurantBottomSheet.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/components/RestaurantBottomSheet.kt@@ -49,12 +49,18 @@ fun goto(context: Context, uri: String) { }  @Composable-fun RestaurantBottomSheet(feature: SpecificFeature.Restaurant, requestDirections: () -> Unit) {+fun RestaurantBottomSheet(inactiveNavigation: SpecificFeature.Route?, feature: SpecificFeature.Restaurant, requestDirections: () -> Unit) {     val context = LocalContext.current     Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {         Row(verticalAlignment = Alignment.CenterVertically) {             Text(feature.name, style = MaterialTheme.typography.titleLarge, modifier = Modifier.weight(1f))-            Button({requestDirections()}) { Text("Directions") }+            Button({requestDirections()}) {+                if(inactiveNavigation == null) {+                    Text("Directions")+                } else {+                    Text("Add Stop to Route")+                }+            }         }         feature.openingHours?.let {             Spacer(Modifier.height(8.dp))