1 /*
2  * 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.statusbar.notification.icon.ui.viewbinder
18 
19 import androidx.lifecycle.lifecycleScope
20 import com.android.app.tracing.traceSection
21 import com.android.systemui.common.ui.ConfigurationState
22 import com.android.systemui.keyguard.ui.binder.KeyguardRootViewBinder
23 import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel
24 import com.android.systemui.lifecycle.repeatWhenAttached
25 import com.android.systemui.statusbar.notification.collection.NotifCollection
26 import com.android.systemui.statusbar.notification.icon.ui.viewbinder.NotificationIconContainerViewBinder.IconViewStore
27 import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconContainerAlwaysOnDisplayViewModel
28 import com.android.systemui.statusbar.phone.NotificationIconContainer
29 import com.android.systemui.statusbar.phone.ScreenOffAnimationController
30 import com.android.systemui.statusbar.ui.SystemBarUtilsState
31 import javax.inject.Inject
32 import kotlinx.coroutines.DisposableHandle
33 import kotlinx.coroutines.launch
34 
35 /** Binds a [NotificationIconContainer] to a [NotificationIconContainerAlwaysOnDisplayViewModel]. */
36 class NotificationIconContainerAlwaysOnDisplayViewBinder
37 @Inject
38 constructor(
39     private val viewModel: NotificationIconContainerAlwaysOnDisplayViewModel,
40     private val keyguardRootViewModel: KeyguardRootViewModel,
41     private val configuration: ConfigurationState,
42     private val failureTracker: StatusBarIconViewBindingFailureTracker,
43     private val screenOffAnimationController: ScreenOffAnimationController,
44     private val systemBarUtilsState: SystemBarUtilsState,
45     private val viewStore: AlwaysOnDisplayNotificationIconViewStore,
46 ) {
bindWhileAttachednull47     fun bindWhileAttached(view: NotificationIconContainer): DisposableHandle {
48         return traceSection("NICAlwaysOnDisplay#bindWhileAttached") {
49             view.repeatWhenAttached {
50                 lifecycleScope.launch {
51                     launch {
52                         NotificationIconContainerViewBinder.bind(
53                             view = view,
54                             viewModel = viewModel,
55                             configuration = configuration,
56                             systemBarUtilsState = systemBarUtilsState,
57                             failureTracker = failureTracker,
58                             viewStore = viewStore,
59                         )
60                     }
61                     launch {
62                         KeyguardRootViewBinder.bindAodNotifIconVisibility(
63                             view = view,
64                             isVisible = keyguardRootViewModel.isNotifIconContainerVisible,
65                             configuration = configuration,
66                             screenOffAnimationController = screenOffAnimationController,
67                         )
68                     }
69                 }
70             }
71         }
72     }
73 }
74 
75 /** [IconViewStore] for the always-on display. */
76 class AlwaysOnDisplayNotificationIconViewStore
77 @Inject
78 constructor(notifCollection: NotifCollection) :
<lambda>null79     IconViewStore by (notifCollection.iconViewStoreBy { it.aodIcon })
80