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

Commit 3552a9e7 authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge "If the app bubble is in the overflow, use that instead of recreating" into main

parents ea76da3a 449d9b5a
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -1275,10 +1275,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()