1 /* <lambda>null2 * 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.app.animation.Interpolators 20 import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.keyguard.shared.model.Edge 23 import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING 24 import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB 25 import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow 26 import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition 27 import com.android.systemui.res.R 28 import com.android.systemui.scene.shared.model.Scenes 29 import javax.inject.Inject 30 import kotlin.time.Duration.Companion.milliseconds 31 import kotlin.time.Duration.Companion.seconds 32 import kotlinx.coroutines.ExperimentalCoroutinesApi 33 import kotlinx.coroutines.flow.Flow 34 import kotlinx.coroutines.flow.flatMapLatest 35 import kotlinx.coroutines.flow.map 36 37 @OptIn(ExperimentalCoroutinesApi::class) 38 @SysUISingleton 39 class GlanceableHubToDreamingTransitionViewModel 40 @Inject 41 constructor( 42 animationFlow: KeyguardTransitionAnimationFlow, 43 configurationInteractor: ConfigurationInteractor, 44 ) : DeviceEntryIconTransition { 45 46 private val transitionAnimation = 47 animationFlow 48 .setup( 49 duration = FROM_GLANCEABLE_HUB_DURATION, 50 edge = Edge.create(from = Scenes.Communal, to = DREAMING), 51 ) 52 .setupWithoutSceneContainer( 53 edge = Edge.create(from = GLANCEABLE_HUB, to = DREAMING), 54 ) 55 56 val dreamOverlayAlpha: Flow<Float> = 57 transitionAnimation.sharedFlow( 58 duration = 167.milliseconds, 59 startTime = 167.milliseconds, 60 onStep = { it }, 61 name = "GLANCEABLE_HUB->DREAMING: dreamOverlayAlpha", 62 ) 63 64 val dreamOverlayTranslationX: Flow<Float> = 65 configurationInteractor 66 .dimensionPixelSize(R.dimen.hub_to_dreaming_transition_dream_overlay_translation_x) 67 .flatMapLatest { translatePx: Int -> 68 transitionAnimation.sharedFlow( 69 duration = FROM_GLANCEABLE_HUB_DURATION, 70 onStep = { value -> -translatePx + value * translatePx }, 71 interpolator = Interpolators.EMPHASIZED, 72 onCancel = { -translatePx.toFloat() }, 73 name = "GLANCEABLE_HUB->LOCKSCREEN: dreamOverlayTranslationX" 74 ) 75 } 76 77 // Show UMO until transition finishes. 78 val showUmo: Flow<Boolean> = 79 transitionAnimation 80 .sharedFlow( 81 duration = FROM_GLANCEABLE_HUB_DURATION, 82 onStep = { it }, 83 onCancel = { 0f }, 84 onFinish = { 1f }, 85 ) 86 .map { step -> step != 1f } 87 88 override val deviceEntryParentViewAlpha: Flow<Float> = 89 transitionAnimation.sharedFlow( 90 duration = 167.milliseconds, 91 onStep = { 1 - it }, 92 onCancel = { 1f }, 93 onFinish = { 0f }, 94 ) 95 96 private companion object { 97 val FROM_GLANCEABLE_HUB_DURATION = 1.seconds 98 } 99 } 100