blob: 4ef64a5cddbfc6bab0a4fbd08241c1ea916dfa76 [file] [log] [blame]
Fabian Kozynski1e3178d2020-02-19 09:32:27 -05001/*
2 * Copyright (C) 2019 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
17package com.android.systemui.controls.management
18
Fabian Kozynski8765d352020-04-06 21:16:02 -040019import android.content.ComponentName
Matt Pietala2e20852020-06-22 09:36:48 -040020import android.graphics.drawable.Icon
Fabian Kozynski8765d352020-04-06 21:16:02 -040021import androidx.recyclerview.widget.RecyclerView
22import com.android.systemui.controls.ControlInterface
Fabian Kozynski1e3178d2020-02-19 09:32:27 -050023import com.android.systemui.controls.ControlStatus
24import com.android.systemui.controls.controller.ControlInfo
25
26/**
27 * Model for using with [ControlAdapter].
28 *
29 * Implementations of this interface provide different views of the controls to show.
30 */
31interface ControlsModel {
32
33 /**
Fabian Kozynski8765d352020-04-06 21:16:02 -040034 * List of favorites in order.
Fabian Kozynski1e3178d2020-02-19 09:32:27 -050035 *
36 * This should be obtained prior to storing the favorites using
37 * [ControlsController.replaceFavoritesForComponent].
38 */
Fabian Kozynski8765d352020-04-06 21:16:02 -040039 val favorites: List<ControlInfo>
Fabian Kozynski1e3178d2020-02-19 09:32:27 -050040
41 /**
42 * List of all the elements to display by the corresponding [RecyclerView].
43 */
44 val elements: List<ElementWrapper>
45
Fabian Kozynski93a69752020-05-14 09:06:14 -040046 val moveHelper: MoveHelper?
47
Fabian Kozynski1e3178d2020-02-19 09:32:27 -050048 /**
49 * Change the favorite status of a particular control.
50 */
51 fun changeFavoriteStatus(controlId: String, favorite: Boolean) {}
52
53 /**
54 * Move an item (in elements) from one position to another.
55 */
56 fun onMoveItem(from: Int, to: Int) {}
Fabian Kozynski8765d352020-04-06 21:16:02 -040057
58 /**
59 * Attach an adapter to the model.
60 *
61 * This can be used to notify the adapter of changes in the model.
62 */
63 fun attachAdapter(adapter: RecyclerView.Adapter<*>) {}
64
65 /**
66 * Callback to notify elements (other than the adapter) of relevant changes in the model.
67 */
68 interface ControlsModelCallback {
69
70 /**
71 * Use to notify that the model has changed for the first time
72 */
73 fun onFirstChange()
74 }
Fabian Kozynski93a69752020-05-14 09:06:14 -040075
76 /**
77 * Interface to facilitate moving controls from an [AccessibilityDelegate].
78 *
79 * All positions should be 0 based.
80 */
81 interface MoveHelper {
82
83 /**
84 * Whether the control in `position` can be moved to the position before it.
85 */
86 fun canMoveBefore(position: Int): Boolean
87
88 /**
89 * Whether the control in `position` can be moved to the position after it.
90 */
91 fun canMoveAfter(position: Int): Boolean
92
93 /**
94 * Move the control in `position` to the position before it.
95 */
96 fun moveBefore(position: Int)
97
98 /**
99 * Move the control in `position` to the position after it.
100 */
101 fun moveAfter(position: Int)
102 }
Fabian Kozynski1e3178d2020-02-19 09:32:27 -0500103}
104
105/**
106 * Wrapper classes for the different types of elements shown in the [RecyclerView]s in
107 * [ControlAdapter].
108 */
109sealed class ElementWrapper
Fabian Kozynski8765d352020-04-06 21:16:02 -0400110
Fabian Kozynski1e3178d2020-02-19 09:32:27 -0500111data class ZoneNameWrapper(val zoneName: CharSequence) : ElementWrapper()
Fabian Kozynski8765d352020-04-06 21:16:02 -0400112
113data class ControlStatusWrapper(
114 val controlStatus: ControlStatus
115) : ElementWrapper(), ControlInterface by controlStatus
116
117data class ControlInfoWrapper(
118 override val component: ComponentName,
119 val controlInfo: ControlInfo,
120 override var favorite: Boolean
121) : ElementWrapper(), ControlInterface {
122 override val controlId: String
123 get() = controlInfo.controlId
124 override val title: CharSequence
125 get() = controlInfo.controlTitle
126 override val subtitle: CharSequence
127 get() = controlInfo.controlSubtitle
128 override val deviceType: Int
129 get() = controlInfo.deviceType
Matt Pietala2e20852020-06-22 09:36:48 -0400130 override val customIcon: Icon?
131 // Will need to address to support for edit activity
132 get() = null
Fabian Kozynski8765d352020-04-06 21:16:02 -0400133}
134
135data class DividerWrapper(
136 var showNone: Boolean = false,
137 var showDivider: Boolean = false
Matt Pietala2e20852020-06-22 09:36:48 -0400138) : ElementWrapper()