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.keyguard.data.quickaffordance
18 
19 import com.android.systemui.Flags
20 import com.android.systemui.animation.Expandable
21 import com.android.systemui.common.shared.model.ContentDescription
22 import com.android.systemui.common.shared.model.Icon
23 import com.android.systemui.communal.data.repository.CommunalSceneRepository
24 import com.android.systemui.communal.shared.model.CommunalScenes
25 import com.android.systemui.dagger.SysUISingleton
26 import com.android.systemui.res.R
27 import javax.inject.Inject
28 import kotlinx.coroutines.flow.Flow
29 import kotlinx.coroutines.flow.flowOf
30 
31 /** Shortcut that opens the glanceable hub. */
32 // TODO(b/339667383): delete or properly implement this once a product decision is made
33 @SysUISingleton
34 class GlanceableHubQuickAffordanceConfig
35 @Inject
36 constructor(
37     private val communalRepository: CommunalSceneRepository,
38 ) : KeyguardQuickAffordanceConfig {
39 
40     override val key: String = BuiltInKeyguardQuickAffordanceKeys.GLANCEABLE_HUB
41 
pickerNamenull42     override fun pickerName(): String = "Glanceable hub"
43 
44     override val pickerIconResourceId = R.drawable.ic_widgets
45 
46     override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> by lazy {
47         if (Flags.glanceableHubShortcutButton()) {
48             val contentDescription = ContentDescription.Loaded(pickerName())
49             val icon = Icon.Resource(pickerIconResourceId, contentDescription)
50             flowOf(KeyguardQuickAffordanceConfig.LockScreenState.Visible(icon))
51         } else {
52             flowOf(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
53         }
54     }
55 
getPickerScreenStatenull56     override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
57         return KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
58     }
59 
onTriggerednull60     override fun onTriggered(
61         expandable: Expandable?
62     ): KeyguardQuickAffordanceConfig.OnTriggeredResult {
63         communalRepository.changeScene(CommunalScenes.Communal, null)
64         return KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
65     }
66 }
67