diff options
Diffstat (limited to 'libs')
3 files changed, 24 insertions, 5 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java index 8434d668e153..6f526ecf2b62 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java @@ -575,6 +575,7 @@ public class BubbleData { Log.d(TAG, "Overflowing: " + bubble); } mLogger.logOverflowAdd(bubble, reason); + mOverflowBubbles.remove(bubble); mOverflowBubbles.add(0, bubble); mStateChange.addedOverflowBubble = bubble; bubble.stopInflation(); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java index 8ee2b40d5985..f7c7285a7b6e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java @@ -220,18 +220,25 @@ public class BubbleOverflowContainerView extends LinearLayout { Log.d(TAG, "remove: " + toRemove); } toRemove.cleanupViews(); - final int i = mOverflowBubbles.indexOf(toRemove); + final int indexToRemove = mOverflowBubbles.indexOf(toRemove); mOverflowBubbles.remove(toRemove); - mAdapter.notifyItemRemoved(i); + mAdapter.notifyItemRemoved(indexToRemove); } Bubble toAdd = update.addedOverflowBubble; if (toAdd != null) { + final int indexToAdd = mOverflowBubbles.indexOf(toAdd); if (DEBUG_OVERFLOW) { - Log.d(TAG, "add: " + toAdd); + Log.d(TAG, "add: " + toAdd + " prevIndex: " + indexToAdd); + } + if (indexToAdd > 0) { + mOverflowBubbles.remove(toAdd); + mOverflowBubbles.add(0, toAdd); + mAdapter.notifyItemMoved(indexToAdd, 0); + } else { + mOverflowBubbles.add(0, toAdd); + mAdapter.notifyItemInserted(0); } - mOverflowBubbles.add(0, toAdd); - mAdapter.notifyItemInserted(0); } updateEmptyStateVisibility(); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java index 9a80a5545984..2bb7204c7941 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java @@ -19,6 +19,8 @@ package com.android.wm.shell.bubbles; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static junit.framework.TestCase.assertEquals; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -799,6 +801,15 @@ public class BubbleDataTest extends ShellTestCase { assertExpandedChangedTo(false); } + @Test + public void test_addToOverflow_doesntAllowDupes() { + assertEquals(0, mBubbleData.getOverflowBubbles().size()); + mBubbleData.overflowBubble(Bubbles.DISMISS_AGED, mBubbleA1); + mBubbleData.overflowBubble(Bubbles.DISMISS_AGED, mBubbleA1); + mBubbleData.overflowBubble(Bubbles.DISMISS_AGED, mBubbleA1); + assertEquals(1, mBubbleData.getOverflowBubbles().size()); + } + private void verifyUpdateReceived() { verify(mListener).applyUpdate(mUpdateCaptor.capture()); reset(mListener); |