Commit 5e1c96ad by olly Committed by kim-vde

Fix a couple of StyledPlayerControlView bugs

1. The first time the player controls are are made visible,
   there is no animation.
2. The first time the player controls are made visible, the
   "select tracks" button isn't displayed. When tapping to
   subsequently hide the player controls, the button briefly
   becomes visible and then is hidden again. This bug is due
   to state in StyledPlayerControlViewLayoutManager being
   out of sync, resulting in StyledPlayerControlView's
   onVisibilityChange not being called properly.

After this change both of these issues should be resolved.

PiperOrigin-RevId: 336704031
parent c21529de
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
* Show overflow button in `StyledPlayerControlView` only when there is no * Show overflow button in `StyledPlayerControlView` only when there is no
enough space. enough space.
* UI:
* Fix animation when `StyledPlayerView` first shows its playback controls.
### 2.12.0 (2020-09-11) ### ### 2.12.0 (2020-09-11) ###
......
...@@ -459,6 +459,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -459,6 +459,7 @@ public class StyledPlayerControlView extends FrameLayout {
@SuppressWarnings({ @SuppressWarnings({
"nullness:argument.type.incompatible", "nullness:argument.type.incompatible",
"nullness:assignment.type.incompatible",
"nullness:method.invocation.invalid", "nullness:method.invocation.invalid",
"nullness:methodref.receiver.bound.invalid" "nullness:methodref.receiver.bound.invalid"
}) })
...@@ -526,8 +527,11 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -526,8 +527,11 @@ public class StyledPlayerControlView extends FrameLayout {
a.recycle(); a.recycle();
} }
} }
controlViewLayoutManager = new StyledPlayerControlViewLayoutManager();
controlViewLayoutManager.setAnimationEnabled(animationEnabled); LayoutInflater.from(context).inflate(controllerLayoutId, /* root= */ this);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
componentListener = new ComponentListener();
visibilityListeners = new CopyOnWriteArrayList<>(); visibilityListeners = new CopyOnWriteArrayList<>();
period = new Timeline.Period(); period = new Timeline.Period();
window = new Timeline.Window(); window = new Timeline.Window();
...@@ -537,13 +541,9 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -537,13 +541,9 @@ public class StyledPlayerControlView extends FrameLayout {
playedAdGroups = new boolean[0]; playedAdGroups = new boolean[0];
extraAdGroupTimesMs = new long[0]; extraAdGroupTimesMs = new long[0];
extraPlayedAdGroups = new boolean[0]; extraPlayedAdGroups = new boolean[0];
componentListener = new ComponentListener();
controlDispatcher = new DefaultControlDispatcher(fastForwardMs, rewindMs); controlDispatcher = new DefaultControlDispatcher(fastForwardMs, rewindMs);
updateProgressAction = this::updateProgress; updateProgressAction = this::updateProgress;
LayoutInflater.from(context).inflate(controllerLayoutId, /* root= */ this);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
// Relating to Bottom Bar Left View // Relating to Bottom Bar Left View
durationView = findViewById(R.id.exo_duration); durationView = findViewById(R.id.exo_duration);
positionView = findViewById(R.id.exo_position); positionView = findViewById(R.id.exo_position);
...@@ -581,10 +581,10 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -581,10 +581,10 @@ public class StyledPlayerControlView extends FrameLayout {
} else { } else {
timeBar = null; timeBar = null;
} }
if (timeBar != null) { if (timeBar != null) {
timeBar.addListener(componentListener); timeBar.addListener(componentListener);
} }
playPauseButton = findViewById(R.id.exo_play_pause); playPauseButton = findViewById(R.id.exo_play_pause);
if (playPauseButton != null) { if (playPauseButton != null) {
playPauseButton.setOnClickListener(componentListener); playPauseButton.setOnClickListener(componentListener);
...@@ -626,7 +626,6 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -626,7 +626,6 @@ public class StyledPlayerControlView extends FrameLayout {
} }
resources = context.getResources(); resources = context.getResources();
buttonAlphaEnabled = buttonAlphaEnabled =
(float) resources.getInteger(R.integer.exo_media_button_opacity_percentage_enabled) / 100; (float) resources.getInteger(R.integer.exo_media_button_opacity_percentage_enabled) / 100;
buttonAlphaDisabled = buttonAlphaDisabled =
...@@ -634,10 +633,12 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -634,10 +633,12 @@ public class StyledPlayerControlView extends FrameLayout {
vrButton = findViewById(R.id.exo_vr); vrButton = findViewById(R.id.exo_vr);
if (vrButton != null) { if (vrButton != null) {
setShowVrButton(showVrButton);
updateButton(/* enabled= */ false, vrButton); updateButton(/* enabled= */ false, vrButton);
} }
controlViewLayoutManager = new StyledPlayerControlViewLayoutManager(this);
controlViewLayoutManager.setAnimationEnabled(animationEnabled);
// Related to Settings List View // Related to Settings List View
String[] settingTexts = new String[2]; String[] settingTexts = new String[2];
Drawable[] settingIcons = new Drawable[2]; Drawable[] settingIcons = new Drawable[2];
...@@ -1071,6 +1072,11 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1071,6 +1072,11 @@ public class StyledPlayerControlView extends FrameLayout {
controlViewLayoutManager.hide(); controlViewLayoutManager.hide();
} }
/** Hides the controller without any animation. */
public void hideImmediately() {
controlViewLayoutManager.hideImmediately();
}
/** Returns whether the controller is fully visible, which means all UI controls are visible. */ /** Returns whether the controller is fully visible, which means all UI controls are visible. */
public boolean isFullyVisible() { public boolean isFullyVisible() {
return controlViewLayoutManager.isFullyVisible(); return controlViewLayoutManager.isFullyVisible();
...@@ -1607,7 +1613,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1607,7 +1613,7 @@ public class StyledPlayerControlView extends FrameLayout {
@Override @Override
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
controlViewLayoutManager.onViewAttached(this); controlViewLayoutManager.onAttachedToWindow();
isAttachedToWindow = true; isAttachedToWindow = true;
if (isFullyVisible()) { if (isFullyVisible()) {
controlViewLayoutManager.resetHideCallbacks(); controlViewLayoutManager.resetHideCallbacks();
...@@ -1618,7 +1624,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1618,7 +1624,7 @@ public class StyledPlayerControlView extends FrameLayout {
@Override @Override
public void onDetachedFromWindow() { public void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
controlViewLayoutManager.onViewDetached(this); controlViewLayoutManager.onDetachedFromWindow();
isAttachedToWindow = false; isAttachedToWindow = false;
removeCallbacks(updateProgressAction); removeCallbacks(updateProgressAction);
controlViewLayoutManager.removeHideCallbacks(); controlViewLayoutManager.removeHideCallbacks();
......
...@@ -510,11 +510,11 @@ public class StyledPlayerView extends FrameLayout implements AdsLoader.AdViewPro ...@@ -510,11 +510,11 @@ public class StyledPlayerView extends FrameLayout implements AdsLoader.AdViewPro
this.controllerAutoShow = controllerAutoShow; this.controllerAutoShow = controllerAutoShow;
this.controllerHideDuringAds = controllerHideDuringAds; this.controllerHideDuringAds = controllerHideDuringAds;
this.useController = useController && controller != null; this.useController = useController && controller != null;
hideController();
updateContentDescription();
if (controller != null) { if (controller != null) {
controller.hideImmediately();
controller.addVisibilityListener(/* listener= */ componentListener); controller.addVisibilityListener(/* listener= */ componentListener);
} }
updateContentDescription();
} }
/** /**
......
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