• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2022 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.bouncer.ui.viewmodel
18 
19 import android.view.View
20 import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor
21 import com.android.systemui.bouncer.shared.model.BouncerShowMessageModel
22 import com.android.systemui.bouncer.ui.BouncerView
23 import com.android.systemui.bouncer.ui.BouncerViewDelegate
24 import javax.inject.Inject
25 import kotlinx.coroutines.flow.Flow
26 import kotlinx.coroutines.flow.map
27 
28 /** Models UI state for the lock screen bouncer; handles user input. */
29 class KeyguardBouncerViewModel
30 @Inject
31 constructor(
32     private val view: BouncerView,
33     private val interactor: PrimaryBouncerInteractor,
34 ) {
35     /** Observe on bouncer expansion amount. */
36     val bouncerExpansionAmount: Flow<Float> = interactor.panelExpansionAmount
37 
38     /** Can the user interact with the view? */
39     val isInteractable: Flow<Boolean> = interactor.isInteractable
40 
41     /** Observe whether bouncer is showing or not. */
42     val isShowing: Flow<Boolean> = interactor.isShowing
43 
44     /** Observe whether bouncer is starting to hide. */
45     val startingToHide: Flow<Unit> = interactor.startingToHide
46 
47     /** Observe whether we want to start the disappear animation. */
48     val startDisappearAnimation: Flow<Runnable> = interactor.startingDisappearAnimation
49 
50     /** Observe whether we want to update keyguard position. */
51     val keyguardPosition: Flow<Float> = interactor.keyguardPosition
52 
53     /** Observe whether we want to update resources. */
54     val updateResources: Flow<Boolean> = interactor.resourceUpdateRequests
55 
56     /** Observe whether we want to set a keyguard message when the bouncer shows. */
57     val bouncerShowMessage: Flow<BouncerShowMessageModel> = interactor.showMessage
58 
59     /** Observe whether keyguard is authenticated already. */
60     val keyguardAuthenticated: Flow<Boolean> = interactor.keyguardAuthenticatedBiometrics
61 
62     /** Observe whether we want to update resources. */
63     fun notifyUpdateResources() {
64         interactor.notifyUpdatedResources()
65     }
66 
67     /** Notify that keyguard authenticated was handled */
68     fun notifyKeyguardAuthenticated() {
69         interactor.notifyKeyguardAuthenticatedHandled()
70     }
71 
72     /** Notifies that the message was shown. */
73     fun onMessageShown() {
74         interactor.onMessageShown()
75     }
76 
77     /** Observe whether back button is enabled. */
78     fun observeOnIsBackButtonEnabled(systemUiVisibility: () -> Int): Flow<Int> {
79         return interactor.isBackButtonEnabled.map { enabled ->
80             var vis: Int = systemUiVisibility()
81             vis =
82                 if (enabled) {
83                     vis and View.STATUS_BAR_DISABLE_BACK.inv()
84                 } else {
85                     vis or View.STATUS_BAR_DISABLE_BACK
86                 }
87             vis
88         }
89     }
90 
91     /** Set an abstraction that will hold reference to the ui delegate for the bouncer view. */
92     fun setBouncerViewDelegate(delegate: BouncerViewDelegate?) {
93         view.delegate = delegate
94     }
95 }
96