/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package com.android.systemui.bouncer.ui.viewmodel import android.view.View import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor import com.android.systemui.bouncer.shared.model.BouncerShowMessageModel import com.android.systemui.bouncer.ui.BouncerView import com.android.systemui.bouncer.ui.BouncerViewDelegate import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map /** Models UI state for the lock screen bouncer; handles user input. */ @ExperimentalCoroutinesApi class KeyguardBouncerViewModel @Inject constructor( private val view: BouncerView, private val interactor: PrimaryBouncerInteractor, ) { /** Observe on bouncer expansion amount. */ val bouncerExpansionAmount: Flow = interactor.panelExpansionAmount /** Can the user interact with the view? */ val isInteractable: Flow = interactor.isInteractable /** Observe whether bouncer is showing or not. */ val isShowing: Flow = interactor.isShowing /** Observe whether bouncer is starting to hide. */ val startingToHide: Flow = interactor.startingToHide /** Observe whether we want to start the disappear animation. */ val startDisappearAnimation: Flow = interactor.startingDisappearAnimation /** Observe whether we want to update keyguard position. */ val keyguardPosition: Flow = interactor.keyguardPosition /** Observe whether we want to update resources. */ val updateResources: Flow = interactor.resourceUpdateRequests /** Observe whether we want to set a keyguard message when the bouncer shows. */ val bouncerShowMessage: Flow = interactor.showMessage /** Observe whether keyguard is authenticated already. */ val keyguardAuthenticated: Flow = interactor.keyguardAuthenticatedBiometrics /** Observe whether we want to update resources. */ fun notifyUpdateResources() { interactor.notifyUpdatedResources() } /** Notify that keyguard authenticated was handled */ fun notifyKeyguardAuthenticated() { interactor.notifyKeyguardAuthenticatedHandled() } /** Notifies that the message was shown. */ fun onMessageShown() { interactor.onMessageShown() } /** Observe whether back button is enabled. */ fun observeOnIsBackButtonEnabled(systemUiVisibility: () -> Int): Flow { return interactor.isBackButtonEnabled.map { enabled -> var vis: Int = systemUiVisibility() vis = if (enabled) { vis and View.STATUS_BAR_DISABLE_BACK.inv() } else { vis or View.STATUS_BAR_DISABLE_BACK } vis } } /** Set an abstraction that will hold reference to the ui delegate for the bouncer view. */ fun setBouncerViewDelegate(delegate: BouncerViewDelegate?) { view.delegate = delegate } }