Merge Show the arrival time in the phone's 12- or 24-hour format (#118)

This commit is contained in:
Seb3thehacker committed 2026-11-29 16:03:31 -08:00
commit 7c7a5b57f1
4 files changed
+14 -8

No files matched your search

@@ -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<ClusterTurn?>(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())
@@ -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()
@@ -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."
@@ -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("")