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.systemui.keyboard.shortcut.shared.model 18 19 sealed interface ShortcutCategoryType { 20 val isTrusted: Boolean 21 val includeInCustomization: Boolean 22 23 data object System : ShortcutCategoryType { 24 override val isTrusted: Boolean = true 25 override val includeInCustomization: Boolean = true 26 } 27 28 data object MultiTasking : ShortcutCategoryType { 29 override val isTrusted: Boolean = true 30 override val includeInCustomization: Boolean = true 31 } 32 33 data object InputMethodEditor : ShortcutCategoryType { 34 override val isTrusted: Boolean = false 35 override val includeInCustomization: Boolean = false 36 } 37 38 data object AppCategories : ShortcutCategoryType { 39 override val isTrusted: Boolean = true 40 override val includeInCustomization: Boolean = true 41 } 42 43 data object Accessibility : ShortcutCategoryType { 44 override val isTrusted: Boolean = false 45 override val includeInCustomization: Boolean = true 46 } 47 48 data class CurrentApp(val packageName: String) : ShortcutCategoryType { 49 override val isTrusted: Boolean = false 50 override val includeInCustomization: Boolean = false 51 } 52 } 53 54 data class ShortcutCategory( 55 val type: ShortcutCategoryType, 56 val subCategories: List<ShortcutSubCategory>, 57 ) { 58 constructor( 59 type: ShortcutCategoryType, 60 vararg subCategories: ShortcutSubCategory, 61 ) : this(type, subCategories.asList()) 62 } 63 64 class ShortcutCategoryBuilder(val type: ShortcutCategoryType) { 65 private val subCategories = mutableListOf<ShortcutSubCategory>() 66 subCategorynull67 fun subCategory(label: String, builder: ShortcutSubCategoryBuilder.() -> Unit) { 68 subCategories += ShortcutSubCategoryBuilder(label).apply(builder).build() 69 } 70 buildnull71 fun build() = ShortcutCategory(type, subCategories) 72 } 73 74 fun shortcutCategory(type: ShortcutCategoryType, block: ShortcutCategoryBuilder.() -> Unit) = 75 ShortcutCategoryBuilder(type).apply(block).build() 76