1 /*
<lambda>null2  * Copyright (C) 2024 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.emptyshade.ui.viewbinder
18 
19 import android.view.View
20 import com.android.systemui.statusbar.notification.NotificationActivityStarter
21 import com.android.systemui.statusbar.notification.emptyshade.ui.view.EmptyShadeView
22 import com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel.EmptyShadeViewModel
23 import kotlinx.coroutines.coroutineScope
24 import com.android.app.tracing.coroutines.launchTraced as launch
25 
26 object EmptyShadeViewBinder {
27     suspend fun bind(
28         view: EmptyShadeView,
29         viewModel: EmptyShadeViewModel,
30         notificationActivityStarter: NotificationActivityStarter,
31     ) = coroutineScope {
32         launch { viewModel.text.collect { view.setText(it) } }
33 
34         launch {
35             viewModel.onClick.collect { settingsIntent ->
36                 val onClickListener = { view: View ->
37                     notificationActivityStarter.startSettingsIntent(view, settingsIntent)
38                 }
39                 view.setOnClickListener(onClickListener)
40             }
41         }
42 
43         launch { bindFooter(view, viewModel) }
44     }
45 
46     private suspend fun bindFooter(view: EmptyShadeView, viewModel: EmptyShadeViewModel) =
47         coroutineScope {
48             // Bind the resource IDs
49             view.setFooterText(viewModel.footer.messageId)
50             view.setFooterIcon(viewModel.footer.iconId)
51 
52             launch {
53                 viewModel.footer.isVisible.collect { visible ->
54                     view.setFooterVisibility(if (visible) View.VISIBLE else View.GONE)
55                 }
56             }
57         }
58 }
59