diff options
| author | 2023-08-17 19:11:07 +0000 | |
|---|---|---|
| committer | 2023-08-17 19:11:07 +0000 | |
| commit | 060c95128a10ebfe763739a79e11309476213654 (patch) | |
| tree | ce65966909f8b5f1dab8b6f080cb3b1e1cbfba85 | |
| parent | 33adcdf669b6ed3b945d844953982410d8159f31 (diff) | |
| parent | caed383330294e53562048ea81bcda0c1598baca (diff) | |
Merge "Avoid using the same previewMode logic between lockscreen and WPP" into main
6 files changed, 141 insertions, 116 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt index 562c4db44be6..ed84884fca14 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt @@ -40,10 +40,10 @@ import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.keyguard.shared.model.WakefulnessModel import com.android.systemui.statusbar.CommandQueue import com.android.systemui.util.kotlin.sample +import javax.inject.Inject import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged @@ -53,7 +53,6 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart -import javax.inject.Inject /** * Encapsulates business-logic related to the keyguard but not to a more specific part within it. @@ -68,18 +67,6 @@ constructor( bouncerRepository: KeyguardBouncerRepository, configurationRepository: ConfigurationRepository, ) { - - data class PreviewMode( - val isInPreviewMode: Boolean = false, - val shouldHighlightSelectedAffordance: Boolean = false, - ) - - /** - * Whether this view-model instance is powering the preview experience that renders exclusively - * in the wallpaper picker application. This should _always_ be `false` for the real lock screen - * experience. - */ - val previewMode = MutableStateFlow(PreviewMode()) /** * The amount of doze the system is in, where `1.0` is fully dozing and `0.0` is not dozing at * all. 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 dd3da97d398f..41c1c9600561 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 @@ -49,6 +49,7 @@ import com.android.systemui.keyguard.ui.binder.KeyguardBlueprintViewBinder import com.android.systemui.keyguard.ui.binder.KeyguardPreviewClockViewBinder import com.android.systemui.keyguard.ui.binder.KeyguardPreviewSmartspaceViewBinder import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder +import com.android.systemui.keyguard.ui.binder.KeyguardRootViewBinder import com.android.systemui.keyguard.ui.view.KeyguardRootView import com.android.systemui.keyguard.ui.viewmodel.KeyguardBlueprintViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel @@ -56,25 +57,31 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel +import com.android.systemui.keyguard.ui.viewmodel.OccludingAppDeviceEntryMessageViewModel import com.android.systemui.monet.ColorScheme import com.android.systemui.plugins.ClockController import com.android.systemui.plugins.FalsingManager import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.clocks.DefaultClockController import com.android.systemui.shared.clocks.shared.model.ClockPreviewConstants +import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants import com.android.systemui.statusbar.KeyguardIndicationController import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController import com.android.systemui.statusbar.phone.KeyguardBottomAreaView +import com.android.systemui.statusbar.policy.KeyguardStateController +import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator import dagger.assisted.Assisted import dagger.assisted.AssistedInject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.DisposableHandle +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking /** Renders the preview of the lock screen. */ class KeyguardPreviewRenderer +@OptIn(ExperimentalCoroutinesApi::class) @AssistedInject constructor( @Application private val context: Context, @@ -99,6 +106,9 @@ constructor( @Assisted bundle: Bundle, private val keyguardBlueprintViewModel: KeyguardBlueprintViewModel, private val keyguardBlueprintInteractor: KeyguardBlueprintInteractor, + private val occludingAppDeviceEntryMessageViewModel: OccludingAppDeviceEntryMessageViewModel, + private val chipbarCoordinator: ChipbarCoordinator, + private val keyguardStateController: KeyguardStateController, ) { val hostToken: IBinder? = bundle.getBinder(KEY_HOST_TOKEN) @@ -130,19 +140,21 @@ constructor( init { if (featureFlags.isEnabled(Flags.MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA)) { - keyguardRootViewModel.enablePreviewMode( + keyguardRootViewModel.enablePreviewMode() + quickAffordancesCombinedViewModel.enablePreviewMode( initiallySelectedSlotId = - bundle.getString( - KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID, - ), + bundle.getString( + KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID, + ) + ?: KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, ) } else { bottomAreaViewModel.enablePreviewMode( initiallySelectedSlotId = - bundle.getString( - KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID, - ), + bundle.getString( + KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID, + ), shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, ) } @@ -163,17 +175,8 @@ constructor( val rootView = FrameLayout(context) if (featureFlags.isEnabled(Flags.MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA)) { - val keyguardRootView = KeyguardRootView(context, null) - rootView.addView( - keyguardRootView, - FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.MATCH_PARENT, - ), - ) - setupShortcuts(keyguardRootView) - KeyguardBlueprintViewBinder.bind(keyguardRootView, keyguardBlueprintViewModel) - keyguardBlueprintInteractor.refreshBlueprint() + setupKeyguardRootView(rootView) + setupShortcuts(rootView) } else { setUpBottomArea(rootView) } @@ -314,7 +317,7 @@ constructor( false, ) as KeyguardBottomAreaView bottomAreaView.init( - viewModel = bottomAreaViewModel, + viewModel = bottomAreaViewModel, ) parentView.addView( bottomAreaView, @@ -325,10 +328,34 @@ constructor( ) } - private fun setupShortcuts(keyguardRootView: KeyguardRootView) { + @OptIn(ExperimentalCoroutinesApi::class) + private fun setupKeyguardRootView(rootView: FrameLayout) { + val keyguardRootView = KeyguardRootView(context, null) + disposables.add( + KeyguardRootViewBinder.bind( + keyguardRootView, + keyguardRootViewModel, + featureFlags, + occludingAppDeviceEntryMessageViewModel, + chipbarCoordinator, + keyguardStateController, + ) + ) + rootView.addView( + keyguardRootView, + FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT, + ), + ) + KeyguardBlueprintViewBinder.bind(keyguardRootView, keyguardBlueprintViewModel) + keyguardBlueprintInteractor.refreshBlueprint() + } + + private fun setupShortcuts(rootView: FrameLayout) { shortcutsBindings.add( KeyguardQuickAffordanceViewBinder.bind( - keyguardRootView.requireViewById(R.id.start_button), + rootView.requireViewById(R.id.start_button), quickAffordancesCombinedViewModel.startButton, keyguardRootViewModel.alpha, falsingManager, @@ -340,7 +367,7 @@ constructor( shortcutsBindings.add( KeyguardQuickAffordanceViewBinder.bind( - keyguardRootView.requireViewById(R.id.end_button), + rootView.requireViewById(R.id.end_button), quickAffordancesCombinedViewModel.endButton, keyguardRootViewModel.alpha, falsingManager, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt index 56a98455d8b3..02ea5508f34f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt @@ -18,22 +18,20 @@ package com.android.systemui.keyguard.ui.viewmodel import androidx.annotation.VisibleForTesting -import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel import com.android.systemui.keyguard.shared.quickaffordance.ActivationState import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map -import javax.inject.Inject @OptIn(ExperimentalCoroutinesApi::class) class KeyguardQuickAffordancesCombinedViewModel @@ -43,6 +41,18 @@ constructor( private val keyguardInteractor: KeyguardInteractor, ) { + data class PreviewMode( + val isInPreviewMode: Boolean = false, + val shouldHighlightSelectedAffordance: Boolean = false, + ) + + /** + * Whether this view-model instance is powering the preview experience that renders exclusively + * in the wallpaper picker application. This should _always_ be `false` for the real lock screen + * experience. + */ + private val previewMode = MutableStateFlow(PreviewMode()) + /** * ID of the slot that's currently selected in the preview that renders exclusively in the * wallpaper picker application. This is ignored for the actual, real lock screen experience. @@ -85,39 +95,63 @@ constructor( selectedPreviewSlotId.value = slotId } + /** + * Puts this view-model in "preview mode", which means it's being used for UI that is rendering + * the lock screen preview in wallpaper picker / settings and not the real experience on the + * lock screen. + * + * @param initiallySelectedSlotId The ID of the initial slot to render as the selected one. + * @param shouldHighlightSelectedAffordance Whether the selected quick affordance should be + * highlighted (while all others are dimmed to make the selected one stand out). + */ + fun enablePreviewMode( + initiallySelectedSlotId: String?, + shouldHighlightSelectedAffordance: Boolean, + ) { + val newPreviewMode = + PreviewMode( + isInPreviewMode = true, + shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, + ) + onPreviewSlotSelected( + initiallySelectedSlotId ?: KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START + ) + previewMode.value = newPreviewMode + } + private fun button( position: KeyguardQuickAffordancePosition ): Flow<KeyguardQuickAffordanceViewModel> { - return keyguardInteractor.previewMode.flatMapLatest { previewMode -> + return previewMode.flatMapLatest { previewMode -> combine( - if (previewMode.isInPreviewMode) { - quickAffordanceInteractor.quickAffordanceAlwaysVisible(position = position) - } else { - quickAffordanceInteractor.quickAffordance(position = position) - }, - keyguardInteractor.animateDozingTransitions.distinctUntilChanged(), - areQuickAffordancesFullyOpaque, - selectedPreviewSlotId, - quickAffordanceInteractor.useLongPress(), - ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId, useLongPress -> - val slotId = position.toSlotId() - val isSelected = selectedPreviewSlotId == slotId - model.toViewModel( - animateReveal = !previewMode.isInPreviewMode && animateReveal, - isClickable = isFullyOpaque && !previewMode.isInPreviewMode, - isSelected = - previewMode.isInPreviewMode && - previewMode.shouldHighlightSelectedAffordance && - isSelected, - isDimmed = - previewMode.isInPreviewMode && - previewMode.shouldHighlightSelectedAffordance && - !isSelected, - forceInactive = previewMode.isInPreviewMode, - slotId = slotId, - useLongPress = useLongPress, - ) - } + if (previewMode.isInPreviewMode) { + quickAffordanceInteractor.quickAffordanceAlwaysVisible(position = position) + } else { + quickAffordanceInteractor.quickAffordance(position = position) + }, + keyguardInteractor.animateDozingTransitions.distinctUntilChanged(), + areQuickAffordancesFullyOpaque, + selectedPreviewSlotId, + quickAffordanceInteractor.useLongPress(), + ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId, useLongPress -> + val slotId = position.toSlotId() + val isSelected = selectedPreviewSlotId == slotId + model.toViewModel( + animateReveal = !previewMode.isInPreviewMode && animateReveal, + isClickable = isFullyOpaque && !previewMode.isInPreviewMode, + isSelected = + previewMode.isInPreviewMode && + previewMode.shouldHighlightSelectedAffordance && + isSelected, + isDimmed = + previewMode.isInPreviewMode && + previewMode.shouldHighlightSelectedAffordance && + !isSelected, + forceInactive = previewMode.isInPreviewMode, + slotId = slotId, + useLongPress = useLongPress, + ) + } .distinctUntilChanged() } } @@ -167,8 +201,6 @@ constructor( // time, we don't want the number to be too close to 1.0 such that there is a chance that we // never treat the affordance UI as "fully opaque" as that would risk making it forever not // clickable. - @VisibleForTesting - const val AFFORDANCE_FULLY_OPAQUE_ALPHA_THRESHOLD = 0.95f + @VisibleForTesting const val AFFORDANCE_FULLY_OPAQUE_ALPHA_THRESHOLD = 0.95f } - -}
\ No newline at end of file +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt index 316ca771bf8f..92b9ee4cb134 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt @@ -19,29 +19,37 @@ package com.android.systemui.keyguard.ui.viewmodel import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.shared.model.KeyguardRootViewVisibilityState -import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf -import javax.inject.Inject @OptIn(ExperimentalCoroutinesApi::class) class KeyguardRootViewModel @Inject constructor( private val keyguardInteractor: KeyguardInteractor, - private val keyguardQuickAffordancesCombinedViewModel: KeyguardQuickAffordancesCombinedViewModel -) -{ +) { + + data class PreviewMode(val isInPreviewMode: Boolean = false) + + /** + * Whether this view-model instance is powering the preview experience that renders exclusively + * in the wallpaper picker application. This should _always_ be `false` for the real lock screen + * experience. + */ + private val previewMode = MutableStateFlow(PreviewMode()) + /** Represents the current state of the KeyguardRootView visibility */ val keyguardRootViewVisibilityState: Flow<KeyguardRootViewVisibilityState> = keyguardInteractor.keyguardRootViewVisibilityState /** An observable for the alpha level for the entire keyguard root view. */ val alpha: Flow<Float> = - keyguardInteractor.previewMode.flatMapLatest { + previewMode.flatMapLatest { if (it.isInPreviewMode) { flowOf(1f) } else { @@ -53,23 +61,9 @@ constructor( * Puts this view-model in "preview mode", which means it's being used for UI that is rendering * the lock screen preview in wallpaper picker / settings and not the real experience on the * lock screen. - * - * @param initiallySelectedSlotId The ID of the initial slot to render as the selected one. - * @param shouldHighlightSelectedAffordance Whether the selected quick affordance should be - * highlighted (while all others are dimmed to make the selected one stand out). */ - fun enablePreviewMode( - initiallySelectedSlotId: String?, - shouldHighlightSelectedAffordance: Boolean, - ) { - keyguardInteractor.previewMode.value = - KeyguardInteractor.PreviewMode( - isInPreviewMode = true, - shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, - ) - keyguardQuickAffordancesCombinedViewModel.onPreviewSlotSelected( - initiallySelectedSlotId ?: KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START - ) + fun enablePreviewMode() { + val newPreviewMode = PreviewMode(true) + previewMode.value = newPreviewMode } - -}
\ No newline at end of file +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt index ef38d54dc42f..3576ec9601e3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt @@ -281,11 +281,7 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { underTest.onPreviewSlotSelected( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START ) - keyguardInteractor.previewMode.value = - KeyguardInteractor.PreviewMode( - isInPreviewMode = true, - shouldHighlightSelectedAffordance = true, - ) + underTest.enablePreviewMode(KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, true) repository.setKeyguardShowing(false) val latest = collectLastValue(underTest.startButton) @@ -330,11 +326,7 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { underTest.onPreviewSlotSelected( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START ) - keyguardInteractor.previewMode.value = - KeyguardInteractor.PreviewMode( - isInPreviewMode = true, - shouldHighlightSelectedAffordance = true, - ) + underTest.enablePreviewMode(KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, true) repository.setKeyguardShowing(false) val endButton = collectLastValue(underTest.endButton) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt index 05e933b9d572..a14a1c536f87 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt @@ -45,7 +45,6 @@ class KeyguardRootViewModelTest : SysuiTestCase() { private lateinit var testScope: TestScope private lateinit var repository: FakeKeyguardRepository private lateinit var keyguardInteractor: KeyguardInteractor - @Mock private lateinit var keyguardQuickAffordancesCombinedViewModel: KeyguardQuickAffordancesCombinedViewModel @Before fun setUp() { @@ -63,10 +62,7 @@ class KeyguardRootViewModelTest : SysuiTestCase() { keyguardInteractor = withDeps.keyguardInteractor repository = withDeps.repository - underTest = KeyguardRootViewModel( - keyguardInteractor, - keyguardQuickAffordancesCombinedViewModel, - ) + underTest = KeyguardRootViewModel(keyguardInteractor) } @Test @@ -89,10 +85,7 @@ class KeyguardRootViewModelTest : SysuiTestCase() { fun alpha_inPreviewMode_doesNotChange() = testScope.runTest { val value = collectLastValue(underTest.alpha) - underTest.enablePreviewMode( - initiallySelectedSlotId = null, - shouldHighlightSelectedAffordance = false, - ) + underTest.enablePreviewMode() Truth.assertThat(value()).isEqualTo(1f) repository.setKeyguardAlpha(0.1f) @@ -104,4 +97,4 @@ class KeyguardRootViewModelTest : SysuiTestCase() { repository.setKeyguardAlpha(0f) Truth.assertThat(value()).isEqualTo(1f) } -}
\ No newline at end of file +} |