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 18 package com.android.systemui.keyguard.ui.binder 19 20 import android.content.res.ColorStateList 21 import android.view.View 22 import androidx.lifecycle.Lifecycle 23 import androidx.lifecycle.repeatOnLifecycle 24 import com.android.app.tracing.coroutines.launch 25 import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor 26 import com.android.systemui.keyguard.ui.view.DeviceEntryIconView 27 import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerUdfpsIconViewModel 28 import com.android.systemui.lifecycle.repeatWhenAttached 29 import kotlinx.coroutines.ExperimentalCoroutinesApi 30 31 @ExperimentalCoroutinesApi 32 object AlternateBouncerUdfpsViewBinder { 33 34 /** Updates UI for the UDFPS icon on the alternate bouncer. */ 35 @JvmStatic 36 fun bind( 37 view: DeviceEntryIconView, 38 viewModel: AlternateBouncerUdfpsIconViewModel, 39 ) { 40 if (DeviceEntryUdfpsRefactor.isUnexpectedlyInLegacyMode()) { 41 return 42 } 43 val fgIconView = view.iconView 44 val bgView = view.bgView 45 46 view.repeatWhenAttached { 47 repeatOnLifecycle(Lifecycle.State.STARTED) { 48 view.alpha = 0f 49 launch("$TAG#viewModel.accessibilityDelegateHint") { 50 viewModel.accessibilityDelegateHint.collect { hint -> 51 view.accessibilityHintType = hint 52 } 53 } 54 55 launch("$TAG#viewModel.alpha") { viewModel.alpha.collect { view.alpha = it } } 56 } 57 } 58 59 fgIconView.repeatWhenAttached { 60 repeatOnLifecycle(Lifecycle.State.STARTED) { 61 viewModel.fgViewModel.collect { fgViewModel -> 62 fgIconView.setImageState( 63 view.getIconState(fgViewModel.type, fgViewModel.useAodVariant), 64 /* merge */ false 65 ) 66 fgIconView.imageTintList = ColorStateList.valueOf(fgViewModel.tint) 67 fgIconView.setPadding( 68 fgViewModel.padding, 69 fgViewModel.padding, 70 fgViewModel.padding, 71 fgViewModel.padding, 72 ) 73 } 74 } 75 } 76 77 bgView.visibility = View.VISIBLE 78 bgView.repeatWhenAttached { 79 repeatOnLifecycle(Lifecycle.State.STARTED) { 80 launch("$TAG#viewModel.bgColor") { 81 viewModel.bgColor.collect { color -> 82 bgView.imageTintList = ColorStateList.valueOf(color) 83 } 84 } 85 launch("$TAG#viewModel.bgAlpha") { 86 viewModel.bgAlpha.collect { alpha -> bgView.alpha = alpha } 87 } 88 } 89 } 90 } 91 92 private const val TAG = "AlternateBouncerUdfpsViewBinder" 93 } 94