From 1a3e4f501f4082ef1b69b42dc0e55e77cc736032 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 6 Jul 2026 16:05:43 +0200 Subject: [PATCH] fix(edit): time picker dial honours the app 24h/12h setting (#27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The event-form (and Settings) time picker seeded is24Hour from the system TIME_12_24 override / device locale, ignoring the app's own TimeFormatPref. So with the app set to 24h under an English locale the dial still showed AM/PM, while every time label (which reads LocalUse24HourFormat) showed 24h. Seed the picker from LocalUse24HourFormat — the app-wide clock convention already resolved once at the root from TimeFormatPref — so the dial matches the labels. Drops the now-unused deviceUses24HourClock helper. Co-Authored-By: Claude Opus 4.8 --- .../calendula/ui/common/TimePickerAlert.kt | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimePickerAlert.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimePickerAlert.kt index d161728..3426433 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimePickerAlert.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimePickerAlert.kt @@ -4,14 +4,9 @@ import androidx.compose.material3.AlertDialog import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Text import androidx.compose.material3.TextButton -import android.content.Context -import android.content.res.Resources -import android.provider.Settings -import android.text.format.DateFormat import androidx.compose.material3.TimePicker import androidx.compose.material3.rememberTimePickerState import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import de.jeanlucmakiola.calendula.R import kotlinx.datetime.LocalTime @@ -27,10 +22,13 @@ fun TimePickerAlert( onConfirm: (LocalTime) -> Unit, onDismiss: () -> Unit, ) { + // Honour the app's own time-format preference (the value every time label + // reads), not the system/locale clock — otherwise an explicit 24h setting + // still showed an AM/PM dial (issue #27). val state = rememberTimePickerState( initialHour = initial.hour, initialMinute = initial.minute, - is24Hour = deviceUses24HourClock(LocalContext.current), + is24Hour = LocalUse24HourFormat.current, ) AlertDialog( onDismissRequest = onDismiss, @@ -45,24 +43,3 @@ fun TimePickerAlert( text = { TimePicker(state = state) }, ) } - -/** - * Whether the clock should read 24-hour, matching the rest of the device. - * - * [DateFormat.is24HourFormat] resolves a "locale default" system setting against - * the *app's* context locale — and this app applies a per-app language - * (AppCompatDelegate), so an English UI on a German-region phone would wrongly - * read 12-hour while the system clock shows 24-hour. So we honour an explicit - * system 12/24 override, and otherwise fall back to the **device** locale - * (Resources.getSystem), not the app's. - */ -private fun deviceUses24HourClock(context: Context): Boolean = - when (Settings.System.getString(context.contentResolver, Settings.System.TIME_12_24)) { - "24" -> true - "12" -> false - // 'a' is the AM/PM marker; a best-fit pattern without it is 24-hour. - else -> { - val deviceLocale = Resources.getSystem().configuration.locales[0] - !DateFormat.getBestDateTimePattern(deviceLocale, "jm").contains('a') - } - }