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.controls.panels
18 
19 import android.content.ComponentName
20 import com.android.systemui.controls.ui.ControlsUiController
21 import com.android.systemui.controls.ui.SelectedItem
22 import com.android.systemui.flags.Flags
23 
24 /** Stores user-selected preferred component. */
25 interface SelectedComponentRepository {
26 
27     /**
28      * Returns currently set preferred component, or null when nothing is set. Consider using
29      * [ControlsUiController.getPreferredSelectedItem] to get domain specific data
30      */
31     fun getSelectedComponent(): SelectedComponent?
32 
33     /** Sets preferred component. Use [getSelectedComponent] to get current one */
34     fun setSelectedComponent(selectedComponent: SelectedComponent)
35 
36     /** Clears current preferred component. [getSelectedComponent] will return null afterwards */
37     fun removeSelectedComponent()
38 
39     /**
40      * Return true when default preferred component should be set up and false the otherwise. This
41      * is always true when [Flags.APP_PANELS_REMOVE_APPS_ALLOWED] is disabled
42      */
43     fun shouldAddDefaultComponent(): Boolean
44 
45     /**
46      * Sets if default component should be added. This is ignored when
47      * [Flags.APP_PANELS_REMOVE_APPS_ALLOWED] is disabled
48      */
49     fun setShouldAddDefaultComponent(shouldAdd: Boolean)
50 
51     data class SelectedComponent(
52         val name: String,
53         val componentName: ComponentName?,
54         val isPanel: Boolean,
55     ) {
56         constructor(
57             selectedItem: SelectedItem
58         ) : this(
59             name = selectedItem.name.toString(),
60             componentName = selectedItem.componentName,
61             isPanel = selectedItem is SelectedItem.PanelItem,
62         )
63     }
64 }
65