Fix spring not springing when unstashing.

The spring animation was getting cancelled by the reset
animation.

Added a check to avoid creating a new reset animation if we
are already animating to the final value.

Bug: 273961611
Change-Id: I3afb62b89b5f6fbe920906499db2497ef8e94069
Flag: ENABLE_TRANSIENT_TASKBAR
Test: stash transient taskbar
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
index a6c38da..aa81bfd 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
@@ -553,12 +553,16 @@
             animatorSet.play(stashAnimator);
         }
 
-        if (isAnimatingToLauncher() || mLauncherState == LauncherState.NORMAL) {
-            // Translate back to 0 at a shorter or same duration as the icon alignment animation.
-            // This ensures there is no jump after switching to hotseat, e.g. when swiping up from
-            // overview to home. Currently we do duration / 2 just to make it feel snappier.
+        // Translate back to 0 at a shorter or same duration as the icon alignment animation.
+        // This ensures there is no jump after switching to hotseat, e.g. when swiping up from
+        // overview to home. When not in app, we do duration / 2 just to make it feel snappier.
+        long resetDuration = mControllers.taskbarStashController.isInApp()
+                ? duration
+                : duration / 2;
+        if (!mControllers.taskbarTranslationController.willAnimateToZeroBefore(resetDuration)
+                && (isAnimatingToLauncher() || mLauncherState == LauncherState.NORMAL)) {
             animatorSet.play(mControllers.taskbarTranslationController
-                    .createAnimToResetTranslation(duration / 2));
+                    .createAnimToResetTranslation(resetDuration));
         }
     }
 
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarTranslationController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarTranslationController.java
index b9b63db..065d111 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarTranslationController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarTranslationController.java
@@ -134,6 +134,21 @@
     }
 
     /**
+     * Returns true if we will animate to zero before the input duration.
+     */
+    public boolean willAnimateToZeroBefore(long duration) {
+        if (mSpringBounce != null && mSpringBounce.isRunning()) {
+            long springDuration = mSpringBounce.getDuration();
+            long current = mSpringBounce.getCurrentPlayTime();
+            return (springDuration - current < duration);
+        }
+        if (mTranslationYForSwipe.isAnimatingToValue(0)) {
+            return mTranslationYForSwipe.getRemainingTime() < duration;
+        }
+        return false;
+    }
+
+    /**
      * Returns an animation to reset the taskbar translation to {@code 0}.
      */
     public ObjectAnimator createAnimToResetTranslation(long duration) {
diff --git a/src/com/android/launcher3/anim/AnimatedFloat.java b/src/com/android/launcher3/anim/AnimatedFloat.java
index 2380af4..2f3fa63 100644
--- a/src/com/android/launcher3/anim/AnimatedFloat.java
+++ b/src/com/android/launcher3/anim/AnimatedFloat.java
@@ -133,6 +133,15 @@
     }
 
     /**
+     * Returns the remaining time of the existing animation (if any).
+     */
+    public long getRemainingTime() {
+        return isAnimating() && mValueAnimator.isRunning()
+                ? Math.max(0, mValueAnimator.getDuration() - mValueAnimator.getCurrentPlayTime())
+                : 0;
+    }
+
+    /**
      * Returns whether we are currently not animating, and the animation's value matches the given.
      */
     public boolean isSettledOnValue(float endValue) {