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.pipeline.icons.shared.model
18 
19 /**
20  * A BindableIcon describes a status bar icon that can be housed in the [ModernStatusBarView]
21  * created by [initializer]. They can be registered statically for [BindableIconsRepositoryImpl].
22  *
23  * Typical usage would be to create an (@SysUISingleton) adapter class that implements the
24  * interface. For example:
25  * ```
26  * @SysuUISingleton
27  * class MyBindableIconAdapter
28  * @Inject constructor(
29  *     // deps
30  *     val viewModel: MyViewModel
31  * ) : BindableIcon {
32  *     override val slot = "icon_slot_name"
33  *
34  *     override val initializer = ModernStatusBarViewCreator() {
35  *         SingleBindableStatusBarIconView.createView(context).also { iconView ->
36  *             MyIconViewBinder.bind(iconView, viewModel)
37  *         }
38  *     }
39  *
40  *     override fun shouldBind() = Flags.myFlag()
41  * }
42  * ```
43  *
44  * By defining this adapter (and injecting it into the repository), we get our icon registered with
45  * the legacy StatusBarIconController while proxying all updates to the view binder that is created
46  * elsewhere.
47  *
48  * Note that the initializer block defines a closure that can pull in the viewModel dependency
49  * without us having to store it directly in the icon controller.
50  */
51 interface BindableIcon {
52     val slot: String
53     val initializer: ModernStatusBarViewCreator
54     val shouldBindIcon: Boolean
55 }
56