• 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.touchpad.tutorial.ui.viewmodel
18 
19 import androidx.lifecycle.ViewModel
20 import androidx.lifecycle.ViewModelProvider
21 import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
22 import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext
23 import com.android.systemui.touchpad.tutorial.domain.interactor.TouchpadGesturesInteractor
24 import javax.inject.Inject
25 import kotlinx.coroutines.flow.MutableStateFlow
26 import kotlinx.coroutines.flow.StateFlow
27 
28 class TouchpadTutorialViewModel(
29     private val gesturesInteractor: TouchpadGesturesInteractor,
30     private val logger: InputDeviceTutorialLogger,
31 ) : ViewModel() {
32 
33     private val _screen = MutableStateFlow(Screen.TUTORIAL_SELECTION)
34     val screen: StateFlow<Screen> = _screen
35 
goTonull36     fun goTo(screen: Screen) {
37         logger.logGoingToScreen(screen, TutorialContext.TOUCHPAD_TUTORIAL)
38         _screen.value = screen
39     }
40 
onOpenednull41     fun onOpened() {
42         gesturesInteractor.disableGestures()
43     }
44 
onClosednull45     fun onClosed() {
46         gesturesInteractor.enableGestures()
47     }
48 
49     class Factory
50     @Inject
51     constructor(
52         private val gesturesInteractor: TouchpadGesturesInteractor,
53         private val logger: InputDeviceTutorialLogger,
54     ) : ViewModelProvider.Factory {
55 
56         @Suppress("UNCHECKED_CAST")
createnull57         override fun <T : ViewModel> create(modelClass: Class<T>): T {
58             return TouchpadTutorialViewModel(gesturesInteractor, logger) as T
59         }
60     }
61 }
62 
63 enum class Screen {
64     TUTORIAL_SELECTION,
65     BACK_GESTURE,
66     HOME_GESTURE,
67     RECENT_APPS_GESTURE,
68     SWITCH_APPS_GESTURE,
69 }
70