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 package com.android.systemui.communal.ui.viewmodel 18 19 import com.android.systemui.communal.domain.interactor.CommunalTutorialInteractor 20 import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor 21 import javax.inject.Inject 22 import kotlinx.coroutines.flow.Flow 23 import kotlinx.coroutines.flow.MutableStateFlow 24 import kotlinx.coroutines.flow.StateFlow 25 import kotlinx.coroutines.flow.asStateFlow 26 import kotlinx.coroutines.flow.distinctUntilChanged 27 28 /** View model for communal tutorial indicator on keyguard */ 29 class CommunalTutorialIndicatorViewModel 30 @Inject 31 constructor( 32 private val communalTutorialInteractor: CommunalTutorialInteractor, 33 bottomAreaInteractor: KeyguardBottomAreaInteractor, 34 ) { 35 /** 36 * An observable for whether the tutorial indicator view should be visible. 37 * 38 * @param isPreviewMode Whether for preview keyguard mode in wallpaper settings. 39 */ showIndicatornull40 fun showIndicator(isPreviewMode: Boolean): StateFlow<Boolean> { 41 return if (isPreviewMode) { 42 MutableStateFlow(false).asStateFlow() 43 } else { 44 communalTutorialInteractor.isTutorialAvailable 45 } 46 } 47 48 /** An observable for the alpha level for the tutorial indicator. */ 49 val alpha: Flow<Float> = bottomAreaInteractor.alpha.distinctUntilChanged() 50 } 51