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.composable
18
19 import androidx.compose.runtime.Composable
20 import androidx.compose.runtime.remember
21 import com.airbnb.lottie.compose.rememberLottieDynamicProperties
22 import com.android.compose.theme.LocalAndroidColorScheme
23 import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialScreenConfig
24 import com.android.systemui.inputdevice.tutorial.ui.composable.rememberColorFilterProperty
25 import com.android.systemui.res.R
26 import com.android.systemui.touchpad.tutorial.ui.viewmodel.EasterEggGestureViewModel
27 import com.android.systemui.touchpad.tutorial.ui.viewmodel.HomeGestureScreenViewModel
28
29 @Composable
HomeGestureTutorialScreennull30 fun HomeGestureTutorialScreen(
31 viewModel: HomeGestureScreenViewModel,
32 easterEggGestureViewModel: EasterEggGestureViewModel,
33 onDoneButtonClicked: () -> Unit,
34 onBack: () -> Unit,
35 onAutoProceed: (suspend () -> Unit)? = null,
36 ) {
37 val screenConfig =
38 TutorialScreenConfig(
39 colors = rememberScreenColors(),
40 strings =
41 TutorialScreenConfig.Strings(
42 titleResId = R.string.touchpad_home_gesture_action_title,
43 bodyResId = R.string.touchpad_home_gesture_guidance,
44 titleSuccessResId = R.string.touchpad_home_gesture_success_title,
45 bodySuccessResId = R.string.touchpad_home_gesture_success_body,
46 titleErrorResId = R.string.gesture_error_title,
47 bodyErrorResId = R.string.touchpad_home_gesture_error_body,
48 ),
49 animations = TutorialScreenConfig.Animations(educationResId = R.raw.trackpad_home_edu),
50 )
51 GestureTutorialScreen(
52 screenConfig = screenConfig,
53 tutorialStateFlow = viewModel.tutorialState,
54 motionEventConsumer = {
55 easterEggGestureViewModel.accept(it)
56 viewModel.handleEvent(it)
57 },
58 easterEggTriggeredFlow = easterEggGestureViewModel.easterEggTriggered,
59 onEasterEggFinished = easterEggGestureViewModel::onEasterEggFinished,
60 onDoneButtonClicked = onDoneButtonClicked,
61 onBack = onBack,
62 onAutoProceed = onAutoProceed,
63 )
64 }
65
66 @Composable
rememberScreenColorsnull67 private fun rememberScreenColors(): TutorialScreenConfig.Colors {
68 val primaryFixedDim = LocalAndroidColorScheme.current.primaryFixedDim
69 val onPrimaryFixed = LocalAndroidColorScheme.current.onPrimaryFixed
70 val onPrimaryFixedVariant = LocalAndroidColorScheme.current.onPrimaryFixedVariant
71 val dynamicProperties =
72 rememberLottieDynamicProperties(
73 rememberColorFilterProperty(".primaryFixedDim", primaryFixedDim),
74 rememberColorFilterProperty(".onPrimaryFixed", onPrimaryFixed),
75 rememberColorFilterProperty(".onPrimaryFixedVariant", onPrimaryFixedVariant),
76 )
77 val screenColors =
78 remember(dynamicProperties) {
79 TutorialScreenConfig.Colors(
80 background = onPrimaryFixed,
81 title = primaryFixedDim,
82 animationColors = dynamicProperties,
83 )
84 }
85 return screenColors
86 }
87