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

Commit f4883225 authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

Merge "Initialize keyguard preview w/ sample weather data as fallback" into main

parents 0dedbd47 2a52e3d0
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(