• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.shelf.ui.viewbinder
18 
19 import com.android.app.tracing.coroutines.launchTraced as launch
20 import com.android.app.tracing.traceSection
21 import com.android.systemui.Flags
22 import com.android.systemui.plugins.FalsingManager
23 import com.android.systemui.scene.shared.flag.SceneContainerFlag
24 import com.android.systemui.statusbar.NotificationShelf
25 import com.android.systemui.statusbar.notification.icon.ui.viewbinder.NotificationIconContainerShelfViewBinder
26 import com.android.systemui.statusbar.notification.row.ui.viewbinder.ActivatableNotificationViewBinder
27 import com.android.systemui.statusbar.notification.shelf.ui.viewmodel.NotificationShelfViewModel
28 import kotlinx.coroutines.awaitCancellation
29 import kotlinx.coroutines.coroutineScope
30 
31 /** Binds a [NotificationShelf] to its [view model][NotificationShelfViewModel]. */
32 object NotificationShelfViewBinder {
bindnull33     suspend fun bind(
34         shelf: NotificationShelf,
35         viewModel: NotificationShelfViewModel,
36         falsingManager: FalsingManager,
37         nicBinder: NotificationIconContainerShelfViewBinder,
38     ): Unit = coroutineScope {
39         ActivatableNotificationViewBinder.bind(viewModel, shelf, falsingManager)
40         shelf.apply {
41             traceSection("NotifShelf#bindShelfIcons") { launch { nicBinder.bind(shelfIcons) } }
42             launch {
43                 viewModel.canModifyColorOfNotifications.collect(::setCanModifyColorOfNotifications)
44             }
45             launch { viewModel.isClickable.collect(::setCanInteract) }
46 
47             if (SceneContainerFlag.isEnabled) {
48                 launch { viewModel.isAlignedToEnd.collect(::setAlignedToEnd) }
49             }
50 
51             if (Flags.notificationRowTransparency()) {
52                 launch { viewModel.isBlurSupported.collect(shelf::setIsBlurSupported) }
53             }
54 
55             registerViewListenersWhileAttached(shelf, viewModel)
56         }
57     }
58 
registerViewListenersWhileAttachednull59     private suspend fun registerViewListenersWhileAttached(
60         shelf: NotificationShelf,
61         viewModel: NotificationShelfViewModel,
62     ) {
63         try {
64             shelf.setOnClickListener { viewModel.onShelfClicked() }
65             awaitCancellation()
66         } finally {
67             shelf.setOnClickListener(null)
68         }
69     }
70 }
71