• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.keyguard.ui.binder
18 
19 import com.android.systemui.keyguard.ui.view.InWindowLauncherUnlockAnimationManager
20 import com.android.systemui.keyguard.ui.viewmodel.InWindowLauncherAnimationViewModel
21 import kotlinx.coroutines.CoroutineScope
22 import com.android.app.tracing.coroutines.launchTraced as launch
23 
24 /**
25  * Binds the [InWindowLauncherUnlockAnimationManager] "view", which manages the lifecycle and state
26  * of the in-window Launcher animation.
27  */
28 object InWindowLauncherAnimationViewBinder {
29 
30     @JvmStatic
31     fun bind(
32         viewModel: InWindowLauncherAnimationViewModel,
33         inWindowLauncherUnlockAnimationManager: InWindowLauncherUnlockAnimationManager,
34         scope: CoroutineScope
35     ) {
36         scope.launch {
37             viewModel.shouldPrepareForInWindowAnimation.collect { shouldPrepare ->
38                 if (shouldPrepare) {
39                     inWindowLauncherUnlockAnimationManager.prepareForUnlock()
40                 } else {
41                     // If we no longer meet the conditions to prepare for unlock, we'll need to
42                     // manually set Launcher unlocked if we didn't start the unlock animation, or it
43                     // will remain "prepared" (blank) forever.
44                     inWindowLauncherUnlockAnimationManager.ensureUnlockedOrAnimatingUnlocked()
45                 }
46             }
47         }
48 
49         scope.launch {
50             viewModel.shouldStartInWindowAnimation.collect { shouldStart ->
51                 if (shouldStart) {
52                     inWindowLauncherUnlockAnimationManager.playUnlockAnimation(unlocked = true)
53                 } else {
54                     // Once the conditions to start the animation are no longer met, clear whether
55                     // we started the animation, since we'll need to start it again if the
56                     // conditions become true again.
57                     inWindowLauncherUnlockAnimationManager.clearStartedUnlockAnimation()
58                 }
59             }
60         }
61     }
62 }
63