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

Commit 78cae68f authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Android (Google) Code Review
Browse files

Merge "Update callbacks when media session has changed"

parents 02a118de d1eb0a8c
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -167,12 +167,6 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
        mContext = ctx;
        mMediaManager = Dependency.get(NotificationMediaManager.class);
        mMetricsLogger = Dependency.get(MetricsLogger.class);

        if (mView instanceof MediaNotificationView) {
            MediaNotificationView mediaView = (MediaNotificationView) mView;
            mediaView.addVisibilityListener(mVisibilityListener);
            mView.addOnAttachStateChangeListener(mAttachStateListener);
        }
    }

    private void resolveViews() {
@@ -213,13 +207,13 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
        }

        // Check for existing media controller and clean up / create as necessary
        boolean controllerUpdated = false;
        boolean shouldUpdateListeners = false;
        if (mMediaController == null || !mMediaController.getSessionToken().equals(token)) {
            if (mMediaController != null) {
                mMediaController.unregisterCallback(mMediaCallback);
            }
            mMediaController = new MediaController(mContext, token);
            controllerUpdated = true;
            shouldUpdateListeners = true;
        }

        mMediaMetadata = mMediaController.getMetadata();
@@ -231,7 +225,7 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
                    mSeekBarView.setVisibility(View.GONE);
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
                    clearTimer();
                } else if (mSeekBarView == null && controllerUpdated) {
                } else if (mSeekBarView == null && shouldUpdateListeners) {
                    // Only log if the controller changed, otherwise we would log multiple times for
                    // the same notification when user pauses/resumes
                    mMetricsLogger.write(newLog(MetricsEvent.TYPE_CLOSE));
@@ -261,6 +255,16 @@ public class NotificationMediaTemplateViewWrapper extends NotificationTemplateVi
            mSeekBarElapsedTime = mSeekBarView.findViewById(R.id.notification_media_elapsed_time);
            mSeekBarTotalTime = mSeekBarView.findViewById(R.id.notification_media_total_time);

            shouldUpdateListeners = true;
        }

        if (shouldUpdateListeners) {
            if (mView instanceof MediaNotificationView) {
                MediaNotificationView mediaView = (MediaNotificationView) mView;
                mediaView.addVisibilityListener(mVisibilityListener);
                mView.addOnAttachStateChangeListener(mAttachStateListener);
            }

            if (mSeekBarTimer == null) {
                if (mMediaController != null && canSeekMedia(mMediaController.getPlaybackState())) {
                    // Log initial state, since it will not be updated