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

Commit 449d9b5a authored by Mady Mellor's avatar Mady Mellor
Browse files

If the app bubble is in the overflow, use that instead of recreating

Previously we didn't show app bubbles in the overflow, ag/25579902
changed that but didn't update the showOrHideAppBubble code path
to account for the app bubble being in the overflow.

This CL modifies the code to check for an app bubble in the overflow
and remove it & add it back to the stack.

Flag: none
Test: atest BubblesTest BubbleDataTest
Test: manual - add an app bubble, add a chat bubble, dismiss app
               bubble, check the overflow to see the app bubble,
               then trigger the app bubble again, check the overflow
               to verify the app bubble isn't there
Bug: 314124017
Change-Id: Ie801e8e86178d471ee56f4095f60660917ca1944
parent 9b26927b
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -1272,10 +1272,18 @@ public class BubbleController implements ConfigurationChangeListener,
                mBubbleData.setSelectedBubble(existingAppBubble);
                mBubbleData.setExpanded(true);
            }
        } else {
            // Check if it exists in the overflow
            Bubble b = mBubbleData.getOverflowBubbleWithKey(appBubbleKey);
            if (b != null) {
                // It's in the overflow, so remove it & reinflate
                Log.i(TAG, "  showOrHideAppBubble, expanding app bubble from overflow");
                mBubbleData.removeOverflowBubble(b);
            } else {
                // App bubble does not exist, lets add and expand it
                Log.i(TAG, "  showOrHideAppBubble, creating and expanding app bubble");
            Bubble b = Bubble.createAppBubble(intent, user, icon, mMainExecutor);
                b = Bubble.createAppBubble(intent, user, icon, mMainExecutor);
            }
            b.setShouldAutoExpand(true);
            inflateAndAdd(b, /* suppressFlyout= */ true, /* showInShade= */ false);
        }
+13 −1
Original line number Diff line number Diff line
@@ -490,6 +490,19 @@ public class BubbleData {
        dispatchPendingChanges();
    }

    /**
     * Explicitly removes a bubble from the overflow, if it exists.
     *
     * @param bubble the bubble to remove.
     */
    public void removeOverflowBubble(Bubble bubble) {
        if (bubble == null) return;
        if (mOverflowBubbles.remove(bubble)) {
            mStateChange.removedOverflowBubble = bubble;
            dispatchPendingChanges();
        }
    }

    /**
     * Adds a group key indicating that the summary for this group should be suppressed.
     *
@@ -1145,7 +1158,6 @@ public class BubbleData {
        return null;
    }

    @VisibleForTesting(visibility = PRIVATE)
    public Bubble getOverflowBubbleWithKey(String key) {
        for (int i = 0; i < mOverflowBubbles.size(); i++) {
            Bubble bubble = mOverflowBubbles.get(i);
+17 −0
Original line number Diff line number Diff line
@@ -1190,6 +1190,23 @@ public class BubbleDataTest extends ShellTestCase {
        assertThat(mBubbleData.getBubbleInStackWithKey(appBubbleKey)).isNull();
    }

    @Test
    public void test_removeOverflowBubble() {
        sendUpdatedEntryAtTime(mEntryA1, 2000);
        mBubbleData.setListener(mListener);

        mBubbleData.dismissBubbleWithKey(mEntryA1.getKey(), Bubbles.DISMISS_USER_GESTURE);
        verifyUpdateReceived();
        assertOverflowChangedTo(ImmutableList.of(mBubbleA1));

        mBubbleData.removeOverflowBubble(mBubbleA1);
        verifyUpdateReceived();

        BubbleData.Update update = mUpdateCaptor.getValue();
        assertThat(update.removedOverflowBubble).isEqualTo(mBubbleA1);
        assertOverflowChangedTo(ImmutableList.of());
    }

    private void verifyUpdateReceived() {
        verify(mListener).applyUpdate(mUpdateCaptor.capture());
        reset(mListener);
+20 −0
Original line number Diff line number Diff line
@@ -2097,6 +2097,26 @@ public class BubblesTest extends SysuiTestCase {
        assertThat(mBubbleData.getBubbles().size()).isEqualTo(2);
    }

    @Test
    public void testShowOrHideAppBubble_addsFromOverflow() {
        String appBubbleKey = Bubble.getAppBubbleKeyForApp(mAppBubbleIntent.getPackage(), mUser0);
        mBubbleController.showOrHideAppBubble(mAppBubbleIntent, mUser0, mAppBubbleIcon);

        // Collapse the stack so we don't need to wait for the dismiss animation in the test
        mBubbleController.collapseStack();

        // Dismiss the app bubble so it's in the overflow
        mBubbleController.dismissBubble(appBubbleKey, Bubbles.DISMISS_USER_GESTURE);
        assertThat(mBubbleData.getOverflowBubbleWithKey(appBubbleKey)).isNotNull();

        // Calling this while collapsed will re-add and expand the app bubble
        mBubbleController.showOrHideAppBubble(mAppBubbleIntent, mUser0, mAppBubbleIcon);
        assertThat(mBubbleData.getSelectedBubble().getKey()).isEqualTo(appBubbleKey);
        assertThat(mBubbleController.isStackExpanded()).isTrue();
        assertThat(mBubbleData.getBubbles().size()).isEqualTo(1);
        assertThat(mBubbleData.getOverflowBubbleWithKey(appBubbleKey)).isNull();
    }

    @Test
    public void testCreateBubbleFromOngoingNotification() {
        NotificationEntry notif = new NotificationEntryBuilder()