[Output Switcher] Adjust casting volume in output switcher cause icons to flicker
-Only update current active item Bug: 190146269 Test: atest MediaOutputAdapterTest MediaOutputControllerTest MediaOutputBaseDialogTest MediaOutputDialogTest MediaOutputGroupAdapterTest MediaOutputGroupDialogTest Change-Id: I603e895b7e0e08874c53527cbb5ff177e2b97c5b
This commit is contained in:
@@ -46,7 +46,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private ViewGroup mConnectedItem;
|
||||
private boolean mInclueDynamicGroup;
|
||||
private boolean mIncludeDynamicGroup;
|
||||
|
||||
public MediaOutputAdapter(MediaOutputController controller) {
|
||||
super(controller);
|
||||
@@ -56,7 +56,6 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
public MediaDeviceBaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
|
||||
int viewType) {
|
||||
super.onCreateViewHolder(viewGroup, viewType);
|
||||
|
||||
return new MediaDeviceViewHolder(mHolderView);
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
if (position == size && mController.isZeroMode()) {
|
||||
viewHolder.onBind(CUSTOMIZED_ITEM_PAIR_NEW, false /* topMargin */,
|
||||
true /* bottomMargin */);
|
||||
} else if (mInclueDynamicGroup) {
|
||||
} else if (mIncludeDynamicGroup) {
|
||||
if (position == 0) {
|
||||
viewHolder.onBind(CUSTOMIZED_ITEM_DYNAMIC_GROUP, true /* topMargin */,
|
||||
false /* bottomMargin */);
|
||||
@@ -76,11 +75,12 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
// from "position - 1".
|
||||
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices()))
|
||||
.get(position - 1),
|
||||
false /* topMargin */, position == size /* bottomMargin */);
|
||||
false /* topMargin */, position == size /* bottomMargin */, position);
|
||||
}
|
||||
} else if (position < size) {
|
||||
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices())).get(position),
|
||||
position == 0 /* topMargin */, position == (size - 1) /* bottomMargin */);
|
||||
position == 0 /* topMargin */, position == (size - 1) /* bottomMargin */,
|
||||
position);
|
||||
} else if (DEBUG) {
|
||||
Log.d(TAG, "Incorrect position: " + position);
|
||||
}
|
||||
@@ -88,8 +88,8 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
mInclueDynamicGroup = mController.getSelectedMediaDevice().size() > 1;
|
||||
if (mController.isZeroMode() || mInclueDynamicGroup) {
|
||||
mIncludeDynamicGroup = mController.getSelectedMediaDevice().size() > 1;
|
||||
if (mController.isZeroMode() || mIncludeDynamicGroup) {
|
||||
// Add extra one for "pair new" or dynamic group
|
||||
return mController.getMediaDevices().size() + 1;
|
||||
}
|
||||
@@ -120,9 +120,10 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
||||
super.onBind(device, topMargin, bottomMargin);
|
||||
final boolean currentlyConnected = !mInclueDynamicGroup && isCurrentlyConnected(device);
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||
super.onBind(device, topMargin, bottomMargin, position);
|
||||
final boolean currentlyConnected = !mIncludeDynamicGroup
|
||||
&& isCurrentlyConnected(device);
|
||||
if (currentlyConnected) {
|
||||
mConnectedItem = mContainerLayout;
|
||||
}
|
||||
@@ -160,6 +161,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
||||
setTwoLineLayout(device, true /* bFocused */, true /* showSeekBar */,
|
||||
false /* showProgressBar */, false /* showSubtitle */);
|
||||
initSeekbar(device);
|
||||
mCurrentActivePosition = position;
|
||||
} else {
|
||||
setSingleLineLayout(getItemTitle(device), false /* bFocused */);
|
||||
mContainerLayout.setOnClickListener(v -> onItemClick(v, device));
|
||||
|
||||
@@ -64,10 +64,12 @@ public abstract class MediaOutputBaseAdapter extends
|
||||
Context mContext;
|
||||
View mHolderView;
|
||||
boolean mIsDragging;
|
||||
int mCurrentActivePosition;
|
||||
|
||||
public MediaOutputBaseAdapter(MediaOutputController controller) {
|
||||
mController = controller;
|
||||
mIsDragging = false;
|
||||
mCurrentActivePosition = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,6 +101,10 @@ public abstract class MediaOutputBaseAdapter extends
|
||||
return mIsAnimating;
|
||||
}
|
||||
|
||||
int getCurrentActivePosition() {
|
||||
return mCurrentActivePosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewHolder for binding device view.
|
||||
*/
|
||||
@@ -136,7 +142,7 @@ public abstract class MediaOutputBaseAdapter extends
|
||||
mCheckBox = view.requireViewById(R.id.check_box);
|
||||
}
|
||||
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||
mDeviceId = device.getId();
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
|
||||
|
||||
@@ -174,7 +174,12 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
||||
mHeaderTitle.setGravity(Gravity.NO_GRAVITY);
|
||||
}
|
||||
if (!mAdapter.isDragging() && !mAdapter.isAnimating()) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
int currentActivePosition = mAdapter.getCurrentActivePosition();
|
||||
if (currentActivePosition >= 0) {
|
||||
mAdapter.notifyItemChanged(currentActivePosition);
|
||||
} else {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
// Show when remote media session is available
|
||||
mStopButton.setVisibility(getStopButtonVisibility());
|
||||
|
||||
@@ -68,7 +68,7 @@ public class MediaOutputGroupAdapter extends MediaOutputBaseAdapter {
|
||||
final int size = mGroupMediaDevices.size();
|
||||
if (newPosition < size) {
|
||||
viewHolder.onBind(mGroupMediaDevices.get(newPosition), false /* topMargin */,
|
||||
newPosition == (size - 1) /* bottomMargin */);
|
||||
newPosition == (size - 1) /* bottomMargin */, position);
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
@@ -94,8 +94,8 @@ public class MediaOutputGroupAdapter extends MediaOutputBaseAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
||||
super.onBind(device, topMargin, bottomMargin);
|
||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||
super.onBind(device, topMargin, bottomMargin, position);
|
||||
mDivider.setVisibility(View.GONE);
|
||||
mAddIcon.setVisibility(View.GONE);
|
||||
mBottomDivider.setVisibility(View.GONE);
|
||||
|
||||
@@ -155,6 +155,7 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void refresh_notInDragging_verifyUpdateAdapter() {
|
||||
when(mMediaOutputBaseAdapter.getCurrentActivePosition()).thenReturn(-1);
|
||||
when(mMediaOutputBaseAdapter.isDragging()).thenReturn(false);
|
||||
mMediaOutputBaseDialogImpl.refresh();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user