1 /*
2  * Copyright (C) 2022 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.pipeline.mobile.ui.binder
18 
19 import android.view.View
20 import androidx.lifecycle.Lifecycle
21 import androidx.lifecycle.repeatOnLifecycle
22 import com.android.systemui.lifecycle.repeatWhenAttached
23 import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager
24 import com.android.systemui.statusbar.pipeline.mobile.ui.MobileUiAdapter
25 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModel
26 import kotlinx.coroutines.flow.collect
27 import kotlinx.coroutines.launch
28 
29 object MobileIconsBinder {
30     /**
31      * Start this ViewModel collecting on the list of mobile subscriptions in the scope of [view]
32      * which is passed in and managed by [IconManager]. Once the subscription list flow starts
33      * collecting, [MobileUiAdapter] will send updates to the icon manager.
34      */
35     @JvmStatic
36     fun bind(view: View, viewModel: MobileIconsViewModel) {
37         view.repeatWhenAttached {
38             repeatOnLifecycle(Lifecycle.State.STARTED) {
39                 launch {
40                     viewModel.subscriptionIdsFlow.collect {
41                         // TODO(b/249790733): This is an empty collect, because [MobileUiAdapter]
42                         //  sets up a side-effect in this flow to trigger the methods on
43                         // [StatusBarIconController] which allows for this pipeline to be a data
44                         // source for the mobile icons.
45                     }
46                 }
47             }
48         }
49     }
50 }
51