Add style to BinaryClock for 24-hour time (#1190)

* Add style to BinaryClock for 24-hour time

* Use global time format preference for all clock widget styles

* Add support for time format preference to remaining clock styles

---------

Co-authored-by: MM20 <15646950+MM2-0@users.noreply.github.com>
This commit is contained in:
Oscar Ronberg
2025-02-24 18:56:19 +01:00
committed by GitHub
co-authored by MM20
parent 4330b2a712
commit 5240431348
11 changed files with 158 additions and 44 deletions
@@ -34,6 +34,7 @@ data class LauncherSettingsData internal constructor(
val clockWidgetCustom: ClockWidgetStyle.Custom = ClockWidgetStyle.Custom(),
val clockWidgetColors: ClockWidgetColors = ClockWidgetColors.Auto,
val clockWidgetShowSeconds: Boolean = false,
val clockWidgetTimeFormat: TimeFormat = TimeFormat.System,
val clockWidgetUseThemeColor: Boolean = false,
val clockWidgetAlarmPart: Boolean = true,
val clockWidgetBatteryPart: Boolean = true,
@@ -408,4 +409,11 @@ enum class KeyboardFilterBarItem {
@SerialName("events") Events,
@SerialName("tools") Tools,
@SerialName("hidden") HiddenResults,
}
@Serializable
enum class TimeFormat {
@SerialName("system") System,
@SerialName("12h") TwelveHour,
@SerialName("24h") TwentyFourHour
}
@@ -5,6 +5,7 @@ import de.mm20.launcher2.preferences.ClockWidgetColors
import de.mm20.launcher2.preferences.ClockWidgetStyle
import de.mm20.launcher2.preferences.ClockWidgetStyleEnum
import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.preferences.TimeFormat
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
@@ -137,6 +138,15 @@ class ClockWidgetSettings internal constructor(
}
}
val timeFormat
get() = launcherDataStore.data.map { it.clockWidgetTimeFormat }
fun setTimeFormat(timeFormat: TimeFormat) {
launcherDataStore.update {
it.copy(clockWidgetTimeFormat = timeFormat)
}
}
val useThemeColor
get() = launcherDataStore.data.map { it.clockWidgetUseThemeColor }