1 /* <lambda>null2 * 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 package com.android.systemui.keyguard.ui.viewmodel 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryUdfpsInteractor 21 import com.android.systemui.keyguard.domain.interactor.FromGoneTransitionInteractor.Companion.TO_DOZING_DURATION 22 import com.android.systemui.keyguard.shared.model.Edge 23 import com.android.systemui.keyguard.shared.model.KeyguardState.DOZING 24 import com.android.systemui.keyguard.shared.model.KeyguardState.GONE 25 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 26 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 27 import com.android.systemui.scene.shared.model.Scenes 28 import javax.inject.Inject 29 import kotlin.time.Duration.Companion.milliseconds 30 import kotlinx.coroutines.flow.Flow 31 import kotlinx.coroutines.flow.emptyFlow 32 import kotlinx.coroutines.flow.flatMapLatest 33 34 /** Breaks down GONE->DOZING transition into discrete steps for corresponding views to consume. */ 35 @SysUISingleton 36 class GoneToDozingTransitionViewModel 37 @Inject 38 constructor( 39 deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor, 40 animationFlow: KeyguardTransitionAnimationFlow, 41 ) : DeviceEntryIconTransition { 42 43 private val transitionAnimation = 44 animationFlow 45 .setup( 46 duration = TO_DOZING_DURATION, 47 edge = Edge.create(from = Scenes.Gone, to = DOZING), 48 ) 49 .setupWithoutSceneContainer( 50 edge = Edge.create(from = GONE, to = DOZING), 51 ) 52 53 val lockscreenAlpha: Flow<Float> = 54 transitionAnimation.sharedFlow( 55 duration = 500.milliseconds, 56 onStep = { 0f }, 57 onCancel = { 1f }, 58 onFinish = { 1f }, 59 ) 60 61 val notificationAlpha: Flow<Float> = 62 transitionAnimation.sharedFlow( 63 duration = 500.milliseconds, 64 onStep = { 1f - it }, 65 // Needs to be 1f in order for HUNs to appear on AOD 66 onFinish = { 1f }, 67 ) 68 69 val deviceEntryBackgroundViewAlpha: Flow<Float> = 70 transitionAnimation.immediatelyTransitionTo(0f) 71 72 override val deviceEntryParentViewAlpha: Flow<Float> = 73 deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { 74 isUdfpsEnrolledAndEnabled -> 75 if (isUdfpsEnrolledAndEnabled) { 76 transitionAnimation.immediatelyTransitionTo(1f) 77 } else { 78 emptyFlow() 79 } 80 } 81 } 82