Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24bdaa4f authored by cecilia's avatar cecilia Committed by Cecilia Hong
Browse files

[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
parent 8093fd20
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ class MediaCarouselController @Inject constructor(
    private var needsReordering: Boolean = false
    private var keysNeedRemoval = mutableSetOf<String>()
    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
            }
        }
+5 −13
Original line number Diff line number Diff line
@@ -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);
        });
    }