• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.graphics.Color
21 import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor
22 import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor
23 import com.android.systemui.keyguard.DismissCallbackRegistry
24 import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
25 import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER
26 import com.android.systemui.scene.shared.flag.SceneContainerFlag
27 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
28 import dagger.Lazy
29 import javax.inject.Inject
30 import kotlinx.coroutines.flow.Flow
31 import kotlinx.coroutines.flow.distinctUntilChanged
32 import kotlinx.coroutines.flow.flowOf
33 import kotlinx.coroutines.flow.map
34 import kotlinx.coroutines.flow.onEach
35 
36 class AlternateBouncerViewModel
37 @Inject
38 constructor(
39     private val statusBarKeyguardViewManager: StatusBarKeyguardViewManager,
40     keyguardTransitionInteractor: KeyguardTransitionInteractor,
41     private val dismissCallbackRegistry: DismissCallbackRegistry,
42     alternateBouncerInteractor: Lazy<AlternateBouncerInteractor>,
43     private val primaryBouncerInteractor: PrimaryBouncerInteractor,
44 ) {
45     // When we're fully transitioned to the AlternateBouncer, the alpha of the scrim should be:
46     private val alternateBouncerScrimAlpha = .66f
47 
48     /** Reports the alternate bouncer visible state if the scene container flag is enabled. */
49     val isVisible: Flow<Boolean> =
<lambda>null50         alternateBouncerInteractor.get().isVisible.onEach {
51             SceneContainerFlag.unsafeAssertInNewMode()
52         }
53 
54     /** Progress to a fully transitioned alternate bouncer. 1f represents fully transitioned. */
55     val transitionToAlternateBouncerProgress: Flow<Float> =
56         keyguardTransitionInteractor.transitionValue(ALTERNATE_BOUNCER)
57 
58     /** An observable for the scrim alpha. */
<lambda>null59     val scrimAlpha = transitionToAlternateBouncerProgress.map { it * alternateBouncerScrimAlpha }
60 
61     /** An observable for the scrim color. Change color for easier debugging. */
62     val scrimColor: Flow<Int> = flowOf(Color.BLACK)
63 
64     val registerForDismissGestures: Flow<Boolean> =
<lambda>null65         transitionToAlternateBouncerProgress.map { it == 1f }.distinctUntilChanged()
66 
onTappednull67     fun onTapped() {
68         statusBarKeyguardViewManager.showPrimaryBouncer(
69             /* scrimmed */ true,
70             "AlternateBouncerViewModel#onTapped",
71         )
72     }
73 
onRemovedFromWindownull74     fun onRemovedFromWindow() {
75         statusBarKeyguardViewManager.hideAlternateBouncer(false)
76     }
77 
onBackRequestednull78     fun onBackRequested() {
79         statusBarKeyguardViewManager.hideAlternateBouncer(false)
80         dismissCallbackRegistry.notifyDismissCancelled()
81         primaryBouncerInteractor.setDismissAction(null, null)
82     }
83 }
84