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.domain.interactor
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.dagger.qualifiers.Background
21 import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperRepository
22 import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
23 import com.android.systemui.model.SysUiState
24 import com.android.systemui.settings.DisplayTracker
25 import com.android.systemui.shared.system.QuickStepContract
26 import javax.inject.Inject
27 import kotlinx.coroutines.CoroutineScope
28 import kotlinx.coroutines.flow.Flow
29 import kotlinx.coroutines.launch
30 
31 @SysUISingleton
32 class ShortcutHelperInteractor
33 @Inject
34 constructor(
35     private val displayTracker: DisplayTracker,
36     @Background private val backgroundScope: CoroutineScope,
37     private val sysUiState: SysUiState,
38     private val repository: ShortcutHelperRepository
39 ) {
40 
41     val state: Flow<ShortcutHelperState> = repository.state
42 
onViewClosednull43     fun onViewClosed() {
44         repository.hide()
45         setSysUiStateFlagEnabled(false)
46     }
47 
onViewOpenednull48     fun onViewOpened() {
49         setSysUiStateFlagEnabled(true)
50     }
51 
setSysUiStateFlagEnablednull52     private fun setSysUiStateFlagEnabled(enabled: Boolean) {
53         backgroundScope.launch {
54             sysUiState
55                 .setFlag(QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING, enabled)
56                 .commitUpdate(displayTracker.defaultDisplayId)
57         }
58     }
59 }
60