From 24bdaa4f08953c19417acd5b75b9f6345daa1ba8 Mon Sep 17 00:00:00 2001 From: cecilia Date: Fri, 7 May 2021 19:20:00 -0400 Subject: [PATCH] [BugFix] Automatically slide to the active player each time tapping a media recommendation. Before the fix, the slide only happens once on the first tap, and it's because #reorderAllPlayers is not always called on only updating the player. Bug: 186786793 Test: Local builds Change-Id: Ia74321de6e4ca1715bcc9f6c82c2edeebff662be --- .../systemui/media/MediaCarouselController.kt | 10 +++++----- .../systemui/media/MediaControlPanel.java | 18 +++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt index 7fe88e5166e8c..816cf6160c464 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt @@ -115,7 +115,7 @@ class MediaCarouselController @Inject constructor( private var needsReordering: Boolean = false private var keysNeedRemoval = mutableSetOf() private var bgColor = getBackgroundColor() - private var shouldScrollToActivePlayer: Boolean = false + protected var shouldScrollToActivePlayer: Boolean = false private var isRtl: Boolean = false set(value) { if (value != field) { @@ -309,7 +309,7 @@ class MediaCarouselController @Inject constructor( } else { existingPlayer.bindPlayer(dataCopy, key) MediaPlayerData.addMediaPlayer(key, dataCopy, existingPlayer) - if (visualStabilityManager.isReorderingAllowed) { + if (visualStabilityManager.isReorderingAllowed || shouldScrollToActivePlayer) { reorderAllPlayers() } else { needsReordering = true @@ -340,7 +340,7 @@ class MediaCarouselController @Inject constructor( val lp = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) newRecs.recommendationViewHolder?.recommendations?.setLayoutParams(lp) - newRecs.bindRecommendation(data, bgColor, { v -> shouldScrollToActivePlayer = true }) + newRecs.bindRecommendation(data, bgColor) MediaPlayerData.addMediaRecommendation(key, newRecs) updatePlayerToState(newRecs, noAnimation = true) reorderAllPlayers() @@ -656,7 +656,7 @@ class MediaCarouselController @Inject constructor( @VisibleForTesting internal object MediaPlayerData { private val EMPTY = MediaData(-1, false, 0, null, null, null, null, null, - emptyList(), emptyList(), "INVALID", null, null, null, false, null) + emptyList(), emptyList(), "INVALID", null, null, null, true, null) data class MediaSortKey( // Is Smartspace media recommendation. When the Smartspace media is present, it should @@ -709,7 +709,7 @@ internal object MediaPlayerData { /** Returns the index of the first non-timeout media. */ fun getActiveMediaIndex(): Int { mediaPlayers.entries.forEachIndexed { index, e -> - if (e.key.data.active) { + if (!e.key.isSsMediaRec && e.key.data.active) { return index } } diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index b3ebed1fe6a9f..7514c19375a7a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -472,10 +472,7 @@ public class MediaControlPanel { } /** Bind this recommendation view based on the data given. */ - public void bindRecommendation( - @NonNull SmartspaceTarget target, - @NonNull int backgroundColor, - @Nullable View.OnClickListener callback) { + public void bindRecommendation(@NonNull SmartspaceTarget target, @NonNull int backgroundColor) { if (mRecommendationViewHolder == null) { return; } @@ -536,10 +533,7 @@ public class MediaControlPanel { mediaCoverImageView.setImageIcon(recommendation.getIcon()); // Set up the click listener if applicable. - setSmartspaceRecItemOnClickListener( - mediaCoverImageView, - recommendation, - callback); + setSmartspaceRecItemOnClickListener(mediaCoverImageView, recommendation); if (uiComponentIndex < MEDIA_RECOMMENDATION_ITEMS_PER_ROW) { setVisibleAndAlpha(collapsedSet, @@ -658,8 +652,7 @@ public class MediaControlPanel { private void setSmartspaceRecItemOnClickListener( @NonNull View view, - @NonNull SmartspaceAction action, - @Nullable View.OnClickListener callback) { + @NonNull SmartspaceAction action) { if (view == null || action == null || action.getIntent() == null) { Log.e(TAG, "No tap action can be set up"); return; @@ -682,9 +675,8 @@ public class MediaControlPanel { view.getContext().startActivity(action.getIntent()); } - if (callback != null) { - callback.onClick(v); - } + // Automatically scroll to the active player once the media is loaded. + mMediaCarouselController.setShouldScrollToActivePlayer(true); }); }