diff options
| author | 2022-02-08 07:47:16 +0000 | |
|---|---|---|
| committer | 2022-02-08 07:47:16 +0000 | |
| commit | ae1e8c1df151f1a4bde40633ed1409304a23fef0 (patch) | |
| tree | 3e5c708ec51c8b2a57a81105a00fa25f33187aec | |
| parent | ed3eb039b888ccb6c7505fbb3295251ef5f46402 (diff) | |
| parent | 72f590464fee58b8f3a7d24e95a17a20bed99e7d (diff) | |
[automerge] [Output Switcher] Refresh list when data set changed 2p: 72f590464f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16689464
Bug: 211392105
Change-Id: If7bc6c6ecab2583baa9fa25c43f6a1f395d43ac3
3 files changed, 19 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java index f2cb254c3b97..b309c1bb67b9 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java @@ -150,6 +150,10 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements } void refresh() { + refresh(false); + } + + void refresh(boolean deviceSetChanged) { // Update header icon final int iconRes = getHeaderIconRes(); final IconCompat iconCompat = getHeaderIcon(); @@ -175,7 +179,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements } if (!mAdapter.isDragging() && !mAdapter.isAnimating()) { int currentActivePosition = mAdapter.getCurrentActivePosition(); - if (currentActivePosition >= 0 && currentActivePosition < mAdapter.getItemCount()) { + if (!deviceSetChanged && currentActivePosition >= 0 + && currentActivePosition < mAdapter.getItemCount()) { mAdapter.notifyItemChanged(currentActivePosition); } else { mAdapter.notifyDataSetChanged(); @@ -215,6 +220,11 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements } @Override + public void onDeviceListChanged() { + mMainThreadHandler.post(() -> refresh(true)); + } + + @Override public void dismissDialog() { dismiss(); } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index a1e2c57c5c37..9eaedd753394 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -166,7 +166,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback { @Override public void onDeviceListUpdate(List<MediaDevice> devices) { buildMediaDevices(devices); - mCallback.onRouteChanged(); + mCallback.onDeviceListChanged(); } @Override @@ -529,11 +529,16 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback { void onMediaStoppedOrPaused(); /** - * Override to handle the device updating. + * Override to handle the device status or attributes updating. */ void onRouteChanged(); /** + * Override to handle the devices set updating. + */ + void onDeviceListChanged(); + + /** * Override to dismiss dialog. */ void dismissDialog(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java index cd26e0d960dc..b5c501ab388b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java @@ -201,7 +201,7 @@ public class MediaOutputControllerTest extends SysuiTestCase { assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); - verify(mCb).onRouteChanged(); + verify(mCb).onDeviceListChanged(); } @Test |