Merge "[Media TTT] Don't show scrubbing times if we don't have the prev or next button." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7af8cbc481
@@ -630,7 +630,7 @@ public class MediaControlPanel {
|
||||
for (int id : SEMANTIC_ACTIONS_ALL) {
|
||||
ImageButton button = mMediaViewHolder.getAction(id);
|
||||
MediaAction action = semanticActions.getActionById(id);
|
||||
setSemanticButton(button, action);
|
||||
setSemanticButton(button, action, semanticActions);
|
||||
}
|
||||
} else {
|
||||
// Hide buttons that only appear for semantic actions
|
||||
@@ -699,7 +699,10 @@ public class MediaControlPanel {
|
||||
setVisibleAndAlpha(collapsedSet, button.getId(), visible && showInCompact);
|
||||
}
|
||||
|
||||
private void setSemanticButton(final ImageButton button, @Nullable MediaAction mediaAction) {
|
||||
private void setSemanticButton(
|
||||
final ImageButton button,
|
||||
@Nullable MediaAction mediaAction,
|
||||
MediaButton semanticActions) {
|
||||
AnimationBindHandler animHandler;
|
||||
if (button.getTag() == null) {
|
||||
animHandler = new AnimationBindHandler();
|
||||
@@ -710,7 +713,7 @@ public class MediaControlPanel {
|
||||
|
||||
animHandler.tryExecute(() -> {
|
||||
bindButtonWithAnimations(button, mediaAction, animHandler);
|
||||
setSemanticButtonVisibleAndAlpha(button.getId(), mediaAction);
|
||||
setSemanticButtonVisibleAndAlpha(button.getId(), mediaAction, semanticActions);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -773,12 +776,14 @@ public class MediaControlPanel {
|
||||
|
||||
private void setSemanticButtonVisibleAndAlpha(
|
||||
int buttonId,
|
||||
MediaAction mediaAction) {
|
||||
@Nullable MediaAction mediaAction,
|
||||
MediaButton semanticActions) {
|
||||
ConstraintSet collapsedSet = mMediaViewController.getCollapsedLayout();
|
||||
ConstraintSet expandedSet = mMediaViewController.getExpandedLayout();
|
||||
boolean showInCompact = SEMANTIC_ACTIONS_COMPACT.contains(buttonId);
|
||||
boolean hideWhenScrubbing = SEMANTIC_ACTIONS_HIDE_WHEN_SCRUBBING.contains(buttonId);
|
||||
boolean shouldBeHiddenDueToScrubbing = hideWhenScrubbing && mIsScrubbing;
|
||||
boolean shouldBeHiddenDueToScrubbing =
|
||||
scrubbingTimeViewsEnabled(semanticActions) && hideWhenScrubbing && mIsScrubbing;
|
||||
boolean visible = mediaAction != null && !shouldBeHiddenDueToScrubbing;
|
||||
|
||||
setVisibleAndAlpha(expandedSet, buttonId, visible);
|
||||
@@ -791,7 +796,8 @@ public class MediaControlPanel {
|
||||
// Update visibilities of the scrubbing time views and the scrubbing-dependent buttons.
|
||||
bindScrubbingTime(mMediaData);
|
||||
SEMANTIC_ACTIONS_HIDE_WHEN_SCRUBBING.forEach((id) ->
|
||||
setSemanticButtonVisibleAndAlpha(id, semanticActions.getActionById(id)));
|
||||
setSemanticButtonVisibleAndAlpha(
|
||||
id, semanticActions.getActionById(id), semanticActions));
|
||||
// Trigger a state refresh so that we immediately update visibilities.
|
||||
mMediaViewController.refreshState();
|
||||
}
|
||||
@@ -802,7 +808,7 @@ public class MediaControlPanel {
|
||||
int elapsedTimeId = mMediaViewHolder.getScrubbingElapsedTimeView().getId();
|
||||
int totalTimeId = mMediaViewHolder.getScrubbingTotalTimeView().getId();
|
||||
|
||||
boolean visible = data.getSemanticActions() != null && mIsScrubbing;
|
||||
boolean visible = scrubbingTimeViewsEnabled(data.getSemanticActions()) && mIsScrubbing;
|
||||
setVisibleAndAlpha(expandedSet, elapsedTimeId, visible);
|
||||
setVisibleAndAlpha(expandedSet, totalTimeId, visible);
|
||||
// Never show in collapsed
|
||||
@@ -810,6 +816,14 @@ public class MediaControlPanel {
|
||||
setVisibleAndAlpha(collapsedSet, totalTimeId, false);
|
||||
}
|
||||
|
||||
private boolean scrubbingTimeViewsEnabled(@Nullable MediaButton semanticActions) {
|
||||
// The scrubbing time views replace the SEMANTIC_ACTIONS_HIDE_WHEN_SCRUBBING action views,
|
||||
// so we should only allow scrubbing times to be shown if those action views are present.
|
||||
return semanticActions != null && SEMANTIC_ACTIONS_HIDE_WHEN_SCRUBBING.stream().allMatch(
|
||||
id -> semanticActions.getActionById(id) != null
|
||||
);
|
||||
}
|
||||
|
||||
// AnimationBindHandler is responsible for tracking the bound animation state and preventing
|
||||
// jank and conflicts due to media notifications arriving at any time during an animation. It
|
||||
// does this in two parts.
|
||||
|
||||
@@ -413,10 +413,52 @@ public class MediaControlPanelTest : SysuiTestCase() {
|
||||
listener.onScrubbingChanged(true)
|
||||
mainExecutor.runAllReady()
|
||||
|
||||
verify(expandedSet, never()).setVisibility(eq(R.id.actionPrev), anyInt())
|
||||
verify(expandedSet, never()).setVisibility(eq(R.id.actionNext), anyInt())
|
||||
verify(expandedSet, never()).setVisibility(eq(R.id.media_scrubbing_elapsed_time), anyInt())
|
||||
verify(expandedSet, never()).setVisibility(eq(R.id.media_scrubbing_total_time), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setIsScrubbing_noPrevButton_scrubbingTimesNotShown() {
|
||||
val icon = context.getDrawable(android.R.drawable.ic_media_play)
|
||||
val semanticActions = MediaButton(
|
||||
prevOrCustom = null,
|
||||
nextOrCustom = MediaAction(icon, {}, "next", null),
|
||||
)
|
||||
val state = mediaData.copy(semanticActions = semanticActions)
|
||||
player.attachPlayer(viewHolder)
|
||||
player.bindPlayer(state, PACKAGE)
|
||||
reset(expandedSet)
|
||||
|
||||
getScrubbingChangeListener().onScrubbingChanged(true)
|
||||
mainExecutor.runAllReady()
|
||||
|
||||
verify(expandedSet).setVisibility(R.id.actionNext, View.VISIBLE)
|
||||
verify(expandedSet).setVisibility(R.id.media_scrubbing_elapsed_time, View.GONE)
|
||||
verify(expandedSet).setVisibility(R.id.media_scrubbing_total_time, View.GONE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setIsScrubbing_noNextButton_scrubbingTimesNotShown() {
|
||||
val icon = context.getDrawable(android.R.drawable.ic_media_play)
|
||||
val semanticActions = MediaButton(
|
||||
prevOrCustom = MediaAction(icon, {}, "prev", null),
|
||||
nextOrCustom = null,
|
||||
)
|
||||
val state = mediaData.copy(semanticActions = semanticActions)
|
||||
player.attachPlayer(viewHolder)
|
||||
player.bindPlayer(state, PACKAGE)
|
||||
reset(expandedSet)
|
||||
|
||||
getScrubbingChangeListener().onScrubbingChanged(true)
|
||||
mainExecutor.runAllReady()
|
||||
|
||||
verify(expandedSet).setVisibility(R.id.actionPrev, View.VISIBLE)
|
||||
verify(expandedSet).setVisibility(R.id.media_scrubbing_elapsed_time, View.GONE)
|
||||
verify(expandedSet).setVisibility(R.id.media_scrubbing_total_time, View.GONE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setIsScrubbing_true_scrubbingViewsShownAndPrevNextHiddenOnlyInExpanded() {
|
||||
val icon = context.getDrawable(android.R.drawable.ic_media_play)
|
||||
|
||||
Reference in New Issue
Block a user