• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 data class Shortcut(
20     val label: String,
21     val commands: List<ShortcutCommand>,
22     val icon: ShortcutIcon? = null,
23     val contentDescription: String = "",
24     val isCustomizable: Boolean = true,
25 ) {
<lambda>null26     val containsCustomShortcutCommands: Boolean = commands.any { it.isCustom }
27 }
28 
29 class ShortcutBuilder(private val label: String) {
30     val commands = mutableListOf<ShortcutCommand>()
31     var contentDescription = ""
32     var isCustomizable = true
33 
commandnull34     fun command(builder: ShortcutCommandBuilder.() -> Unit) {
35         commands += ShortcutCommandBuilder().apply(builder).build()
36     }
37 
contentDescriptionnull38     fun contentDescription(string: () -> String) {
39         contentDescription = string.invoke()
40     }
41 
buildnull42     fun build() =
43         Shortcut(
44             label,
45             commands,
46             contentDescription = contentDescription,
47             isCustomizable = isCustomizable,
48         )
49 }
50 
51 fun shortcut(label: String, block: ShortcutBuilder.() -> Unit): Shortcut =
52     ShortcutBuilder(label).apply(block).build()
53