Modern Apps git

← Modern-Apps.git

maps: adopt Expressive shapes, type and button groups

Commit
0fb78bd3bcda70dfddf9fe4bc65ae8d51ee2e5ba
Author
vayun-mathur <[email protected]>
When
2026-08-21 17:30 UTC (3 months ago)
Parents
3ab285e

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/MaterialAliases.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialAliases.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialAliases.ktindex 6cced69389..1cef855b9e 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialAliases.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialAliases.kt@@ -109,6 +109,7 @@ typealias TabPosition = androidx.compose.material3.TabPosition typealias ExposedDropdownMenuBoxScope = androidx.compose.material3.ExposedDropdownMenuBoxScope typealias SingleChoiceSegmentedButtonRowScope = androidx.compose.material3.SingleChoiceSegmentedButtonRowScope typealias FloatingActionButtonMenuScope = androidx.compose.material3.FloatingActionButtonMenuScope+typealias ButtonGroupScope = androidx.compose.material3.ButtonGroupScope typealias ToggleFloatingActionButtonScope = androidx.compose.material3.ToggleFloatingActionButtonScope  // --- Composition locals (re-exported as vals; cannot be typealiased) ---
library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.ktindex 7273085aa6..7147cdb714 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt@@ -288,3 +288,36 @@ fun NavigationSuiteScaffold( ) = androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold(     navigationSuiteItems = navigationSuiteItems, modifier = modifier, layoutType = layoutType, content = content, )++// --- Expressive button group ---+/**+ * A connected row of buttons that behave as one control.+ *+ * The Expressive replacement for a tab row when the choices are actions or short icon-led+ * options: the group reads as a single object, and pressing a member animates its neighbours+ * aside rather than sliding an indicator. Use [ButtonGroupScope.toggleableItem] for a+ * single-select group and [ButtonGroupScope.clickableItem] for a row of actions.+ *+ * [overflowIndicator] is what shows when the items do not fit; it defaults to a "more" button+ * that opens them as a menu. Defaulted rather than required because every caller wants the same+ * thing, but not omitted — a group with no indicator silently drops whatever overflows.+ */+@Composable+fun ButtonGroup(+    modifier: Modifier = Modifier,+    horizontalArrangement: androidx.compose.foundation.layout.Arrangement.Horizontal =+        androidx.compose.foundation.layout.Arrangement.spacedBy(+            androidx.compose.material3.ButtonGroupDefaults.ConnectedSpaceBetween+        ),+    overflowIndicator: @Composable (androidx.compose.material3.ButtonGroupMenuState) -> Unit = { state ->+        FilledTonalIconButton(onClick = { if (state.isShowing) state.dismiss() else state.show() }) {+            IconMoreVert()+        }+    },+    content: ButtonGroupScope.() -> Unit,+) = androidx.compose.material3.ButtonGroup(+    overflowIndicator = overflowIndicator,+    modifier = modifier,+    horizontalArrangement = horizontalArrangement,+    content = content,+)\ No newline at end of file
maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.ktindex f441732849..1094e0f17e 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt@@ -12,6 +12,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ButtonDefaults+import com.vayunmathur.library.ui.ButtonGroup import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.ListItem@@ -19,6 +20,7 @@ import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.PrimaryTabRow import com.vayunmathur.library.ui.Tab+import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.verticalShape@@ -169,19 +171,32 @@ fun RouteSheet(     modifier: Modifier = Modifier, ) {     Column(modifier) {-        PrimaryTabRow(route.entries.indexOfFirst { it.key == selectedRouteType }) {-            route.entries.forEach {-                Tab(-                    selectedRouteType == it.key,-                    { setSelectedRouteType(it.key) }) {-                    val label = when(it.key) {-                        RouteService.TravelMode.WALK -> stringResource(R.string.travel_mode_walk)-                        RouteService.TravelMode.BICYCLE -> stringResource(R.string.travel_mode_bicycle)-                        RouteService.TravelMode.DRIVE -> stringResource(R.string.travel_mode_drive)-                        RouteService.TravelMode.TRANSIT -> stringResource(R.string.travel_mode_transit)-                    }-                    Text(label)+        // A connected ButtonGroup rather than a tab row: these are four short choices about one+        // thing, which reads as a single segmented control. A tab row implies four pages, and it+        // sat above content that is the same shape for every mode.+        //+        // Labels are resolved before the group because ButtonGroupScope's builder is a plain+        // lambda, not a composable one — `stringResource` cannot be called inside it.+        val modeLabels = route.keys.associateWith { mode ->+            stringResource(+                when (mode) {+                    RouteService.TravelMode.WALK -> R.string.travel_mode_walk+                    RouteService.TravelMode.BICYCLE -> R.string.travel_mode_bicycle+                    RouteService.TravelMode.DRIVE -> R.string.travel_mode_drive+                    RouteService.TravelMode.TRANSIT -> R.string.travel_mode_transit                 }+            )+        }+        ButtonGroup(+            modifier = Modifier.fillMaxWidth().padding(vertical = Spacing.sm),+        ) {+            route.keys.forEach { mode ->+                toggleableItem(+                    checked = selectedRouteType == mode,+                    label = modeLabels.getValue(mode),+                    onCheckedChange = { setSelectedRouteType(mode) },+                    weight = 1f,+                )             }         }         val routeForMode = route[selectedRouteType]@@ -448,4 +463,4 @@ fun SavedPlaceActions(             leadingIcon = { IconWork(Modifier.size(18.dp)) },         )     }-}\ No newline at end of file+}
maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt b/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.ktindex da0e7ea0f3..50bc8a5649 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/CategoryChips.kt@@ -11,7 +11,9 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.FilterChipDefaults import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.rememberHaptics import com.vayunmathur.maps.R import com.vayunmathur.maps.util.PoiCategories @@ -49,9 +51,10 @@ fun CategoryChips(     modifier: Modifier = Modifier,     selected: MapCategory? = null, ) {+    val haptics = rememberHaptics()     Row(         modifier = modifier.horizontalScroll(rememberScrollState()),-        horizontalArrangement = Arrangement.spacedBy(8.dp),+        horizontalArrangement = Arrangement.spacedBy(Spacing.sm),     ) {         // Material's unselected filter chip has a *transparent* container. On the         // browse screen these float directly over the map, where that leaves the@@ -63,7 +66,12 @@ fun CategoryChips(         MAP_CATEGORIES.forEach { category ->             FilterChip(                 selected = category == selected,-                onClick = { onCategory(category) },+                onClick = {+                    // A chip tap changes what is drawn on the map, not what page you are on, so+                    // the confirmation is the only feedback that the tap landed.+                    haptics.confirm()+                    onCategory(category)+                },                 label = { Text(stringResource(category.labelRes)) },                 colors = colors,             )
maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt b/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.ktindex 47bb46e38c..9be05b0513 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt@@ -42,6 +42,7 @@ import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.SmallFloatingActionButton import com.vayunmathur.library.ui.Text import com.vayunmathur.maps.R+import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.Spacing import com.vayunmathur.maps.data.PostedLimit import com.vayunmathur.maps.ui.theme.MapChromeMetrics@@ -54,6 +55,7 @@ import com.vayunmathur.maps.util.NavigationSessionManager import com.vayunmathur.maps.util.RouteService import com.vayunmathur.maps.util.formatDistance import com.vayunmathur.maps.util.formatEta+import com.vayunmathur.library.ui.R as UiR  /**  * Full-screen overlay drawn on top of [MaplibreMap] while navigation is@@ -83,6 +85,21 @@ fun NavigationOverlay(     if (navState is NavigationSessionManager.NavState.Idle) return      var showSteps by remember { mutableStateOf(false) }+    // Ending a trip discards the route and stops guidance, and the button sat one tap away from+    // a driver's thumb with no confirmation at all.+    var confirmEndTrip by remember { mutableStateOf(false) }++    if (confirmEndTrip) {+        ConfirmDialog(+            title = stringResource(R.string.nav_end_confirm_title),+            message = stringResource(R.string.nav_end_confirm_message),+            confirmLabel = stringResource(R.string.nav_action_end),+            dismissLabel = stringResource(UiR.string.cancel),+            destructive = true,+            onConfirm = onEndTrip,+            onDismiss = { confirmEndTrip = false },+        )+    }      Box(modifier.fillMaxSize()) {         // ---- Top maneuver banner / status ----@@ -181,7 +198,7 @@ fun NavigationOverlay(             is NavigationSessionManager.NavState.Navigating -> {                 EtaStrip(                     progress = navState.progress,-                    onEndTrip = onEndTrip,+                    onEndTrip = { confirmEndTrip = true },                     onToggleSteps = { showSteps = !showSteps },                     modifier = Modifier                         .align(Alignment.BottomCenter)@@ -224,12 +241,12 @@ private fun StatusCard( ) {     Card(         modifier = modifier.fillMaxWidth(),-        shape = RoundedCornerShape(16.dp),+        shape = MaterialTheme.shapes.largeIncreased,     ) {-        Column(Modifier.padding(16.dp)) {-            Text(text, fontWeight = FontWeight.Medium)+        Column(Modifier.padding(Spacing.lg)) {+            Text(text, style = MaterialTheme.typography.titleMediumEmphasized)             if (showProgress) {-                Spacer(Modifier.height(8.dp))+                Spacer(Modifier.height(Spacing.sm))                 LinearProgressIndicator(Modifier.fillMaxWidth())             }         }@@ -249,22 +266,25 @@ private fun EtaStrip(      Card(         modifier = modifier,-        shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),+        shape = MaterialTheme.shapes.extraLargeIncreased.copy(+            bottomStart = androidx.compose.foundation.shape.CornerSize(0.dp),+            bottomEnd = androidx.compose.foundation.shape.CornerSize(0.dp),+        ),         colors = CardDefaults.cardColors(-            containerColor = MaterialTheme.colorScheme.surface,+            containerColor = MaterialTheme.colorScheme.surfaceContainerLow,         ),     ) {         Row(             modifier = Modifier                 .fillMaxWidth()-                .padding(horizontal = 16.dp, vertical = 12.dp),+                .padding(horizontal = Spacing.lg, vertical = Spacing.md),             verticalAlignment = Alignment.CenterVertically,         ) {             Column(Modifier.weight(1f)) {-                Text(etaText, fontSize = 20.sp, fontWeight = FontWeight.Bold)+                Text(etaText, style = MaterialTheme.typography.titleLargeEmphasized)                 Text(                     stringResource(R.string.min, remainingMinutes, remainingDistance),-                    fontSize = 14.sp,+                    style = MaterialTheme.typography.bodyMedium,                     color = MaterialTheme.colorScheme.onSurfaceVariant,                 )             }
maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.ktindex 7ef0fcf3a5..2c67cd09fb 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt@@ -20,6 +20,7 @@ import androidx.compose.ui.unit.sp import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text import com.vayunmathur.maps.R import com.vayunmathur.maps.ui.iconContent@@ -53,39 +54,40 @@ fun ManeuverBanner(     Card(         modifier = modifier             .fillMaxWidth()-            .shadow(8.dp, RoundedCornerShape(16.dp)),-        shape = RoundedCornerShape(16.dp),+            .shadow(8.dp, MaterialTheme.shapes.extraLarge),+        shape = MaterialTheme.shapes.extraLarge,         colors = CardDefaults.cardColors(             containerColor = MaterialTheme.colorScheme.primaryContainer,             contentColor = MaterialTheme.colorScheme.onPrimaryContainer,         ),     ) {-        Column(Modifier.padding(16.dp)) {+        Column(Modifier.padding(Spacing.lg)) {             Row(verticalAlignment = Alignment.CenterVertically) {                 if (primaryIcon != null) {                     primaryIcon(Modifier.size(56.dp), MaterialTheme.colorScheme.onPrimaryContainer)-                    Spacer(Modifier.width(16.dp))+                    Spacer(Modifier.width(Spacing.lg))                 }                 Column(Modifier.weight(1f)) {-                    Text(distanceText, fontSize = 28.sp, fontWeight = FontWeight.Bold)+                    // The distance to the next turn is the one thing a driver reads at a+                    // glance, so it gets the emphasized headline role rather than a bold body.+                    Text(distanceText, style = MaterialTheme.typography.headlineMediumEmphasized)                     Row(verticalAlignment = Alignment.CenterVertically) {                         if (shield != null) {                             RouteShield(shield)-                            Spacer(Modifier.width(8.dp))+                            Spacer(Modifier.width(Spacing.sm))                         }                         Text(                             primaryInstruction,-                            fontSize = 16.sp,-                            fontWeight = FontWeight.Medium,+                            style = MaterialTheme.typography.titleMedium,                             modifier = Modifier.weight(1f, fill = false),                         )                     }                     val secondary = steps.getOrNull(progress.currentStepIndex + 2)                     if (nextStep != null && secondary != null) {-                        Spacer(Modifier.height(4.dp))+                        Spacer(Modifier.height(Spacing.xs))                         Text(                             stringResource(R.string.then, secondary.navInstruction.instructions),-                            fontSize = 12.sp,+                            style = MaterialTheme.typography.bodySmall,                             color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f),                         )                     }
maps/src/main/res/values/strings.xml
diff --git a/maps/src/main/res/values/strings.xml b/maps/src/main/res/values/strings.xmlindex 5ff0f175ab..6376975a36 100644--- a/maps/src/main/res/values/strings.xml+++ b/maps/src/main/res/values/strings.xml@@ -260,6 +260,10 @@     <string name="nav_status_failed">Navigation stopped</string>     <!-- Button: End navigation. Verb. -->     <string name="nav_action_end">End</string>+    <!-- NavigationOverlay: title of the confirmation shown before ending a trip -->+    <string name="nav_end_confirm_title">End this trip?</string>+    <!-- NavigationOverlay: body of the end-trip confirmation -->+    <string name="nav_end_confirm_message">Turn-by-turn guidance will stop.</string>     <!-- Button: Recenter map on user location. Verb. -->     <string name="nav_action_recenter">Recenter</string>     <!-- Header for the full turn-by-turn step list sheet. -->