diff options
5 files changed, 51 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt index 641e20b4a3fc..16ad29aeb734 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt @@ -21,12 +21,17 @@ import android.provider.Settings import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyguard.shared.model.SettingsClockSize +import com.android.systemui.plugins.ClockId +import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.util.settings.SecureSettings import com.android.systemui.util.settings.SettingsProxyExt.observerFlow import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.withContext @@ -35,6 +40,7 @@ class KeyguardClockRepository @Inject constructor( private val secureSettings: SecureSettings, + private val clockRegistry: ClockRegistry, @Background private val backgroundDispatcher: CoroutineDispatcher, ) { @@ -47,6 +53,24 @@ constructor( .onStart { emit(Unit) } // Forces an initial update. .map { getClockSize() } + val currentClockId: Flow<ClockId> = + callbackFlow { + fun send() { + trySend(clockRegistry.currentClockId) + } + + val listener = + object : ClockRegistry.ClockChangeListener { + override fun onCurrentClockChanged() { + send() + } + } + clockRegistry.registerClockChangeListener(listener) + send() + awaitClose { clockRegistry.unregisterClockChangeListener(listener) } + } + .mapNotNull { it } + private suspend fun getClockSize(): SettingsClockSize { return withContext(backgroundDispatcher) { if ( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt index 98f445c4419a..dad5831d6d4f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt @@ -20,6 +20,7 @@ package com.android.systemui.keyguard.domain.interactor import com.android.systemui.dagger.SysUISingleton import com.android.systemui.keyguard.data.repository.KeyguardClockRepository import com.android.systemui.keyguard.shared.model.SettingsClockSize +import com.android.systemui.plugins.ClockId import javax.inject.Inject import kotlinx.coroutines.flow.Flow @@ -31,4 +32,6 @@ constructor( repository: KeyguardClockRepository, ) { val selectedClockSize: Flow<SettingsClockSize> = repository.selectedClockSize + + val currentClockId: Flow<ClockId> = repository.currentClockId } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt index 387e9a6ff74c..f5e4c6adcb91 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt @@ -18,10 +18,12 @@ package com.android.systemui.keyguard.ui.binder import android.view.View +import androidx.core.view.isInvisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel import com.android.systemui.lifecycle.repeatWhenAttached +import kotlinx.coroutines.launch /** Binder for the small clock view, large clock view and smartspace. */ object KeyguardPreviewSmartspaceViewBinder { @@ -31,10 +33,11 @@ object KeyguardPreviewSmartspaceViewBinder { smartspace: View, viewModel: KeyguardPreviewSmartspaceViewModel, ) { - smartspace.repeatWhenAttached { repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.smartSpaceTopPadding.collect { smartspace.setTopPadding(it) } + launch { viewModel.smartspaceTopPadding.collect { smartspace.setTopPadding(it) } } + + launch { viewModel.shouldHideSmartspace.collect { smartspace.isInvisible = it } } } } } 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 f9a8b988a27f..fe62bf4388e9 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 @@ -240,7 +240,7 @@ constructor( smartSpaceView?.let { it.setPaddingRelative(startPadding, topPadding, endPadding, 0) it.isClickable = false - + it.isInvisible = true parentView.addView( it, FrameLayout.LayoutParams( @@ -399,9 +399,6 @@ constructor( updateLargeClock(clock) updateSmallClock(clock) - - // Hide smart space if the clock has weather display; otherwise show it - hideSmartspace(clock.largeClock.config.hasCustomWeatherDataDisplay) } private fun updateLargeClock(clock: ClockController) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt index e60bb3412c31..bf51976e27f0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt @@ -24,6 +24,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor import com.android.systemui.keyguard.shared.model.SettingsClockSize import javax.inject.Inject import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map /** View model for the smartspace. */ @@ -34,7 +35,7 @@ constructor( interactor: KeyguardClockInteractor, ) { - val smartSpaceTopPadding: Flow<Int> = + val smartspaceTopPadding: Flow<Int> = interactor.selectedClockSize.map { when (it) { SettingsClockSize.DYNAMIC -> getLargeClockSmartspaceTopPadding(context.resources) @@ -42,6 +43,22 @@ constructor( } } + val shouldHideSmartspace: Flow<Boolean> = + combine( + interactor.selectedClockSize, + interactor.currentClockId, + ::Pair, + ) + .map { (size, currentClockId) -> + when (size) { + // TODO (b/284122375) This is temporary. We should use clockController + // .largeClock.config.hasCustomWeatherDataDisplay instead, but + // ClockRegistry.createCurrentClock is not reliable. + SettingsClockSize.DYNAMIC -> currentClockId == "DIGITAL_CLOCK_WEATHER" + SettingsClockSize.SMALL -> false + } + } + companion object { fun getLargeClockSmartspaceTopPadding(resources: Resources): Int { return with(resources) { |