Commit 751809b4 by olly Committed by Christos Tsilopoulos

StyledPlayerView: Fix control overflow logic

PiperOrigin-RevId: 347657903
parent 7c28df62
...@@ -631,65 +631,59 @@ import java.util.List; ...@@ -631,65 +631,59 @@ import java.util.List;
styledPlayerControlView.getWidth() styledPlayerControlView.getWidth()
- styledPlayerControlView.getPaddingLeft() - styledPlayerControlView.getPaddingLeft()
- styledPlayerControlView.getPaddingRight(); - styledPlayerControlView.getPaddingRight();
int bottomBarWidth = getWidthWithMargins(timeView);
for (int i = 0; i < basicControls.getChildCount(); ++i) { // Reset back to all controls being basic controls and the overflow not being needed. The last
bottomBarWidth += basicControls.getChildAt(i).getWidth(); // child of extraControls is the overflow hide button, which shouldn't be moved back.
while (extraControls.getChildCount() > 1) {
int controlViewIndex = extraControls.getChildCount() - 2;
View controlView = extraControls.getChildAt(controlViewIndex);
extraControls.removeViewAt(controlViewIndex);
basicControls.addView(controlView, /* index= */ 0);
}
if (overflowShowButton != null) {
overflowShowButton.setVisibility(View.GONE);
}
// Calculate how much of the available width is occupied. The last child of basicControls is the
// overflow show button, which we're currently assuming will not be visible.
int occupiedWidth = getWidthWithMargins(timeView);
int endIndex = basicControls.getChildCount() - 1;
for (int i = 0; i < endIndex; i++) {
View controlView = basicControls.getChildAt(i);
occupiedWidth += getWidthWithMargins(controlView);
} }
if (bottomBarWidth > width) { if (occupiedWidth > width) {
if (overflowShowButton != null && overflowShowButton.getVisibility() != View.VISIBLE) { // We need to move some controls to extraControls.
if (overflowShowButton != null) {
overflowShowButton.setVisibility(View.VISIBLE); overflowShowButton.setVisibility(View.VISIBLE);
bottomBarWidth += overflowShowButton.getWidth(); occupiedWidth += getWidthWithMargins(overflowShowButton);
} }
// Move control views from basicControls to extraControls ArrayList<View> controlsToMove = new ArrayList<>();
ArrayList<View> movingChildren = new ArrayList<>(); // The last child of basicControls is the overflow show button, which shouldn't be moved.
int movingWidth = 0; for (int i = 0; i < endIndex; i++) {
// The last child is overflow show button, which shouldn't move. View control = basicControls.getChildAt(i);
int endIndex = basicControls.getChildCount() - 1; occupiedWidth -= getWidthWithMargins(control);
for (int index = 0; index < endIndex; index++) { controlsToMove.add(control);
View child = basicControls.getChildAt(index); if (occupiedWidth <= width) {
movingWidth += child.getWidth();
movingChildren.add(child);
if (bottomBarWidth - movingWidth <= width) {
break; break;
} }
} }
if (!controlsToMove.isEmpty()) {
if (!movingChildren.isEmpty()) { basicControls.removeViews(/* start= */ 0, controlsToMove.size());
basicControls.removeViews(0, movingChildren.size()); for (int i = 0; i < controlsToMove.size(); i++) {
// The last child of extraControls is the overflow hide button. Add controls before it.
for (View child : movingChildren) {
// The last child of extra controls is the overflow hide button. Adding other buttons
// before it.
int index = extraControls.getChildCount() - 1; int index = extraControls.getChildCount() - 1;
extraControls.addView(child, index); extraControls.addView(controlsToMove.get(i), index);
} }
} }
} else { } else {
// Move controls from extraControls to basicControls if possible, else do nothing. // If extraControls are visible, hide them since they're now empty.
ArrayList<View> movingChildren = new ArrayList<>(); if (extraControlsScrollView != null
int movingWidth = 0; && extraControlsScrollView.getVisibility() == View.VISIBLE
// The last child of extra controls is the overflow button, which shouldn't move. && !overflowHideAnimator.isStarted()) {
int endIndex = extraControls.getChildCount() - 2; overflowShowAnimator.cancel();
for (int index = endIndex; index >= 0; index--) { overflowHideAnimator.start();
View child = extraControls.getChildAt(index);
movingWidth += child.getWidth();
if (bottomBarWidth + movingWidth > width) {
break;
}
movingChildren.add(child);
}
if (!movingChildren.isEmpty()) {
extraControls.removeViews(endIndex - movingChildren.size() + 1, movingChildren.size());
for (View child : movingChildren) {
basicControls.addView(child, 0);
}
}
if (extraControls.getChildCount() == 1 && overflowShowButton != null) {
overflowShowButton.setVisibility(View.GONE);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment