1 /* <lambda>null2 * Copyright (C) 2022 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 android.animation.ValueAnimator 20 import androidx.lifecycle.Lifecycle 21 import androidx.lifecycle.repeatOnLifecycle 22 import com.android.app.animation.Interpolators.ALPHA_IN 23 import com.android.app.tracing.coroutines.launchTraced as launch 24 import com.android.systemui.keyguard.ui.viewmodel.LightRevealScrimViewModel 25 import com.android.systemui.lifecycle.repeatWhenAttached 26 import com.android.systemui.shared.Flags.ambientAod 27 import com.android.systemui.statusbar.LightRevealScrim 28 import com.android.systemui.wallpapers.ui.viewmodel.WallpaperViewModel 29 30 object LightRevealScrimViewBinder { 31 @JvmStatic 32 fun bind( 33 revealScrim: LightRevealScrim, 34 viewModel: LightRevealScrimViewModel, 35 wallpaperViewModel: WallpaperViewModel, 36 ) { 37 revealScrim.repeatWhenAttached { 38 repeatOnLifecycle(Lifecycle.State.CREATED) { 39 if (ambientAod()) { 40 launch("$TAG#wallpaperViewModel.wallpaperSupportsAmbientMode") { 41 wallpaperViewModel.wallpaperSupportsAmbientMode.collect { 42 viewModel.setWallpaperSupportsAmbientMode(it) 43 } 44 } 45 launch("$TAG#viewModel.maxAlpha") { 46 var animator: ValueAnimator? = null 47 viewModel.maxAlpha.collect { (alpha, animate) -> 48 if (alpha != revealScrim.alpha) { 49 animator?.cancel() 50 if (!animate) { 51 revealScrim.alpha = alpha 52 } else { 53 animator = 54 ValueAnimator.ofFloat(revealScrim.alpha, alpha).apply { 55 startDelay = 333 56 duration = 733 57 interpolator = ALPHA_IN 58 addUpdateListener { animation -> 59 revealScrim.alpha = 60 animation.getAnimatedValue() as Float 61 } 62 start() 63 } 64 } 65 } 66 } 67 } 68 } 69 70 launch("$TAG#viewModel.revealAmount") { 71 viewModel.revealAmount.collect { revealScrim.revealAmount = it } 72 } 73 74 launch("$TAG#viewModel.lightRevealEffect") { 75 viewModel.lightRevealEffect.collect { effect -> 76 revealScrim.revealEffect = effect 77 } 78 } 79 } 80 } 81 } 82 83 private const val TAG = "LightRevealScrimViewBinder" 84 } 85