Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d62b1fac authored by Hawkwood's avatar Hawkwood
Browse files

Update child formatters for large clock with correct time format

Root cause was Ic522121ba8de7374caa0120e2c07ee2ca8e314ab which was
intended to dedupe Calendar and SimpleDateFormat. The formatters are
only partially shared and as a result a couple of additional objects
weren't correctly receiving the updated time format.

While it shouldn't be nessecary (as the calendar is fully shared) I'm
also defensively adding a similar update to TimeZone to ensure it's
correct when refreshing the time immediately after a change.

Bug: 417649342
Test: Manually checked large clock 24hr format
Flag: com.android.systemui.shared.clock_reactive_variants
Change-Id: Ieeb7825b71f3b56bc93841e8ffb18ea96e7e97e5
parent d8d3c589
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ class FlexClockFaceController(
        }

        override fun onLocaleChanged(locale: Locale) {
            timeFormatter.updateLocale(locale)
            timeFormatter.locale = locale
            layerController.events.onLocaleChanged(locale)
        }

+3 −1
Original line number Diff line number Diff line
@@ -123,15 +123,17 @@ open class SimpleDigitalHandLayerController(
            override var isReactiveTouchInteractionEnabled = false

            override fun onLocaleChanged(locale: Locale) {
                timespec.formatter.updateLocale(locale)
                timespec.formatter.locale = locale
                refreshTime()
            }

            override fun onTimeFormatChanged(formatKind: TimeFormatKind) {
                timespec.formatter.formatKind = formatKind
                refreshTime()
            }

            override fun onTimeZoneChanged(timeZone: TimeZone) {
                timespec.formatter.timeKeeper.timeZone = timeZone
                refreshTime()
            }

+26 −14
Original line number Diff line number Diff line
@@ -43,9 +43,11 @@ open class TimeKeeperImpl(private val cal: Calendar = Calendar.getInstance()) :
    override var timeZone: TimeZone
        get() = cal.timeZone
        set(value) {
            if (cal.timeZone != value) {
                cal.timeZone = value
                callbacks.forEach { it.onTimeZoneChanged() }
            }
        }

    override val callbacks = mutableListOf<TimeKeeper.Callback>()

@@ -82,35 +84,45 @@ private fun TimeFormatKind.getContentDescriptionPattern(pattern: String): String

class DigitalTimeFormatter(
    val pattern: String,
    private val timeKeeper: TimeKeeper,
    private val enableContentDescription: Boolean = false,
    val timeKeeper: TimeKeeper,
    val enableContentDescription: Boolean = false,
) : TimeKeeper.Callback {
    var formatKind = TimeFormatKind.HALF_DAY
        set(value) {
            if (field != value) {
                field = value
                applyPattern()
            }
        }

    var locale = Locale.getDefault()
        set(value) {
            if (field != value) {
                field = value
                onLocaleChanged()
            }
        }

    private lateinit var textFormat: SimpleDateFormat
    private var contentDescriptionFormat: SimpleDateFormat? = null

    init {
        timeKeeper.callbacks.add(this)
        updateLocale(Locale.getDefault())
        onLocaleChanged()
    }

    override fun onTimeZoneChanged() {
        textFormat.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id)
        contentDescriptionFormat?.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id)
        applyPattern()
    }

    fun updateLocale(locale: Locale) {
    fun onLocaleChanged() {
        textFormat = getTextFormat(locale)
        contentDescriptionFormat = getContentDescriptionFormat(locale)
        onTimeZoneChanged()
    }

    override fun onTimeZoneChanged() {
        textFormat.timeZone = timeKeeper.timeZone
        contentDescriptionFormat?.timeZone = timeKeeper.timeZone
        applyPattern()
    }

    private fun getTextFormat(locale: Locale): SimpleDateFormat {
        if (locale.language.equals(Locale.ENGLISH.language)) {
            // force date format in English, and time format to use format defined in json