• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.Flags
20 import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
21 import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
22 import com.android.systemui.communal.shared.model.CommunalBackgroundType
23 import com.android.systemui.dagger.SysUISingleton
24 import com.android.systemui.keyguard.domain.interactor.FromGlanceableHubTransitionInteractor
25 import com.android.systemui.keyguard.shared.model.Edge
26 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB
27 import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
28 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
29 import com.android.systemui.keyguard.ui.transitions.BlurConfig
30 import com.android.systemui.keyguard.ui.transitions.PrimaryBouncerTransition
31 import com.android.systemui.statusbar.policy.KeyguardStateController
32 import javax.inject.Inject
33 import kotlinx.coroutines.ExperimentalCoroutinesApi
34 import kotlinx.coroutines.flow.Flow
35 import kotlinx.coroutines.flow.filter
36 import kotlinx.coroutines.flow.flatMapLatest
37 
38 @OptIn(ExperimentalCoroutinesApi::class)
39 @SysUISingleton
40 class GlanceableHubToPrimaryBouncerTransitionViewModel
41 @Inject
42 constructor(
43     private val blurConfig: BlurConfig,
44     animationFlow: KeyguardTransitionAnimationFlow,
45     private val communalSettingsInteractor: CommunalSettingsInteractor,
46     private val communalSceneInteractor: CommunalSceneInteractor,
47     private val keyguardStateController: KeyguardStateController,
48 ) : PrimaryBouncerTransition {
49     private val transitionAnimation =
50         animationFlow
51             .setup(
52                 duration = FromGlanceableHubTransitionInteractor.TO_BOUNCER_DURATION,
53                 edge = Edge.INVALID,
54             )
55             .setupWithoutSceneContainer(edge = Edge.create(GLANCEABLE_HUB, PRIMARY_BOUNCER))
56 
57     override val windowBlurRadius: Flow<Float> =
58         if (Flags.glanceableHubBlurredBackground()) {
59             communalSettingsInteractor.communalBackground
<lambda>null60                 .filter { it != CommunalBackgroundType.BLUR }
<lambda>null61                 .flatMapLatest {
62                     transitionAnimation.immediatelyTransitionTo(blurConfig.maxBlurRadiusPx)
63                 }
64         } else {
65             transitionAnimation.immediatelyTransitionTo(blurConfig.maxBlurRadiusPx)
66         }
67 
68     /** Whether to delay the animation to fade in bouncer elements. */
willDelayAppearAnimationnull69     fun willDelayAppearAnimation(isLandscape: Boolean): Boolean =
70         communalSettingsInteractor.isV2FlagEnabled() &&
71             communalSceneInteractor.isIdleOnCommunal.value &&
72             !keyguardStateController.isKeyguardScreenRotationAllowed() &&
73             isLandscape
74 
75     override val notificationBlurRadius: Flow<Float> =
76         transitionAnimation.immediatelyTransitionTo(0.0f)
77 }
78