1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package com.android.systemui.keyguard.ui.viewmodel 19 20 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor 21 import com.android.systemui.keyguard.shared.model.KeyguardRootViewVisibilityState 22 import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots 23 import kotlinx.coroutines.ExperimentalCoroutinesApi 24 import kotlinx.coroutines.flow.Flow 25 import kotlinx.coroutines.flow.distinctUntilChanged 26 import kotlinx.coroutines.flow.flatMapLatest 27 import kotlinx.coroutines.flow.flowOf 28 import javax.inject.Inject 29 30 @OptIn(ExperimentalCoroutinesApi::class) 31 class KeyguardRootViewModel 32 @Inject 33 constructor( 34 private val keyguardInteractor: KeyguardInteractor, 35 private val keyguardQuickAffordancesCombinedViewModel: KeyguardQuickAffordancesCombinedViewModel 36 ) 37 { 38 /** Represents the current state of the KeyguardRootView visibility */ 39 val keyguardRootViewVisibilityState: Flow<KeyguardRootViewVisibilityState> = 40 keyguardInteractor.keyguardRootViewVisibilityState 41 42 /** An observable for the alpha level for the entire keyguard root view. */ 43 val alpha: Flow<Float> = 44 keyguardInteractor.previewMode.flatMapLatest { 45 if (it.isInPreviewMode) { 46 flowOf(1f) 47 } else { 48 keyguardInteractor.keyguardAlpha.distinctUntilChanged() 49 } 50 } 51 52 /** 53 * Puts this view-model in "preview mode", which means it's being used for UI that is rendering 54 * the lock screen preview in wallpaper picker / settings and not the real experience on the 55 * lock screen. 56 * 57 * @param initiallySelectedSlotId The ID of the initial slot to render as the selected one. 58 * @param shouldHighlightSelectedAffordance Whether the selected quick affordance should be 59 * highlighted (while all others are dimmed to make the selected one stand out). 60 */ 61 fun enablePreviewMode( 62 initiallySelectedSlotId: String?, 63 shouldHighlightSelectedAffordance: Boolean, 64 ) { 65 keyguardInteractor.previewMode.value = 66 KeyguardInteractor.PreviewMode( 67 isInPreviewMode = true, 68 shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, 69 ) 70 keyguardQuickAffordancesCombinedViewModel.onPreviewSlotSelected( 71 initiallySelectedSlotId ?: KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START 72 ) 73 } 74 75 }