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

Commit 098baf4d authored by Selim Cinek's avatar Selim Cinek
Browse files

Migrated away from view detaching as a signal

Previously the seekbar update stopped pretty much
immediately since the Lifecycle was set to destroyed
whenever detatched.
We're now listening whenever a view exists.
Similarly, were we making the view inactive whenever
reattaching, which happens constantly now

Test: add any player, observe progress bar updating
Bug: 154137987
Change-Id: I5bac0822ceb282999db35c797d7355127b1daf31
parent c5436712
Loading
Loading
Loading
Loading
+7 −25
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.media;

import static com.android.systemui.util.SysuiLifecycle.viewAttachLifecycle;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
@@ -41,7 +39,6 @@ import android.service.media.MediaBrowserService;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -139,17 +136,6 @@ public class MediaControlPanel {
        }
    };

    private final OnAttachStateChangeListener mStateListener = new OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View unused) {
            makeActive();
        }
        @Override
        public void onViewDetachedFromWindow(View unused) {
            makeInactive();
        }
    };

    private final LocalMediaManager.DeviceCallback mDeviceCallback =
            new LocalMediaManager.DeviceCallback() {
        @Override
@@ -191,29 +177,25 @@ public class MediaControlPanel {
        mMediaNotifView = (MotionLayout) inflater.inflate(R.layout.qs_media_panel, parent, false);
        mBackground = mMediaNotifView.findViewById(R.id.media_background);
        mKeyFrames = mMediaNotifView.getDefinedTransitions().get(0).getKeyFrameList();
        // TODO(b/150854549): removeOnAttachStateChangeListener when this doesn't inflate views
        // mStateListener shouldn't need to be unregistered since this object shares the same
        // lifecycle with the inflated view. It would be better, however, if this controller used an
        // attach/detach of views instead of inflating them in the constructor, which would allow
        // mStateListener to be unregistered in detach.
        mMediaNotifView.addOnAttachStateChangeListener(mStateListener);
        mLocalMediaManager = routeManager;
        mForegroundExecutor = foregroundExecutor;
        mBackgroundExecutor = backgroundExecutor;
        mActivityStarter = activityStarter;
        mSeekBarViewModel = new SeekBarViewModel(backgroundExecutor);
        mSeekBarObserver = new SeekBarObserver(getView());
        // Can't use the viewAttachLifecycle of media player because remove/add is used to adjust
        // priority of players. As soon as it is removed, the lifecycle will end and the seek bar
        // will stop updating. So, use the lifecycle of the parent instead.
        // TODO: this parent is also detached, need to fix that
        mSeekBarViewModel.getProgress().observe(viewAttachLifecycle(parent), mSeekBarObserver);
        // TODO: we should pause this whenever the screen is off / panel is collapsed etc.
        mSeekBarViewModel.getProgress().observeForever(mSeekBarObserver);
        SeekBar bar = getView().findViewById(R.id.media_progress_bar);
        bar.setOnSeekBarChangeListener(mSeekBarViewModel.getSeekBarListener());
        bar.setOnTouchListener(mSeekBarViewModel.getSeekBarTouchListener());
        loadDimens();
    }

    public void onDestroy() {
        mSeekBarViewModel.getProgress().removeObserver(mSeekBarObserver);
        makeInactive();
    }

    private void loadDimens() {
        mAlbumArtRadius = mContext.getResources().getDimensionPixelSize(
                Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius));
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ class MediaHierarchyManager @Inject constructor(
                val removed = mediaPlayers.remove(key)
                removed?.apply {
                    mediaContent.removeView(removed.view)
                    removed.onDestroy()
                }
            }
        })