Merge "Using success animation from state instead of configuration" into main
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
index 4142be3..058e587 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
@@ -52,7 +52,7 @@
             Modifier.fillMaxSize()
                 .onKeyEvent { keyEvent: KeyEvent ->
                     if (keyEvent.key == Key.MetaLeft && keyEvent.type == KeyEventType.KeyUp) {
-                        actionState = Finished
+                        actionState = Finished(R.raw.action_key_success)
                     }
                     true
                 }
@@ -80,11 +80,7 @@
                 titleSuccessResId = R.string.tutorial_action_key_success_title,
                 bodySuccessResId = R.string.tutorial_action_key_success_body,
             ),
-        animations =
-            TutorialScreenConfig.Animations(
-                educationResId = R.raw.action_key_edu,
-                successResId = R.raw.action_key_success,
-            ),
+        animations = TutorialScreenConfig.Animations(educationResId = R.raw.action_key_edu),
     )
 
 @Composable
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionTutorialContent.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionTutorialContent.kt
index 8e01e37..3d2baee 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionTutorialContent.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionTutorialContent.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui.inputdevice.tutorial.ui.composable
 
+import androidx.annotation.RawRes
 import androidx.annotation.StringRes
 import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.animation.fadeIn
@@ -48,7 +49,7 @@
         val endMarker: String? = null,
     ) : TutorialActionState
 
-    data object Finished : TutorialActionState
+    data class Finished(@RawRes val successAnimation: Int) : TutorialActionState
 }
 
 @Composable
@@ -68,11 +69,11 @@
         Row(modifier = Modifier.fillMaxWidth().weight(1f)) {
             TutorialDescription(
                 titleTextId =
-                    if (actionState == Finished) config.strings.titleSuccessResId
+                    if (actionState is Finished) config.strings.titleSuccessResId
                     else config.strings.titleResId,
                 titleColor = config.colors.title,
                 bodyTextId =
-                    if (actionState == Finished) config.strings.bodySuccessResId
+                    if (actionState is Finished) config.strings.bodySuccessResId
                     else config.strings.bodyResId,
                 modifier = Modifier.weight(1f),
             )
@@ -83,7 +84,7 @@
                 modifier = Modifier.weight(1f).padding(top = 8.dp),
             )
         }
-        AnimatedVisibility(visible = actionState == Finished, enter = fadeIn()) {
+        AnimatedVisibility(visible = actionState is Finished, enter = fadeIn()) {
             DoneButton(onDoneButtonClicked = onDoneButtonClicked)
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialAnimation.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialAnimation.kt
index ef375a8..720c01f 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialAnimation.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialAnimation.kt
@@ -77,7 +77,9 @@
                         config.colors.animationColors,
                     )
                 Finished::class ->
-                    SuccessAnimation(config.animations.successResId, config.colors.animationColors)
+                    // Below cast is safe as Finished state is the last state and afterwards we can
+                    // only leave the screen so this composable would be no longer displayed
+                    SuccessAnimation(actionState as Finished, config.colors.animationColors)
             }
         }
     }
@@ -100,10 +102,11 @@
 
 @Composable
 private fun SuccessAnimation(
-    @RawRes successAnimationId: Int,
+    finishedState: Finished,
     animationProperties: LottieDynamicProperties,
 ) {
-    val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(successAnimationId))
+    val composition by
+        rememberLottieComposition(LottieCompositionSpec.RawRes(finishedState.successAnimation))
     val progress by animateLottieCompositionAsState(composition, iterations = 1)
     LottieAnimation(
         composition = composition,
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialScreenConfig.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialScreenConfig.kt
index 55e5f2d..60dfed3 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialScreenConfig.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/TutorialScreenConfig.kt
@@ -24,13 +24,13 @@
 data class TutorialScreenConfig(
     val colors: Colors,
     val strings: Strings,
-    val animations: Animations
+    val animations: Animations,
 ) {
 
     data class Colors(
         val background: Color,
         val title: Color,
-        val animationColors: LottieDynamicProperties
+        val animationColors: LottieDynamicProperties,
     )
 
     data class Strings(
@@ -40,8 +40,5 @@
         @StringRes val bodySuccessResId: Int,
     )
 
-    data class Animations(
-        @RawRes val educationResId: Int,
-        @RawRes val successResId: Int,
-    )
+    data class Animations(@RawRes val educationResId: Int)
 }
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
index 618722a..2337ec1 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
@@ -44,11 +44,7 @@
                     titleSuccessResId = R.string.touchpad_back_gesture_success_title,
                     bodySuccessResId = R.string.touchpad_back_gesture_success_body,
                 ),
-            animations =
-                TutorialScreenConfig.Animations(
-                    educationResId = R.raw.trackpad_back_edu,
-                    successResId = R.raw.trackpad_back_success,
-                ),
+            animations = TutorialScreenConfig.Animations(educationResId = R.raw.trackpad_back_edu),
         )
     val recognizer = rememberBackGestureRecognizer(LocalContext.current.resources)
     val gestureUiState: Flow<GestureUiState> =
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/GestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/GestureTutorialScreen.kt
index 11e1ff4..e058527 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/GestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/GestureTutorialScreen.kt
@@ -74,7 +74,7 @@
         NotStarted -> TutorialActionState.NotStarted
         // progress is disabled for now as views are not ready to handle varying progress
         is GestureUiState.InProgress -> TutorialActionState.InProgress(progress = 0f)
-        is Finished -> TutorialActionState.Finished
+        is Finished -> TutorialActionState.Finished(successAnimation)
     }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
index 05871ce..55749b2 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
@@ -43,11 +43,7 @@
                     titleSuccessResId = R.string.touchpad_home_gesture_success_title,
                     bodySuccessResId = R.string.touchpad_home_gesture_success_body,
                 ),
-            animations =
-                TutorialScreenConfig.Animations(
-                    educationResId = R.raw.trackpad_home_edu,
-                    successResId = R.raw.trackpad_home_success,
-                ),
+            animations = TutorialScreenConfig.Animations(educationResId = R.raw.trackpad_home_edu),
         )
     val recognizer = rememberHomeGestureRecognizer(LocalContext.current.resources)
     val gestureUiState: Flow<GestureUiState> =
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/RecentAppsGestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/RecentAppsGestureTutorialScreen.kt
index 4fd1644..d928535 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/RecentAppsGestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/RecentAppsGestureTutorialScreen.kt
@@ -44,10 +44,7 @@
                     bodySuccessResId = R.string.touchpad_recent_apps_gesture_success_body,
                 ),
             animations =
-                TutorialScreenConfig.Animations(
-                    educationResId = R.raw.trackpad_recent_apps_edu,
-                    successResId = R.raw.trackpad_recent_apps_success,
-                ),
+                TutorialScreenConfig.Animations(educationResId = R.raw.trackpad_recent_apps_edu),
         )
     val recognizer = rememberRecentAppsGestureRecognizer(LocalContext.current.resources)
     val gestureUiState: Flow<GestureUiState> =