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

Commit f9c2af71 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media] Simplify how we get the background color for the media player.

The color was being passed down all the way from MediaDataManager to
ColorSchemeTransition when it doesn't need to be. This moves the
background color fetch to ColorSchemeTransition, which groups it with
all the other color fetching.

Bug: 228960370
Test: atest SystemUITests
Test: manual: verify media player still looks good
Change-Id: I0a542fd68847b942c3cb1e3c4576344068a06a07
parent f6453bc3
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -85,12 +85,13 @@ typealias ColorTransitionFactory = (Int, (ColorScheme) -> Int, (Int) -> Unit) ->
 */
class ColorSchemeTransition internal constructor(
    private val context: Context,
    bgColor: Int,
    mediaViewHolder: MediaViewHolder,
    colorTransitionFactory: ColorTransitionFactory
) {
    constructor(context: Context, bgColor: Int, mediaViewHolder: MediaViewHolder) :
        this(context, bgColor, mediaViewHolder, ::ColorTransition)
    constructor(context: Context, mediaViewHolder: MediaViewHolder) :
        this(context, mediaViewHolder, ::ColorTransition)

    val bgColor = context.getColor(com.android.systemui.R.color.material_dynamic_secondary95)

    val surfaceColor = colorTransitionFactory(
        bgColor,
+0 −1
Original line number Diff line number Diff line
@@ -904,7 +904,6 @@ internal object MediaPlayerData {
    private val EMPTY = MediaData(
            userId = -1,
            initialized = false,
            backgroundColor = 0,
            app = null,
            appIcon = null,
            artist = null,
+4 −7
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@ public class MediaControlPanel {
    private MediaSession.Token mToken;
    private MediaController mController;
    private Lazy<MediaDataManager> mMediaDataManagerLazy;
    private int mBackgroundColor;
    // Uid for the media app.
    protected int mUid = Process.INVALID_UID;
    private int mSmartspaceMediaItemsCount;
@@ -343,8 +342,7 @@ public class MediaControlPanel {
        AnimatorSet exit = loadAnimator(R.anim.media_metadata_exit,
                Interpolators.EMPHASIZED_ACCELERATE, titleText, artistText);

        mColorSchemeTransition = new ColorSchemeTransition(
            mContext, mBackgroundColor, mMediaViewHolder);
        mColorSchemeTransition = new ColorSchemeTransition(mContext, mMediaViewHolder);
        mMetadataAnimationHandler = new MetadataAnimationHandler(exit, enter);
    }

@@ -409,7 +407,6 @@ public class MediaControlPanel {
        }
        mInstanceId = data.getInstanceId();

        mBackgroundColor = data.getBackgroundColor();
        if (mToken == null || !mToken.equals(token)) {
            mToken = token;
        }
@@ -485,7 +482,7 @@ public class MediaControlPanel {
            Drawable icon = device.getIcon();
            if (icon instanceof AdaptiveIcon) {
                AdaptiveIcon aIcon = (AdaptiveIcon) icon;
                aIcon.setBackgroundColor(mBackgroundColor);
                aIcon.setBackgroundColor(mColorSchemeTransition.getBgColor());
                iconView.setImageDrawable(aIcon);
            } else {
                iconView.setImageDrawable(icon);
@@ -956,11 +953,11 @@ public class MediaControlPanel {
        }

        mSmartspaceId = SmallHash.hash(data.getTargetId());
        mBackgroundColor = data.getBackgroundColor();
        int backgroundColor = data.getBackgroundColor();
        mPackageName = data.getPackageName();
        mInstanceId = data.getInstanceId();
        TransitionLayout recommendationCard = mRecommendationViewHolder.getRecommendations();
        recommendationCard.setBackgroundTintList(ColorStateList.valueOf(mBackgroundColor));
        recommendationCard.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));

        List<SmartspaceAction> mediaRecommendationList = data.getRecommendations();
        if (mediaRecommendationList == null || mediaRecommendationList.isEmpty()) {
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import com.android.systemui.R
data class MediaData(
    val userId: Int,
    val initialized: Boolean = false,
    val backgroundColor: Int,
    /**
     * App name that will be displayed on the player.
     */
+2 −4
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ private const val EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY = "dismiss_intent"
private val LOADING = MediaData(
        userId = -1,
        initialized = false,
        backgroundColor = 0,
        app = null,
        appIcon = null,
        artist = null,
@@ -177,7 +176,6 @@ class MediaDataManager(

    private val themeText = com.android.settingslib.Utils.getColorAttr(context,
            com.android.internal.R.attr.textColorPrimary).defaultColor
    private val bgColor = context.getColor(R.color.material_dynamic_secondary95)

    // Internal listeners are part of the internal pipeline. External listeners (those registered
    // with [MediaDeviceManager.addListener]) receive events after they have propagated through
@@ -591,7 +589,7 @@ class MediaDataManager(
        val mediaAction = getResumeMediaAction(resumeAction)
        val lastActive = systemClock.elapsedRealtime()
        foregroundExecutor.execute {
            onMediaDataLoaded(packageName, null, MediaData(userId, true, bgColor, appName,
            onMediaDataLoaded(packageName, null, MediaData(userId, true, appName,
                    null, desc.subtitle, desc.title, artworkIcon, listOf(mediaAction), listOf(0),
                    MediaButton(playOrPause = mediaAction), packageName, token, appIntent,
                    device = null, active = false,
@@ -713,7 +711,7 @@ class MediaDataManager(
            val resumeAction: Runnable? = mediaEntries[key]?.resumeAction
            val hasCheckedForResume = mediaEntries[key]?.hasCheckedForResume == true
            val active = mediaEntries[key]?.active ?: true
            onMediaDataLoaded(key, oldKey, MediaData(sbn.normalizedUserId, true, bgColor, app,
            onMediaDataLoaded(key, oldKey, MediaData(sbn.normalizedUserId, true, app,
                    smallIcon, artist, song, artWorkIcon, actionIcons, actionsToShowCollapsed,
                    semanticActions, sbn.packageName, token, notif.contentIntent, device,
                    active, resumeAction = resumeAction, playbackLocation = playbackLocation,
Loading