Modern Apps git

← Modern-Apps.git

maps: add city labels and a Wikipedia button to the admin sheet

Commit
5b46be59d3ad1acca1478a69c567d87d95ca220d
Author
vayun-mathur <[email protected]>
When
2026-08-21 01:58 UTC (3 months ago)
Parents
f1abead
Country and region sheets rendered the article URL as a plain-text subtitle that could not be opened; they now share an AdminLabelHeader with the name and a trailing Wikipedia TextButton. Adds Admin2Label plus a kind == locality branch, with no ISO lookup since cities have no ISO 3166 code, and highlights the city border from the admin_city layer build_admin_layers.sh already bakes into v5 (matched on name_en, the only key that layer carries).

Diff

maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.ktindex ab1ba93d70..117e254e1c 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/SpecificFeature.kt@@ -20,6 +20,13 @@ sealed interface SpecificFeature {     data class Admin0Label(@SerialName("iso3166_1") val iso: String, val wikipedia: String, val name: String) : SpecificFeature     @Serializable     data class Admin1Label(@SerialName("iso3166_2") val iso: String, val wikipedia: String, val name: String) : SpecificFeature+    /**+     * A city / town. Unlike the country and region labels there is no ISO code to+     * key on — the baked `admin_city` layer carries only `name` / `name_en` — so+     * the border highlight matches on the name instead.+     */+    @Serializable+    data class Admin2Label(val wikipedia: String, val name: String) : SpecificFeature     @Serializable     data class Restaurant(override val name: String, val phone: String?, val website: String?, val menu: String?, val openingHours: OpeningHours?,                           override val position: Position): RoutableFeature@@ -39,7 +46,7 @@ fun JsonObject.string(key: String): String? = this[key]?.jsonPrimitive?.content  *  * Amenities are now Google-only (rendered on the custom overlay layer and tapped  * there — see GooglePoiLayer), so this no longer reads the amenities DB: it only- * handles the country/region admin labels (Wikidata-backed). Everything else+ * handles the country/region/city admin labels (Wikidata-backed). Everything else  * returns null, since native POIs are suppressed in the style.  */ suspend fun parse(feature: Feature1): SpecificFeature? {@@ -64,6 +71,15 @@ suspend fun parse(feature: Feature1): SpecificFeature? {             val name = properties.string("name:en") ?: properties.string("name") ?: return null             SpecificFeature.Admin1Label(iso, wikipediaUrl, name)         }+        "locality" -> {+            // No ISO lookup: a city has no ISO 3166 code, so the Wikidata round+            // trip is only for the article URL.+            val wikidataId = properties.string("wikidata") ?: return null+            val wiki = try { Wikidata.get(wikidataId) } catch (_: Exception) { return null }+            val wikipediaUrl = wiki.getWikipedia() ?: return null+            val name = properties.string("name:en") ?: properties.string("name") ?: return null+            SpecificFeature.Admin2Label(wikipediaUrl, name)+        }         else -> null     } }\ 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 46f944640d..3a771c5f03 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt@@ -19,6 +19,7 @@ import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.PrimaryTabRow import com.vayunmathur.library.ui.Tab import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue@@ -60,18 +61,12 @@ fun BottomSheetContent(     navState: NavigationSessionManager.NavState = NavigationSessionManager.NavState.Idle, ) {     when (selectedFeature) {-        is SpecificFeature.Admin0Label -> {-            Column {-                Text(selectedFeature.name, style = MaterialTheme.typography.titleLarge)-                Text(selectedFeature.wikipedia, style = MaterialTheme.typography.bodyMedium)-            }-        }-        is SpecificFeature.Admin1Label -> {-            Column {-                Text(selectedFeature.name, style = MaterialTheme.typography.titleLarge)-                Text(selectedFeature.wikipedia, style = MaterialTheme.typography.bodyMedium)-            }-        }+        is SpecificFeature.Admin0Label ->+            AdminLabelHeader(selectedFeature.name, selectedFeature.wikipedia)+        is SpecificFeature.Admin1Label ->+            AdminLabelHeader(selectedFeature.name, selectedFeature.wikipedia)+        is SpecificFeature.Admin2Label ->+            AdminLabelHeader(selectedFeature.name, selectedFeature.wikipedia)         is SpecificFeature.Restaurant -> {             Column {                 PlaceSheet(viewModel, savedPlacesViewModel, inactiveNavigation, selectedFeature) {@@ -122,6 +117,28 @@ fun BottomSheetContent(     } } +/**+ * Header for a tapped country / state / city label: the name, with a button to its+ * Wikipedia article pinned to the trailing edge.+ *+ * The article URL is deliberately not rendered. It used to be the subtitle, where+ * it read as noise and — being plain text — could not actually be opened.+ */+@Composable+private fun AdminLabelHeader(name: String, wikipedia: String) {+    val context = LocalContext.current+    Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {+        Text(+            name,+            style = MaterialTheme.typography.titleLarge,+            modifier = Modifier.weight(1f),+        )+        TextButton(onClick = { goto(context, wikipedia) }) {+            Text(stringResource(R.string.wikipedia))+        }+    }+}+ /**  * The directions panel: one tab per travel mode, the trip summary, and the turn-by-turn  * step list.
maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.ktindex 4a6c725e36..a7457b6c62 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt@@ -221,6 +221,10 @@ fun MyMapLayers(                     // Region/state highlight: filter admin_region by iso_3166_2                     // (the key CountryMap.getAdmin1 matched on the FGB).                     AdminHighlight(adminSource, "admin_region", "iso_3166_2", selectedFeature.iso)+                is SpecificFeature.Admin2Label ->+                    // City highlight: admin_city carries no ISO code, so match the+                    // English name — the same value parse() read off the label.+                    AdminHighlight(adminSource, "admin_city", "name_en", selectedFeature.name)                 is SpecificFeature.Route -> {                     if (route != null) {                         LaunchedEffect(
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 60d9fffdf9..115786867e 100644--- a/maps/src/main/res/values/strings.xml+++ b/maps/src/main/res/values/strings.xml@@ -77,6 +77,8 @@     <string name="place_action_call">Call</string>     <!-- Place sheet action row: open the place's website -->     <string name="place_action_website">Website</string>+    <!-- Country/state/city sheet: open the area's Wikipedia article -->+    <string name="wikipedia">Wikipedia</string>     <!-- Place sheet action row: order from this restaurant via the food-delivery app -->     <string name="place_action_order">Order</string>     <!-- Place sheet action row: share the place -->