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

Commit 43340b6a authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Handle adding a bubbling during drag

When a bubble is added, we reorder bubbles which removes them from the view hierarchy and cancelling all touch events. If a bubble is added while dragging, the gesture is abruptly cancelled and the stack remains in a bad state.

This change ensures that the reordering happens at the end of the gesture.

Fixes: 317847303
Test: Manual
      - Add bubbles
      - Expand the stack and start dragging a bubble
      - While dragging trigger a new bubble notification
      - Observe that new bubble is added and dragged bubble still follows the gesture
      - Release dragged bubble either to dismiss it or to return it to the stack
Change-Id: I30072aeb506edb34a023f44728f838b5b3de184e
parent fdaf4101
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -300,6 +300,9 @@ public class BubbleStackView extends FrameLayout
     */
    private int mPointerIndexDown = -1;

    /** Indicates whether bubbles should be reordered at the end of a gesture. */
    private boolean mShouldReorderBubblesAfterGestureCompletes = false;

    @Nullable
    private BubblesNavBarGestureTracker mBubblesNavBarGestureTracker;

@@ -708,6 +711,11 @@ public class BubbleStackView extends FrameLayout

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

            if (mShouldReorderBubblesAfterGestureCompletes) {
                mShouldReorderBubblesAfterGestureCompletes = false;
                updateBubbleOrderInternal(mBubbleData.getBubbles(), true);
            }
        }
    };

@@ -1928,7 +1936,18 @@ public class BubbleStackView extends FrameLayout
    /**
     * Update bubble order and pointer position.
     */
    public void updateBubbleOrder(List<Bubble> bubbles, boolean updatePointerPositoion) {
    public void updateBubbleOrder(List<Bubble> bubbles, boolean updatePointerPosition) {
        // Don't reorder bubbles in the middle of a gesture because that would remove bubbles from
        // view hierarchy and will cancel all touch events. Instead wait until the gesture is
        // finished and then reorder.
        if (mIsGestureInProgress) {
            mShouldReorderBubblesAfterGestureCompletes = true;
            return;
        }
        updateBubbleOrderInternal(bubbles, updatePointerPosition);
    }

    private void updateBubbleOrderInternal(List<Bubble> bubbles, boolean updatePointerPosition) {
        final Runnable reorder = () -> {
            for (int i = 0; i < bubbles.size(); i++) {
                Bubble bubble = bubbles.get(i);
@@ -1939,13 +1958,13 @@ public class BubbleStackView extends FrameLayout
            reorder.run();
            updateBadges(false /* setBadgeForCollapsedStack */);
            updateZOrder();
        } else if (!isExpansionAnimating()) {
        } else {
            List<View> bubbleViews = bubbles.stream()
                    .map(b -> b.getIconView()).collect(Collectors.toList());
            mStackAnimationController.animateReorder(bubbleViews, reorder);
        }

        if (updatePointerPositoion) {
        if (updatePointerPosition) {
            updatePointerPosition(false /* forIme */);
        }
    }