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

Commit aa5e46e2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert LockscreenSmartspaceController.isWeatherEnabled to a flow" into main

parents 2a48aff1 58cfffc6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -76,4 +76,9 @@ interface KeyguardRepositoryModule {
    @Binds fun trustRepository(impl: TrustRepositoryImpl): TrustRepository

    @Binds fun keyguardClockRepository(impl: KeyguardClockRepositoryImpl): KeyguardClockRepository

    @Binds
    fun keyguardSmartspaceRepository(
        impl: KeyguardSmartspaceRepositoryImpl
    ): KeyguardSmartspaceRepository
}
+52 −3
Original line number Diff line number Diff line
@@ -16,19 +16,68 @@

package com.android.systemui.keyguard.data.repository

import android.content.Context
import android.provider.Settings
import android.view.View
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.settings.UserTracker
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn

interface KeyguardSmartspaceRepository {
    val bcSmartspaceVisibility: StateFlow<Int>
    val isWeatherEnabled: StateFlow<Boolean>
    fun setBcSmartspaceVisibility(visibility: Int)
}

@SysUISingleton
class KeyguardSmartspaceRepository @Inject constructor() {
class KeyguardSmartspaceRepositoryImpl
@Inject
constructor(
    context: Context,
    private val secureSettings: SecureSettings,
    private val userTracker: UserTracker,
    @Application private val applicationScope: CoroutineScope,
) : KeyguardSmartspaceRepository {
    private val _bcSmartspaceVisibility: MutableStateFlow<Int> = MutableStateFlow(View.GONE)
    val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility.asStateFlow()
    override val bcSmartspaceVisibility: StateFlow<Int> = _bcSmartspaceVisibility.asStateFlow()
    val defaultValue =
        context.resources.getBoolean(
            com.android.internal.R.bool.config_lockscreenWeatherEnabledByDefault
        )
    override val isWeatherEnabled: StateFlow<Boolean> =
        secureSettings
            .observerFlow(
                names = arrayOf(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED),
                userId = userTracker.userId,
            )
            .onStart { emit(Unit) }
            .map { getLockscreenWeatherEnabled() }
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = getLockscreenWeatherEnabled()
            )

    fun setBcSmartspaceVisibility(visibility: Int) {
    override fun setBcSmartspaceVisibility(visibility: Int) {
        _bcSmartspaceVisibility.value = visibility
    }

    private fun getLockscreenWeatherEnabled(): Boolean {
        return secureSettings.getIntForUser(
            Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED,
            if (defaultValue) 1 else 0,
            userTracker.userId
        ) == 1
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ constructor(
    private val keyguardSmartspaceRepository: KeyguardSmartspaceRepository,
) {
    val bcSmartspaceVisibility: StateFlow<Int> = keyguardSmartspaceRepository.bcSmartspaceVisibility
    val isWeatherEnabled: StateFlow<Boolean> = keyguardSmartspaceRepository.isWeatherEnabled

    fun setBcSmartspaceVisibility(visibility: Int) {
        keyguardSmartspaceRepository.setBcSmartspaceVisibility(visibility)
+9 −15
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ constructor(
    val context: Context,
    val keyguardClockViewModel: KeyguardClockViewModel,
    val keyguardSmartspaceViewModel: KeyguardSmartspaceViewModel,
    val keyguardSmartspaceInteractor: KeyguardSmartspaceInteractor,
    private val keyguardSmartspaceInteractor: KeyguardSmartspaceInteractor,
    val smartspaceController: LockscreenSmartspaceController,
    val keyguardUnlockAnimationController: KeyguardUnlockAnimationController,
    val blueprintInteractor: Lazy<KeyguardBlueprintInteractor>,
    private val blueprintInteractor: Lazy<KeyguardBlueprintInteractor>,
) : KeyguardSection() {
    private var smartspaceView: View? = null
    private var weatherView: View? = null
@@ -61,13 +61,11 @@ constructor(
        weatherView = smartspaceController.buildAndConnectWeatherView(constraintLayout)
        dateView = smartspaceController.buildAndConnectDateView(constraintLayout)
        pastVisibility = smartspaceView?.visibility ?: View.GONE
        if (keyguardSmartspaceViewModel.isSmartspaceEnabled) {
        constraintLayout.addView(smartspaceView)
        if (keyguardSmartspaceViewModel.isDateWeatherDecoupled) {
            constraintLayout.addView(weatherView)
            constraintLayout.addView(dateView)
        }
        }
        keyguardUnlockAnimationController.lockscreenSmartspace = smartspaceView
        smartspaceVisibilityListener = OnGlobalLayoutListener {
            smartspaceView?.let {
@@ -205,14 +203,10 @@ constructor(

        constraintSet.apply {
            val weatherVisibility =
                when (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) {
                    true -> ConstraintSet.GONE
                    false ->
                        when (keyguardSmartspaceViewModel.isWeatherEnabled) {
                when (keyguardSmartspaceViewModel.isWeatherVisible.value) {
                    true -> ConstraintSet.VISIBLE
                    false -> ConstraintSet.GONE
                }
                }
            setVisibility(sharedR.id.weather_smartspace_view, weatherVisibility)
            setAlpha(
                sharedR.id.weather_smartspace_view,
+2 −2
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ constructor(
        combine(
                isLargeClockVisible,
                currentClock,
            ) { isLargeClock, clock ->
                clock?.let { clock ->
            ) { isLargeClock, currentClock ->
                currentClock?.let { clock ->
                    val face = if (isLargeClock) clock.largeClock else clock.smallClock
                    face.config.hasCustomWeatherDataDisplay
                }
Loading