diff options
| author | 2020-06-17 22:35:32 +0000 | |
|---|---|---|
| committer | 2020-06-17 22:35:32 +0000 | |
| commit | 6555251f20bc0ef40880e83d305b18f79758db3c (patch) | |
| tree | 07a141dcc34ec4ddfb65ece315e3bc4120903c7b | |
| parent | 09e4a6cff6338597ec5e69fad046be4090b30f6c (diff) | |
| parent | 764eded5ad93194920636f132bcad258a0aa3782 (diff) | |
Merge "Recreate players when density or font changes" into rvc-dev am: 2afb0dad2d am: 398572cae7 am: 189ceafb02 am: 764eded5ad
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11852488
Change-Id: I9300c521b8415b5de5901ec05f08ebc6977f3b35
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt index 9b9a6b4b13ab..bccc3abd8a27 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt @@ -13,6 +13,7 @@ import androidx.core.view.GestureDetectorCompat import com.android.systemui.R import com.android.systemui.qs.PageIndicator import com.android.systemui.statusbar.notification.VisualStabilityManager +import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.util.animation.UniqueObjectHostView import com.android.systemui.util.animation.requiresRemeasuring import javax.inject.Inject @@ -31,7 +32,8 @@ class MediaViewManager @Inject constructor( private val mediaControlPanelFactory: Provider<MediaControlPanel>, private val visualStabilityManager: VisualStabilityManager, private val mediaHostStatesManager: MediaHostStatesManager, - mediaManager: MediaDataCombineLatest + mediaManager: MediaDataCombineLatest, + configurationController: ConfigurationController ) { /** @@ -74,6 +76,7 @@ class MediaViewManager @Inject constructor( private val mediaCarousel: HorizontalScrollView val mediaFrame: ViewGroup val mediaPlayers: MutableMap<String, MediaControlPanel> = mutableMapOf() + private val mediaData: MutableMap<String, MediaData> = mutableMapOf() private val mediaContent: ViewGroup private val pageIndicator: PageIndicator private val gestureDetector: GestureDetectorCompat @@ -120,6 +123,11 @@ class MediaViewManager @Inject constructor( return this@MediaViewManager.onTouch(view, motionEvent) } } + private val configListener = object : ConfigurationController.ConfigurationListener { + override fun onDensityOrFontScaleChanged() { + recreatePlayers() + } + } init { gestureDetector = GestureDetectorCompat(context, gestureListener) @@ -130,6 +138,7 @@ class MediaViewManager @Inject constructor( mediaCarousel.setOnTouchListener(touchListener) mediaCarousel.setOverScrollMode(View.OVER_SCROLL_NEVER) mediaContent = mediaCarousel.requireViewById(R.id.media_carousel) + configurationController.addCallback(configListener) visualStabilityCallback = VisualStabilityManager.Callback { if (needsReordering) { needsReordering = false @@ -142,29 +151,14 @@ class MediaViewManager @Inject constructor( true /* persistent */) mediaManager.addListener(object : MediaDataManager.Listener { override fun onMediaDataLoaded(key: String, oldKey: String?, data: MediaData) { - updateView(key, oldKey, data) - updatePlayerVisibilities() - mediaCarousel.requiresRemeasuring = true + oldKey?.let { mediaData.remove(it) } + mediaData.put(key, data) + addOrUpdatePlayer(key, oldKey, data) } override fun onMediaDataRemoved(key: String) { - val removed = mediaPlayers.remove(key) - removed?.apply { - val beforeActive = mediaContent.indexOfChild(removed.view?.player) <= - activeMediaIndex - mediaContent.removeView(removed.view?.player) - removed.onDestroy() - updateMediaPaddings() - if (beforeActive) { - // also update the index here since the scroll below might not always lead - // to a scrolling changed - activeMediaIndex = Math.max(0, activeMediaIndex - 1) - mediaCarousel.scrollX = Math.max(mediaCarousel.scrollX - - playerWidthPlusPadding, 0) - } - updatePlayerVisibilities() - updatePageIndicator() - } + mediaData.remove(key) + removePlayer(key) } }) mediaHostStatesManager.addCallback(object : MediaHostStatesManager.Callback { @@ -253,7 +247,7 @@ class MediaViewManager @Inject constructor( } } - private fun updateView(key: String, oldKey: String?, data: MediaData) { + private fun addOrUpdatePlayer(key: String, oldKey: String?, data: MediaData) { // If the key was changed, update entry val oldData = mediaPlayers[oldKey] if (oldData != null) { @@ -288,6 +282,39 @@ class MediaViewManager @Inject constructor( existingPlayer?.bind(data) updateMediaPaddings() updatePageIndicator() + updatePlayerVisibilities() + mediaCarousel.requiresRemeasuring = true + } + + private fun removePlayer(key: String) { + val removed = mediaPlayers.remove(key) + removed?.apply { + val beforeActive = mediaContent.indexOfChild(removed.view?.player) <= + activeMediaIndex + mediaContent.removeView(removed.view?.player) + removed.onDestroy() + updateMediaPaddings() + if (beforeActive) { + // also update the index here since the scroll below might not always lead + // to a scrolling changed + activeMediaIndex = Math.max(0, activeMediaIndex - 1) + mediaCarousel.scrollX = Math.max(mediaCarousel.scrollX - + playerWidthPlusPadding, 0) + } + updatePlayerVisibilities() + updatePageIndicator() + } + } + + private fun recreatePlayers() { + // Note that this will scramble the order of players. Actively playing sessions will, at + // least, still be put in the front. If we want to maintain order, then more work is + // needed. + mediaData.forEach { + key, data -> + removePlayer(key) + addOrUpdatePlayer(key = key, oldKey = null, data = data) + } } private fun updateMediaPaddings() { |