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.FromPrimaryBouncerTransitionInteractor
22 import com.android.systemui.keyguard.shared.model.Edge
23 import com.android.systemui.keyguard.shared.model.KeyguardState.AOD
24 import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
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.ExperimentalCoroutinesApi
31 import kotlinx.coroutines.flow.Flow
32 import kotlinx.coroutines.flow.emptyFlow
33 import kotlinx.coroutines.flow.flatMapLatest
34 
35 /**
36  * Breaks down PRIMARY BOUNCER->AOD transition into discrete steps for corresponding views to
37  * consume.
38  */
39 @ExperimentalCoroutinesApi
40 @SysUISingleton
41 class PrimaryBouncerToAodTransitionViewModel
42 @Inject
43 constructor(
44     deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor,
45     animationFlow: KeyguardTransitionAnimationFlow,
46 ) : DeviceEntryIconTransition {
47     private val transitionAnimation =
48         animationFlow
49             .setup(
50                 duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION,
51                 edge = Edge.create(from = Scenes.Bouncer, to = AOD),
52             )
53             .setupWithoutSceneContainer(
54                 edge = Edge.create(from = PRIMARY_BOUNCER, to = AOD),
55             )
56 
57     val deviceEntryBackgroundViewAlpha: Flow<Float> =
58         transitionAnimation.immediatelyTransitionTo(0f)
59 
60     val lockscreenAlpha: Flow<Float> =
61         transitionAnimation.sharedFlow(
62             duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION,
63             onStep = { it }
64         )
65 
66     override val deviceEntryParentViewAlpha: Flow<Float> =
67         deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest {
68             isUdfpsEnrolledAndEnabled ->
69             if (isUdfpsEnrolledAndEnabled) {
70                 transitionAnimation.sharedFlow(
71                     duration = 300.milliseconds,
72                     onStep = { it },
73                     onFinish = { 1f },
74                 )
75             } else {
76                 emptyFlow()
77             }
78         }
79 }
80