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

Commit 9ec3796a authored by Mady Mellor's avatar Mady Mellor
Browse files

BubbleData: Add notion of "pending bubbles" while the contents are being loaded

Previously the code allowed multiple instances of the same bubble to be
created if getOrCreateBubble was called quickly in succession.

This maintains a list of pending bubbles so that we're not making duplicates.

Test: manual - have music of some kind playing / music notif
             - via bubble experiment, make it into a bubble
             - get another bubble, expand / collapse / expand stack
             => Notice that there is only 1 music bubble, not many
             - dismiss the stack, get another bubble, expand the stack
             => Notice that the previous music bubble is not hanging around
             => Notice that the bubbles are dismissed / don't stick around
                the dismiss target area
Fixes: 147465006
Fixes: 147448416
Change-Id: Ib791e838daa5f314e3ae180ccc633a658ddb4956
parent 0258f9f2
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -111,7 +111,10 @@ public class BubbleData {
    }

    private final Context mContext;
    /** Bubbles that are actively in the stack. */
    private final List<Bubble> mBubbles;
    /** Bubbles that are being loaded but haven't been added to the stack just yet. */
    private final List<Bubble> mPendingBubbles;
    private Bubble mSelectedBubble;
    private boolean mExpanded;
    private final int mMaxBubbles;
@@ -143,6 +146,7 @@ public class BubbleData {
    public BubbleData(Context context) {
        mContext = context;
        mBubbles = new ArrayList<>();
        mPendingBubbles = new ArrayList<>();
        mStateChange = new Update(mBubbles);
        mMaxBubbles = mContext.getResources().getInteger(R.integer.bubbles_max_rendered);
    }
@@ -188,7 +192,15 @@ public class BubbleData {
    Bubble getOrCreateBubble(NotificationEntry entry) {
        Bubble bubble = getBubbleWithKey(entry.getKey());
        if (bubble == null) {
            // Check for it in pending
            for (int i = 0; i < mPendingBubbles.size(); i++) {
                Bubble b = mPendingBubbles.get(i);
                if (b.getKey().equals(entry.getKey())) {
                    return b;
                }
            }
            bubble = new Bubble(entry);
            mPendingBubbles.add(bubble);
        } else {
            bubble.setEntry(entry);
        }
@@ -204,7 +216,7 @@ public class BubbleData {
        if (DEBUG_BUBBLE_DATA) {
            Log.d(TAG, "notificationEntryUpdated: " + bubble);
        }

        mPendingBubbles.remove(bubble); // No longer pending once we're here
        Bubble prevBubble = getBubbleWithKey(bubble.getKey());
        suppressFlyout |= !shouldShowFlyout(bubble.getEntry());

@@ -377,6 +389,12 @@ public class BubbleData {
    }

    private void doRemove(String key, @DismissReason int reason) {
        //  If it was pending remove it
        for (int i = 0; i < mPendingBubbles.size(); i++) {
            if (mPendingBubbles.get(i).getKey().equals(key)) {
                mPendingBubbles.remove(mPendingBubbles.get(i));
            }
        }
        int indexToRemove = indexForKey(key);
        if (indexToRemove == -1) {
            return;