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.lifecycle.repeatWhenAttached
23 import com.android.systemui.statusbar.notification.collection.NotifCollection
24 import com.android.systemui.statusbar.notification.icon.ui.viewbinder.NotificationIconContainerViewBinder.IconViewStore
25 import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconContainerStatusBarViewModel
26 import com.android.systemui.statusbar.phone.NotificationIconContainer
27 import com.android.systemui.statusbar.ui.SystemBarUtilsState
28 import javax.inject.Inject
29 import kotlinx.coroutines.DisposableHandle
30 import kotlinx.coroutines.launch
31 
32 /** Binds a [NotificationIconContainer] to a [NotificationIconContainerStatusBarViewModel]. */
33 class NotificationIconContainerStatusBarViewBinder
34 @Inject
35 constructor(
36     private val viewModel: NotificationIconContainerStatusBarViewModel,
37     private val configuration: ConfigurationState,
38     private val systemBarUtilsState: SystemBarUtilsState,
39     private val failureTracker: StatusBarIconViewBindingFailureTracker,
40     private val viewStore: StatusBarNotificationIconViewStore,
41 ) {
bindWhileAttachednull42     fun bindWhileAttached(view: NotificationIconContainer): DisposableHandle {
43         return traceSection("NICStatusBar#bindWhileAttached") {
44             view.repeatWhenAttached {
45                 lifecycleScope.launch {
46                     NotificationIconContainerViewBinder.bind(
47                         view = view,
48                         viewModel = viewModel,
49                         configuration = configuration,
50                         systemBarUtilsState = systemBarUtilsState,
51                         failureTracker = failureTracker,
52                         viewStore = viewStore,
53                     )
54                 }
55             }
56         }
57     }
58 }
59 
60 /** [IconViewStore] for the status bar. */
61 class StatusBarNotificationIconViewStore @Inject constructor(notifCollection: NotifCollection) :
<lambda>null62     IconViewStore by (notifCollection.iconViewStoreBy { it.statusBarIcon })
63