diff options
| author | 2020-04-27 19:02:06 -0700 | |
|---|---|---|
| committer | 2020-05-08 22:23:32 -0700 | |
| commit | 098baf4dd92a94d17445981862079b1ed796b622 (patch) | |
| tree | db9eafc56f173aa8618d21d73b9925a6d6941bdf | |
| parent | c54367124cd59746c260197bb9dfe830484c97b2 (diff) | |
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
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java | 32 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt | 1 |
2 files changed, 8 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index 6621ca13583c..5a5cd6dc3a50 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -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)); diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt index 2e41ffb24960..e584cccb24e2 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt @@ -133,6 +133,7 @@ class MediaHierarchyManager @Inject constructor( val removed = mediaPlayers.remove(key) removed?.apply { mediaContent.removeView(removed.view) + removed.onDestroy() } } }) |