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.view
18
19 import android.os.Bundle
20 import androidx.activity.ComponentActivity
21 import androidx.activity.compose.setContent
22 import androidx.activity.enableEdgeToEdge
23 import androidx.compose.runtime.Composable
24 import androidx.compose.runtime.getValue
25 import androidx.lifecycle.Lifecycle.State.STARTED
26 import androidx.lifecycle.ViewModelProvider
27 import androidx.lifecycle.compose.collectAsStateWithLifecycle
28 import androidx.lifecycle.viewmodel.compose.viewModel
29 import com.android.compose.theme.PlatformTheme
30 import com.android.systemui.touchpad.tutorial.ui.BackGestureTutorialViewModel
31 import com.android.systemui.touchpad.tutorial.ui.GestureViewModelFactory
32 import com.android.systemui.touchpad.tutorial.ui.HomeGestureTutorialViewModel
33 import com.android.systemui.touchpad.tutorial.ui.Screen.BACK_GESTURE
34 import com.android.systemui.touchpad.tutorial.ui.Screen.HOME_GESTURE
35 import com.android.systemui.touchpad.tutorial.ui.Screen.TUTORIAL_SELECTION
36 import com.android.systemui.touchpad.tutorial.ui.TouchpadTutorialViewModel
37 import javax.inject.Inject
38
39 class TouchpadTutorialActivity
40 @Inject
41 constructor(
42 private val viewModelFactory: TouchpadTutorialViewModel.Factory,
43 ) : ComponentActivity() {
44
onCreatenull45 override fun onCreate(savedInstanceState: Bundle?) {
46 super.onCreate(savedInstanceState)
47 enableEdgeToEdge()
48 setContent {
49 PlatformTheme { TouchpadTutorialScreen(viewModelFactory, closeTutorial = { finish() }) }
50 }
51 }
52 }
53
54 @Composable
TouchpadTutorialScreennull55 fun TouchpadTutorialScreen(viewModelFactory: ViewModelProvider.Factory, closeTutorial: () -> Unit) {
56 val vm = viewModel<TouchpadTutorialViewModel>(factory = viewModelFactory)
57 val activeScreen by vm.screen.collectAsStateWithLifecycle(STARTED)
58 when (activeScreen) {
59 TUTORIAL_SELECTION ->
60 TutorialSelectionScreen(
61 onBackTutorialClicked = { vm.goTo(BACK_GESTURE) },
62 onHomeTutorialClicked = { vm.goTo(HOME_GESTURE) },
63 onActionKeyTutorialClicked = {},
64 onDoneButtonClicked = closeTutorial
65 )
66 BACK_GESTURE -> BackGestureTutorialScreen()
67 HOME_GESTURE -> HomeGestureTutorialScreen()
68 }
69 }
70
71 @Composable
BackGestureTutorialScreennull72 fun BackGestureTutorialScreen() {
73 val vm = viewModel<BackGestureTutorialViewModel>(factory = GestureViewModelFactory())
74 }
75
76 @Composable
HomeGestureTutorialScreennull77 fun HomeGestureTutorialScreen() {
78 val vm = viewModel<HomeGestureTutorialViewModel>(factory = GestureViewModelFactory())
79 }
80