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