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.CommunalSettingsInteractor 21 import com.android.systemui.communal.shared.model.CommunalBackgroundType 22 import com.android.systemui.dagger.SysUISingleton 23 import com.android.systemui.keyguard.domain.interactor.FromPrimaryBouncerTransitionInteractor.Companion.TO_GLANCEABLE_HUB_DURATION 24 import com.android.systemui.keyguard.shared.model.Edge 25 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB 26 import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER 27 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 28 import com.android.systemui.keyguard.ui.transitions.BlurConfig 29 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 30 import com.android.systemui.keyguard.ui.transitions.PrimaryBouncerTransition 31 import javax.inject.Inject 32 import kotlinx.coroutines.flow.Flow 33 import kotlinx.coroutines.flow.filter 34 import kotlinx.coroutines.flow.flatMapLatest 35 36 @SysUISingleton 37 class PrimaryBouncerToGlanceableHubTransitionViewModel 38 @Inject 39 constructor( 40 blurConfig: BlurConfig, 41 animationFlow: KeyguardTransitionAnimationFlow, 42 communalSettingsInteractor: CommunalSettingsInteractor, 43 ) : DeviceEntryIconTransition, PrimaryBouncerTransition { 44 private val transitionAnimation = 45 animationFlow 46 .setup(duration = TO_GLANCEABLE_HUB_DURATION, edge = Edge.INVALID) 47 .setupWithoutSceneContainer(edge = Edge.create(PRIMARY_BOUNCER, GLANCEABLE_HUB)) 48 49 override val deviceEntryParentViewAlpha: Flow<Float> = 50 transitionAnimation.immediatelyTransitionTo(1f) 51 52 override val windowBlurRadius: Flow<Float> = 53 if (Flags.glanceableHubBlurredBackground()) { 54 communalSettingsInteractor.communalBackground <lambda>null55 .filter { it != CommunalBackgroundType.BLUR } <lambda>null56 .flatMapLatest { 57 transitionAnimation.immediatelyTransitionTo(blurConfig.minBlurRadiusPx) 58 } 59 } else { 60 transitionAnimation.immediatelyTransitionTo(blurConfig.minBlurRadiusPx) 61 } 62 63 override val notificationBlurRadius: Flow<Float> = 64 transitionAnimation.immediatelyTransitionTo(0.0f) 65 } 66