Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44318ebe authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Fix issue with dragging bubbles in fullscreen.

This ensures that we only animate the stack temporarily invisible if we're not dragging something or a flyout is still showing.

This also adds a 2s delay before hiding the stack if it was visible due to drag/flyout, since a) it looks better b) that way you can open the stack back up if you didn't mean to let go.

Fixes: 159064066
Test: open fullscreen youtube, show status bar, drag around until status bar goes away, then fling bubbles somewhere and observe
Test: get a flyout while in fullscreen, touch the flyout until the status bar goes away, then collapse flyout
Change-Id: I06bc148161a1d51ee047b3861c1d01e7685c2943
parent 11e6ef94
Loading
Loading
Loading
Loading
+52 −7
Original line number Diff line number Diff line
@@ -145,6 +145,12 @@ public class BubbleStackView extends FrameLayout
    @VisibleForTesting
    static final int FLYOUT_HIDE_AFTER = 5000;

    /**
     * How long to wait to animate the stack temporarily invisible after a drag/flyout hide
     * animation ends, if we are in fact temporarily invisible.
     */
    private static final int ANIMATE_TEMPORARILY_INVISIBLE_DELAY = 1000;

    private static final PhysicsAnimator.SpringConfig FLYOUT_IME_ANIMATION_SPRING_CONFIG =
            new PhysicsAnimator.SpringConfig(
                    StackAnimationController.IME_ANIMATION_STIFFNESS,
@@ -281,6 +287,9 @@ public class BubbleStackView extends FrameLayout
    /** Whether or not the stack is temporarily invisible off the side of the screen. */
    private boolean mTemporarilyInvisible = false;

    /** Whether we're in the middle of dragging the stack around by touch. */
    private boolean mIsDraggingStack = false;

    /** Description of current animation controller state. */
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Stack view state:");
@@ -478,6 +487,8 @@ public class BubbleStackView extends FrameLayout
    private OnClickListener mBubbleClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            mIsDraggingStack = false; // If the touch ended in a click, we're no longer dragging.

            // Bubble clicks either trigger expansion/collapse or a bubble switch, both of which we
            // shouldn't interrupt. These are quick transitions, so it's not worth trying to adjust
            // the animations inflight.
@@ -563,6 +574,12 @@ public class BubbleStackView extends FrameLayout
                // Also, save the magnetized stack so we can dispatch touch events to it.
                mMagnetizedObject = mStackAnimationController.getMagnetizedStack(mMagneticTarget);
                mMagnetizedObject.setMagnetListener(mStackMagnetListener);

                mIsDraggingStack = true;

                // Cancel animations to make the stack temporarily invisible, since we're now
                // dragging it.
                updateTemporarilyInvisibleAnimation(false /* hideImmediately */);
            }

            passEventToMagnetizedObject(ev);
@@ -624,6 +641,11 @@ public class BubbleStackView extends FrameLayout

                hideDismissTarget();
            }

            mIsDraggingStack = false;

            // Hide the stack after a delay, if needed.
            updateTemporarilyInvisibleAnimation(false /* hideImmediately */);
        }
    };

@@ -967,14 +989,35 @@ public class BubbleStackView extends FrameLayout
     */
    public void setTemporarilyInvisible(boolean invisible) {
        mTemporarilyInvisible = invisible;
        animateTemporarilyInvisible();

        // If we are animating out, hide immediately if possible so we animate out with the status
        // bar.
        updateTemporarilyInvisibleAnimation(invisible /* hideImmediately */);
    }

    /**
     * Animates onto or off the screen depending on whether we're temporarily invisible, and whether
     * a flyout is visible.
     * Animates the stack to be temporarily invisible, if needed.
     *
     * If we're currently dragging the stack, or a flyout is visible, the stack will remain visible.
     * regardless of the value of {@link #mTemporarilyInvisible}. This method is called on ACTION_UP
     * as well as whenever a flyout hides, so we will animate invisible at that point if needed.
     */
    private void animateTemporarilyInvisible() {
    private void updateTemporarilyInvisibleAnimation(boolean hideImmediately) {
        removeCallbacks(mAnimateTemporarilyInvisibleImmediate);

        if (mIsDraggingStack) {
            // If we're dragging the stack, don't animate it invisible.
            return;
        }

        final boolean shouldHide =
                mTemporarilyInvisible && mFlyout.getVisibility() != View.VISIBLE;

        postDelayed(mAnimateTemporarilyInvisibleImmediate,
                shouldHide && !hideImmediately ? ANIMATE_TEMPORARILY_INVISIBLE_DELAY : 0);
    }

    private final Runnable mAnimateTemporarilyInvisibleImmediate = () -> {
        if (mTemporarilyInvisible && mFlyout.getVisibility() != View.VISIBLE) {
            if (mStackAnimationController.isStackOnLeftSide()) {
                animate().translationX(-mBubbleSize).start();
@@ -984,7 +1027,7 @@ public class BubbleStackView extends FrameLayout
        } else {
            animate().translationX(0).start();
        }
    }
    };

    private void setUpManageMenu() {
        if (mManageMenu != null) {
@@ -2303,7 +2346,9 @@ public class BubbleStackView extends FrameLayout
                    BadgedImageView.SuppressionFlag.FLYOUT_VISIBLE);

            mFlyout.setVisibility(INVISIBLE);
            animateTemporarilyInvisible();

            // Hide the stack after a delay, if needed.
            updateTemporarilyInvisibleAnimation(false /* hideImmediately */);
        };
        mFlyout.setVisibility(INVISIBLE);

@@ -2321,7 +2366,7 @@ public class BubbleStackView extends FrameLayout
            final Runnable expandFlyoutAfterDelay = () -> {
                mAnimateInFlyout = () -> {
                    mFlyout.setVisibility(VISIBLE);
                    animateTemporarilyInvisible();
                    updateTemporarilyInvisibleAnimation(false /* hideImmediately */);
                    mFlyoutDragDeltaX =
                            mStackAnimationController.isStackOnLeftSide()
                                    ? -mFlyout.getWidth()