Commit 602d8808 by insun Committed by kim-vde

Fix StyledControlView's minimal mode bug and setShow{*}Button bug

There were two bugs in StyledPlayerControlView:
- Center icons are shown when toggling control view in minimal mode.
- `StyledControlView#setShow{*}Button` methods and corresponding
  `set_show_*_button` attributes didn't work properly.

This CL fixes bugs by controlling the buttons' visibility in one place,
StyledPlayerControlViewLayoutManager.

PiperOrigin-RevId: 326567213
parent e6bf7bd0
...@@ -28,6 +28,7 @@ import android.view.ViewGroup.MarginLayoutParams; ...@@ -28,6 +28,7 @@ import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/* package */ final class StyledPlayerControlViewLayoutManager { /* package */ final class StyledPlayerControlViewLayoutManager {
private static final long ANIMATION_INTERVAL_MS = 2_000; private static final long ANIMATION_INTERVAL_MS = 2_000;
...@@ -53,6 +54,8 @@ import java.util.ArrayList; ...@@ -53,6 +54,8 @@ import java.util.ArrayList;
private final Runnable hideControllerRunnable; private final Runnable hideControllerRunnable;
private final OnLayoutChangeListener onLayoutChangeListener; private final OnLayoutChangeListener onLayoutChangeListener;
private final List<View> shownButtons;
private int uxState; private int uxState;
private boolean initiallyHidden; private boolean initiallyHidden;
private boolean isMinimalMode; private boolean isMinimalMode;
...@@ -88,6 +91,7 @@ import java.util.ArrayList; ...@@ -88,6 +91,7 @@ import java.util.ArrayList;
onLayoutChangeListener = this::onLayoutChange; onLayoutChangeListener = this::onLayoutChange;
animationEnabled = true; animationEnabled = true;
uxState = UX_STATE_ALL_VISIBLE; uxState = UX_STATE_ALL_VISIBLE;
shownButtons = new ArrayList<>();
} }
public void show() { public void show() {
...@@ -157,6 +161,7 @@ import java.util.ArrayList; ...@@ -157,6 +161,7 @@ import java.util.ArrayList;
styledPlayerControlView.removeCallbacks(hideProgressBarRunnable); styledPlayerControlView.removeCallbacks(hideProgressBarRunnable);
} }
// TODO(insun): Pass StyledPlayerControlView to constructor and reduce multiple nullchecks.
public void onViewAttached(StyledPlayerControlView v) { public void onViewAttached(StyledPlayerControlView v) {
styledPlayerControlView = v; styledPlayerControlView = v;
...@@ -426,6 +431,27 @@ import java.util.ArrayList; ...@@ -426,6 +431,27 @@ import java.util.ArrayList;
return uxState == UX_STATE_ALL_VISIBLE && styledPlayerControlView.isVisible(); return uxState == UX_STATE_ALL_VISIBLE && styledPlayerControlView.isVisible();
} }
public void setShowButton(@Nullable View button, boolean showButton) {
if (button == null) {
return;
}
if (!showButton) {
button.setVisibility(View.GONE);
shownButtons.remove(button);
return;
}
if (isMinimalMode && shouldHideInMinimalMode(button)) {
button.setVisibility(View.INVISIBLE);
} else {
button.setVisibility(View.VISIBLE);
}
shownButtons.add(button);
}
public boolean getShowButton(@Nullable View button) {
return button != null && shownButtons.contains(button);
}
private void setUxState(int uxState) { private void setUxState(int uxState) {
int prevUxState = this.uxState; int prevUxState = this.uxState;
this.uxState = uxState; this.uxState = uxState;
...@@ -573,9 +599,7 @@ import java.util.ArrayList; ...@@ -573,9 +599,7 @@ import java.util.ArrayList;
Math.max( Math.max(
getWidth(embeddedTransportControls), getWidth(timeView) + getWidth(overflowShowButton)); getWidth(embeddedTransportControls), getWidth(timeView) + getWidth(overflowShowButton));
int defaultModeHeight = int defaultModeHeight =
getHeight(embeddedTransportControls) getHeight(embeddedTransportControls) + getHeight(timeBar) + getHeight(bottomBar);
+ getHeight(timeBar)
+ getHeight(bottomBar);
return (width <= defaultModeWidth || height <= defaultModeHeight); return (width <= defaultModeWidth || height <= defaultModeHeight);
} }
...@@ -584,7 +608,7 @@ import java.util.ArrayList; ...@@ -584,7 +608,7 @@ import java.util.ArrayList;
if (this.styledPlayerControlView == null) { if (this.styledPlayerControlView == null) {
return; return;
} }
ViewGroup playerControlView = this.styledPlayerControlView; StyledPlayerControlView playerControlView = this.styledPlayerControlView;
if (minimalControls != null) { if (minimalControls != null) {
minimalControls.setVisibility(isMinimalMode ? View.VISIBLE : View.INVISIBLE); minimalControls.setVisibility(isMinimalMode ? View.VISIBLE : View.INVISIBLE);
...@@ -624,23 +648,22 @@ import java.util.ArrayList; ...@@ -624,23 +648,22 @@ import java.util.ArrayList;
} }
} }
int[] idsToHideInMinimalMode = { for (View v : shownButtons) {
R.id.exo_bottom_bar, v.setVisibility(isMinimalMode && shouldHideInMinimalMode(v) ? View.INVISIBLE : View.VISIBLE);
R.id.exo_prev,
R.id.exo_next,
R.id.exo_rew,
R.id.exo_rew_with_amount,
R.id.exo_ffwd,
R.id.exo_ffwd_with_amount
};
for (int id : idsToHideInMinimalMode) {
View v = playerControlView.findViewById(id);
if (v != null) {
v.setVisibility(isMinimalMode ? View.INVISIBLE : View.VISIBLE);
}
} }
} }
private boolean shouldHideInMinimalMode(View button) {
int id = button.getId();
return (id == R.id.exo_bottom_bar
|| id == R.id.exo_prev
|| id == R.id.exo_next
|| id == R.id.exo_rew
|| id == R.id.exo_rew_with_amount
|| id == R.id.exo_ffwd
|| id == R.id.exo_ffwd_with_amount);
}
private void onLayoutWidthChanged() { private void onLayoutWidthChanged() {
if (basicControls == null || extraControls == null) { if (basicControls == null || extraControls == null) {
return; return;
......
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