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.car.carlaunchercommon.shortcuts
18 
19 import android.content.res.Resources
20 import com.android.car.carlaunchercommon.R
21 import com.android.car.ui.shortcutspopup.CarUiShortcutsPopup
22 
23 /**
24  * {@link CarUiShortcutsPopup.ShortcutItem} to pin or unpin an app to the dock.
25  * @param isItemPinned if the app is pinned to the dock
26  * @param pinItemClickDelegate {@link Runnable} to pin the app to the dock
27  * @param unpinItemClickDelegate {@link Runnable} to unpin the app to the dock
28  */
29 class PinShortcutItem(
30     private val resources: Resources,
31     private val isItemPinned: Boolean,
32     private val pinItemClickDelegate: Runnable,
33     private val unpinItemClickDelegate: Runnable
34 ) : CarUiShortcutsPopup.ShortcutItem {
35 
datanull36     override fun data(): CarUiShortcutsPopup.ItemData {
37         return if (isItemPinned) {
38             CarUiShortcutsPopup.ItemData(
39                 R.drawable.ic_dock_unpin, // leftDrawable
40                 resources.getString(R.string.dock_unpin_shortcut_label) // shortcutName
41             )
42         } else {
43             CarUiShortcutsPopup.ItemData(
44                 R.drawable.ic_dock_pin, // leftDrawable
45                 resources.getString(R.string.dock_pin_shortcut_label) // shortcutName
46             )
47         }
48     }
49 
onClicknull50     override fun onClick(): Boolean {
51         // todo(b/314835197): fix pinning/opening media apps
52         if (isItemPinned) {
53             unpinItemClickDelegate.run()
54         } else {
55             pinItemClickDelegate.run()
56         }
57         return true
58     }
59 
isEnablednull60     override fun isEnabled(): Boolean {
61         return true
62     }
63 }
64