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

Commit 2a52e3d0 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Initialize keyguard preview w/ sample weather data as fallback

In some preview cases weather data can be slow to load, or not load at
all. In these cases, we'll now fallback to using the sample data that
WPP already uses in some places.

Bug: 285877857
Flag: NONE small bugfix
Test: Manually checked preview case in bug
Change-Id: Ib5fa498ffd390d3a911abac315b5095bede0ac30
parent 5a3c53a1
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.core.text.util.LocalePreferences

typealias WeatherTouchAction = (View) -> Unit

@@ -54,11 +55,34 @@ data class WeatherData(
            }
        }

        private fun readIntFromBundle(extras: Bundle, key: String): Int? =
        private fun readIntFromBundle(extras: Bundle, key: String): Int? {
            try {
                extras.getString(key)?.toInt()
                return extras.getString(key)?.toInt()
            } catch (e: Exception) {
                null
                return null
            }
        }

        fun getPlaceholderWeatherData(): WeatherData {
            return getPlaceholderWeatherData(
                LocalePreferences.getTemperatureUnit() == LocalePreferences.TemperatureUnit.CELSIUS
            )
        }

        private const val DESCRIPTION_PLACEHODLER = ""
        private const val TEMPERATURE_FAHRENHEIT_PLACEHOLDER = 58
        private const val TEMPERATURE_CELSIUS_PLACEHOLDER = 21
        private val WEATHERICON_PLACEHOLDER = WeatherData.WeatherStateIcon.MOSTLY_SUNNY

        fun getPlaceholderWeatherData(useCelsius: Boolean): WeatherData {
            return WeatherData(
                description = DESCRIPTION_PLACEHODLER,
                state = WEATHERICON_PLACEHOLDER,
                temperature =
                    if (useCelsius) TEMPERATURE_CELSIUS_PLACEHOLDER
                    else TEMPERATURE_FAHRENHEIT_PLACEHOLDER,
                useCelsius = useCelsius,
            )
        }
    }

+6 −0
Original line number Diff line number Diff line
@@ -477,6 +477,12 @@ constructor(
        smallClockFrame?.viewTreeObserver?.removeOnGlobalLayoutListener(onGlobalLayoutListener)
    }

    fun setFallbackWeatherData(data: WeatherData) {
        if (weatherData != null) return
        weatherData = data
        clock?.run { events.onWeatherDataChanged(data) }
    }

    /**
     * Sets this clock as showing in a secondary display.
     *
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.systemui.keyguard.ui.viewmodel.OccludingAppDeviceEntryMessage
import com.android.systemui.monet.ColorScheme
import com.android.systemui.monet.Style
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shared.clocks.ClockRegistry
@@ -188,6 +189,7 @@ constructor(
    init {
        coroutineScope = CoroutineScope(applicationScope.coroutineContext + Job())
        disposables += DisposableHandle { coroutineScope.cancel() }
        clockController.setFallbackWeatherData(WeatherData.getPlaceholderWeatherData())

        if (KeyguardBottomAreaRefactor.isEnabled) {
            quickAffordancesCombinedViewModel.enablePreviewMode(