diff options
3 files changed, 35 insertions, 3 deletions
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/WeatherData.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/WeatherData.kt index 789a47304ecf..f920b187e7e5 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/WeatherData.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/WeatherData.kt @@ -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,12 +55,35 @@ 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, + ) + } } // Values for WeatherStateIcon must stay in sync with go/g3-WeatherStateIcon diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt index 5dcf1618ed6b..c1eae2e53a44 100644 --- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt @@ -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. * diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt index 51ce3556ffbd..9ccfb5000f97 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt @@ -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( |