• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 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 
18 package com.android.systemui.keyguard.ui.viewmodel
19 
20 import com.android.systemui.R
21 import com.android.systemui.common.shared.model.Icon
22 import com.android.systemui.common.shared.model.Text
23 import com.android.systemui.keyguard.domain.interactor.KeyguardLongPressInteractor
24 import javax.inject.Inject
25 import kotlinx.coroutines.flow.Flow
26 import kotlinx.coroutines.flow.map
27 
28 /** Models UI state to support the lock screen long-press feature. */
29 class KeyguardLongPressViewModel
30 @Inject
31 constructor(
32     private val interactor: KeyguardLongPressInteractor,
33 ) {
34 
35     /** Whether the long-press handling feature should be enabled. */
36     val isLongPressHandlingEnabled: Flow<Boolean> = interactor.isLongPressHandlingEnabled
37 
38     /** View-model for a menu that should be shown; `null` when no menu should be shown. */
39     val menu: Flow<KeyguardSettingsPopupMenuViewModel?> =
40         interactor.menu.map { model ->
41             model?.let {
42                 KeyguardSettingsPopupMenuViewModel(
43                     icon =
44                         Icon.Resource(
45                             res = R.drawable.ic_settings,
46                             contentDescription = null,
47                         ),
48                     text =
49                         Text.Resource(
50                             res = R.string.lock_screen_settings,
51                         ),
52                     position = model.position,
53                     onClicked = model.onClicked,
54                     onDismissed = model.onDismissed,
55                 )
56             }
57         }
58 
59     /** Notifies that the user has long-pressed on the lock screen. */
60     fun onLongPress(
61         x: Int,
62         y: Int,
63     ) {
64         interactor.onLongPress(
65             x = x,
66             y = y,
67         )
68     }
69 }
70