diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/ClusterScreen.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/ClusterScreen.kt index 6ddf3b8..d22bab5 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/ClusterScreen.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/ClusterScreen.kt @@ -79,7 +79,7 @@ internal fun ClusterScreen(marginX: Int, marginY: Int, densityDpi: Int, clearAre // The map app's turn changes a few times a minute: read it once a second. val turn by produceState(null) { while (true) { - value = ClusterTurn.now() + value = ClusterTurn.now(context) delay(1_000) } } @@ -279,7 +279,7 @@ private class ClusterTurn( val rows: Float get() = if (lanes.isEmpty()) 8.5f else 12f companion object { - fun now(): ClusterTurn? { + fun now(context: Context): ClusterTurn? { val turn = NavTurn.current() ?: return null if (turn.rerouting) return null val step = turn.step @@ -290,7 +290,7 @@ private class ClusterTurn( listOf( e.remainingTimeSeconds.takeIf { it >= 0 }?.let { remainingTime(it) }.orEmpty(), e.remainingDistance.display(), - e.arrivalTimeAtDestination.clockTime(), + e.arrivalTimeAtDestination.clockTime(context), ).filter { it.isNotEmpty() }.joinToString(" ยท ") }.orEmpty() return ClusterTurn(step.maneuver?.icon, turn.distance.display(), what, trip, step.lanes.orEmpty()) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateChrome.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateChrome.kt index e9f8925..e7e9b72 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateChrome.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateChrome.kt @@ -426,7 +426,7 @@ private fun TripRow(estimate: TravelEstimate, showStop: Boolean, modifier: Modif val scheme = MaterialTheme.colorScheme val time = remainingTime(estimate.remainingTimeSeconds) val distance = estimate.remainingDistance.display() - val arrival = estimate.arrivalTimeAtDestination.clockTime() + val arrival = estimate.arrivalTimeAtDestination.clockTime(LocalContext.current) val trip = estimate.tripText.text() if (time.isEmpty() && distance.isEmpty() && arrival.isEmpty() && trip.isEmpty()) return val dark = scheme.surface.luminanceIsDark() diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/VoiceReply.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/VoiceReply.kt index 739798c..6015398 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/VoiceReply.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/VoiceReply.kt @@ -258,7 +258,7 @@ object VoiceReply { private fun etaReply(): String? { val estimate = (CarServices.nav.template.value as? NavigationTemplate)?.destinationTravelEstimate ?: return null - val at = estimate.arrivalTimeAtDestination.clockTime() + val at = estimate.arrivalTimeAtDestination.clockTime(appContext) val left = remainingTime(estimate.remainingTimeSeconds) return when { at.isNotEmpty() -> "Driving, I'll be there around $at." diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/host/CarModels.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/host/CarModels.kt index 3c8845f..75f5833 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/host/CarModels.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/host/CarModels.kt @@ -217,12 +217,18 @@ fun remainingTime(seconds: Long): String { return if (hours > 0) "$hours hr $minutes min" else "$minutes min" } -/** "1:10 AM" - the clock at the destination, not the phone's own, in case a route crosses a zone. */ -fun androidx.car.app.model.DateTimeWithZone?.clockTime(): String { +/** + * "1:10 AM" or "13:10", following the phone's 24-hour setting when [context] is known - the clock + * at the destination, not the phone's own, in case a route crosses a zone. + */ +fun androidx.car.app.model.DateTimeWithZone?.clockTime(context: Context?): String { val at = this ?: return "" val shifted = java.util.Date(at.timeSinceEpochMillis + at.zoneOffsetSeconds * 1000L) + val locale = java.util.Locale.getDefault() + val is24Hour = context?.let { android.text.format.DateFormat.is24HourFormat(it) } ?: false return runCatching { - java.text.SimpleDateFormat("h:mm a", java.util.Locale.getDefault()).apply { + val pattern = android.text.format.DateFormat.getBestDateTimePattern(locale, if (is24Hour) "Hm" else "hm") + java.text.SimpleDateFormat(pattern, locale).apply { timeZone = java.util.TimeZone.getTimeZone("UTC") }.format(shifted) }.getOrDefault("")