1 /*
2  * 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.settingslib.bluetooth.devicesettings.shared.model
18 
19 import android.app.PendingIntent
20 import android.content.Intent
21 import android.graphics.Bitmap
22 import androidx.annotation.DrawableRes
23 import com.android.settingslib.bluetooth.CachedBluetoothDevice
24 import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
25 
26 /** Models a device setting. */
27 sealed interface DeviceSettingModel {
28     val cachedDevice: CachedBluetoothDevice
29     @DeviceSettingId val id: Int
30 
31     /** Models a device setting which should be displayed as an action/switch preference. */
32     data class ActionSwitchPreference(
33         override val cachedDevice: CachedBluetoothDevice,
34         @DeviceSettingId override val id: Int,
35         val title: String,
36         val summary: String? = null,
37         val icon: DeviceSettingIcon? = null,
38         val action: DeviceSettingActionModel? = null,
39         val switchState: DeviceSettingStateModel.ActionSwitchPreferenceState? = null,
40         val isAllowedChangingState: Boolean = true,
41         val updateState: ((DeviceSettingStateModel.ActionSwitchPreferenceState) -> Unit)? = null,
42     ) : DeviceSettingModel
43 
44     /** Models a device setting which should be displayed as a multi-toggle preference. */
45     data class MultiTogglePreference(
46         override val cachedDevice: CachedBluetoothDevice,
47         @DeviceSettingId override val id: Int,
48         val title: String,
49         val toggles: List<ToggleModel>,
50         val isActive: Boolean,
51         val state: DeviceSettingStateModel.MultiTogglePreferenceState,
52         val isAllowedChangingState: Boolean,
53         val updateState: (DeviceSettingStateModel.MultiTogglePreferenceState) -> Unit
54     ) : DeviceSettingModel
55 
56     /** Models a footer preference. */
57     data class FooterPreference(
58         override val cachedDevice: CachedBluetoothDevice,
59         @DeviceSettingId override val id: Int,
60         val footerText: String,
61     ) : DeviceSettingModel
62 
63     /** Models a help preference displayed on the top right corner of the fragment. */
64     data class HelpPreference(
65         override val cachedDevice: CachedBluetoothDevice,
66         @DeviceSettingId override val id: Int,
67         val intent: Intent,
68     ) : DeviceSettingModel
69 
70     /** Models an unknown preference. */
71     data class Unknown(
72         override val cachedDevice: CachedBluetoothDevice,
73         @DeviceSettingId override val id: Int
74     ) : DeviceSettingModel
75 }
76 
77 /** Models a toggle in [DeviceSettingModel.MultiTogglePreference]. */
78 data class ToggleModel(val label: String, val icon: DeviceSettingIcon)
79 
80 /** Models an icon in device settings. */
81 sealed interface DeviceSettingIcon {
82 
83     data class BitmapIcon(val bitmap: Bitmap) : DeviceSettingIcon
84 
85     data class ResourceIcon(@DrawableRes val resId: Int) : DeviceSettingIcon
86 }
87 
88 /** Models an action in device settings. */
89 sealed interface DeviceSettingActionModel {
90 
91     data class IntentAction(val intent: Intent) : DeviceSettingActionModel
92 
93     data class PendingIntentAction(val pendingIntent: PendingIntent) : DeviceSettingActionModel
94 }
95