Merge "Create an interface to update for view changes for bubbles" into tm-qpr-dev

This commit is contained in:
Mady Mellor
2023-03-09 00:54:03 +00:00
committed by Android (Google) Code Review
2 changed files with 107 additions and 32 deletions

View File

@@ -135,6 +135,30 @@ public class BubbleController implements ConfigurationChangeListener {
private static final boolean BUBBLE_BAR_ENABLED = private static final boolean BUBBLE_BAR_ENABLED =
SystemProperties.getBoolean("persist.wm.debug.bubble_bar", false); SystemProperties.getBoolean("persist.wm.debug.bubble_bar", false);
/**
* Common interface to send updates to bubble views.
*/
public interface BubbleViewCallback {
/** Called when the provided bubble should be removed. */
void removeBubble(Bubble removedBubble);
/** Called when the provided bubble should be added. */
void addBubble(Bubble addedBubble);
/** Called when the provided bubble should be updated. */
void updateBubble(Bubble updatedBubble);
/** Called when the provided bubble should be selected. */
void selectionChanged(BubbleViewProvider selectedBubble);
/** Called when the provided bubble's suppression state has changed. */
void suppressionChanged(Bubble bubble, boolean isSuppressed);
/** Called when the expansion state of bubbles has changed. */
void expansionChanged(boolean isExpanded);
/**
* Called when the order of the bubble list has changed. Depending on the expanded state
* the pointer might need to be updated.
*/
void bubbleOrderChanged(List<Bubble> bubbleOrder, boolean updatePointer);
}
private final Context mContext; private final Context mContext;
private final BubblesImpl mImpl = new BubblesImpl(); private final BubblesImpl mImpl = new BubblesImpl();
private Bubbles.BubbleExpandListener mExpandListener; private Bubbles.BubbleExpandListener mExpandListener;
@@ -157,7 +181,6 @@ public class BubbleController implements ConfigurationChangeListener {
// Used to post to main UI thread // Used to post to main UI thread
private final ShellExecutor mMainExecutor; private final ShellExecutor mMainExecutor;
private final Handler mMainHandler; private final Handler mMainHandler;
private final ShellExecutor mBackgroundExecutor; private final ShellExecutor mBackgroundExecutor;
private BubbleLogger mLogger; private BubbleLogger mLogger;
@@ -1285,6 +1308,58 @@ public class BubbleController implements ConfigurationChangeListener {
}); });
} }
private final BubbleViewCallback mBubbleViewCallback = new BubbleViewCallback() {
@Override
public void removeBubble(Bubble removedBubble) {
if (mStackView != null) {
mStackView.removeBubble(removedBubble);
}
}
@Override
public void addBubble(Bubble addedBubble) {
if (mStackView != null) {
mStackView.addBubble(addedBubble);
}
}
@Override
public void updateBubble(Bubble updatedBubble) {
if (mStackView != null) {
mStackView.updateBubble(updatedBubble);
}
}
@Override
public void bubbleOrderChanged(List<Bubble> bubbleOrder, boolean updatePointer) {
if (mStackView != null) {
mStackView.updateBubbleOrder(bubbleOrder, updatePointer);
}
}
@Override
public void suppressionChanged(Bubble bubble, boolean isSuppressed) {
if (mStackView != null) {
mStackView.setBubbleSuppressed(bubble, isSuppressed);
}
}
@Override
public void expansionChanged(boolean isExpanded) {
if (mStackView != null) {
mStackView.setExpanded(isExpanded);
}
}
@Override
public void selectionChanged(BubbleViewProvider selectedBubble) {
if (mStackView != null) {
mStackView.setSelectedBubble(selectedBubble);
}
}
};
@SuppressWarnings("FieldCanBeLocal") @SuppressWarnings("FieldCanBeLocal")
private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() {
@@ -1307,7 +1382,8 @@ public class BubbleController implements ConfigurationChangeListener {
// Lazy load overflow bubbles from disk // Lazy load overflow bubbles from disk
loadOverflowBubblesFromDisk(); loadOverflowBubblesFromDisk();
mStackView.updateOverflowButtonDot(); // If bubbles in the overflow have a dot, make sure the overflow shows a dot
updateOverflowButtonDot();
// Update bubbles in overflow. // Update bubbles in overflow.
if (mOverflowListener != null) { if (mOverflowListener != null) {
@@ -1322,9 +1398,7 @@ public class BubbleController implements ConfigurationChangeListener {
final Bubble bubble = removed.first; final Bubble bubble = removed.first;
@Bubbles.DismissReason final int reason = removed.second; @Bubbles.DismissReason final int reason = removed.second;
if (mStackView != null) { mBubbleViewCallback.removeBubble(bubble);
mStackView.removeBubble(bubble);
}
// Leave the notification in place if we're dismissing due to user switching, or // Leave the notification in place if we're dismissing due to user switching, or
// because DND is suppressing the bubble. In both of those cases, we need to be able // because DND is suppressing the bubble. In both of those cases, we need to be able
@@ -1354,49 +1428,47 @@ public class BubbleController implements ConfigurationChangeListener {
} }
mDataRepository.removeBubbles(mCurrentUserId, bubblesToBeRemovedFromRepository); mDataRepository.removeBubbles(mCurrentUserId, bubblesToBeRemovedFromRepository);
if (update.addedBubble != null && mStackView != null) { if (update.addedBubble != null) {
mDataRepository.addBubble(mCurrentUserId, update.addedBubble); mDataRepository.addBubble(mCurrentUserId, update.addedBubble);
mStackView.addBubble(update.addedBubble); mBubbleViewCallback.addBubble(update.addedBubble);
} }
if (update.updatedBubble != null && mStackView != null) { if (update.updatedBubble != null) {
mStackView.updateBubble(update.updatedBubble); mBubbleViewCallback.updateBubble(update.updatedBubble);
} }
if (update.suppressedBubble != null && mStackView != null) { if (update.suppressedBubble != null) {
mStackView.setBubbleSuppressed(update.suppressedBubble, true); mBubbleViewCallback.suppressionChanged(update.suppressedBubble, true);
} }
if (update.unsuppressedBubble != null && mStackView != null) { if (update.unsuppressedBubble != null) {
mStackView.setBubbleSuppressed(update.unsuppressedBubble, false); mBubbleViewCallback.suppressionChanged(update.unsuppressedBubble, false);
} }
boolean collapseStack = update.expandedChanged && !update.expanded; boolean collapseStack = update.expandedChanged && !update.expanded;
// At this point, the correct bubbles are inflated in the stack. // At this point, the correct bubbles are inflated in the stack.
// Make sure the order in bubble data is reflected in bubble row. // Make sure the order in bubble data is reflected in bubble row.
if (update.orderChanged && mStackView != null) { if (update.orderChanged) {
mDataRepository.addBubbles(mCurrentUserId, update.bubbles); mDataRepository.addBubbles(mCurrentUserId, update.bubbles);
// if the stack is going to be collapsed, do not update pointer position // if the stack is going to be collapsed, do not update pointer position
// after reordering // after reordering
mStackView.updateBubbleOrder(update.bubbles, !collapseStack); mBubbleViewCallback.bubbleOrderChanged(update.bubbles, !collapseStack);
} }
if (collapseStack) { if (collapseStack) {
mStackView.setExpanded(false); mBubbleViewCallback.expansionChanged(/* expanded= */ false);
mSysuiProxy.requestNotificationShadeTopUi(false, TAG); mSysuiProxy.requestNotificationShadeTopUi(false, TAG);
} }
if (update.selectionChanged && mStackView != null) { if (update.selectionChanged) {
mStackView.setSelectedBubble(update.selectedBubble); mBubbleViewCallback.selectionChanged(update.selectedBubble);
} }
// Expanding? Apply this last. // Expanding? Apply this last.
if (update.expandedChanged && update.expanded) { if (update.expandedChanged && update.expanded) {
if (mStackView != null) { mBubbleViewCallback.expansionChanged(/* expanded= */ true);
mStackView.setExpanded(true); mSysuiProxy.requestNotificationShadeTopUi(true, TAG);
mSysuiProxy.requestNotificationShadeTopUi(true, TAG);
}
} }
mSysuiProxy.notifyInvalidateNotifications("BubbleData.Listener.applyUpdate"); mSysuiProxy.notifyInvalidateNotifications("BubbleData.Listener.applyUpdate");
@@ -1407,6 +1479,19 @@ public class BubbleController implements ConfigurationChangeListener {
} }
}; };
private void updateOverflowButtonDot() {
BubbleOverflow overflow = mBubbleData.getOverflow();
if (overflow == null) return;
for (Bubble b : mBubbleData.getOverflowBubbles()) {
if (b.showDot()) {
overflow.setShowDot(true);
return;
}
}
overflow.setShowDot(false);
}
private boolean handleDismissalInterception(BubbleEntry entry, private boolean handleDismissalInterception(BubbleEntry entry,
@Nullable List<BubbleEntry> children, IntConsumer removeCallback) { @Nullable List<BubbleEntry> children, IntConsumer removeCallback) {
if (isSummaryOfBubbles(entry)) { if (isSummaryOfBubbles(entry)) {

View File

@@ -1360,16 +1360,6 @@ public class BubbleStackView extends FrameLayout
updateOverflowVisibility(); updateOverflowVisibility();
} }
void updateOverflowButtonDot() {
for (Bubble b : mBubbleData.getOverflowBubbles()) {
if (b.showDot()) {
mBubbleOverflow.setShowDot(true);
return;
}
}
mBubbleOverflow.setShowDot(false);
}
/** /**
* Handle theme changes. * Handle theme changes.
*/ */