summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Mikhail <michaelmikhil@google.com> 2022-12-16 21:05:02 +0000
committer Michael Mikhail <michaelmikhil@google.com> 2023-01-05 17:58:59 +0000
commitd16af9ee11b11f6ab1bbce0114b7cf8732118a04 (patch)
treec2b660d1dd0a431262c4681c297e6a6e6822418f
parentbc2a65562efeace2f98e178faba1a9053b3324b3 (diff)
Reorder media players when orientation changes
makes sure we only update players if orientation changes not all configs. And reorder players to make them available in the UI. Fixes: 261592246 Bug: 261695345 Test: atest MediaCarouselControllerTest Test: manual - check the UMO exists on switching orientation Change-Id: Ieb3ab97b747cb21e51ca42b8e9e56cb611b0d3d8
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt40
2 files changed, 54 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
index 1fdbc99333cb..d5558b27ef1a 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
@@ -184,6 +184,7 @@ constructor(
private val configListener =
object : ConfigurationController.ConfigurationListener {
+ var lastOrientation = -1
override fun onDensityOrFontScaleChanged() {
// System font changes should only happen when UMO is offscreen or a flicker may
@@ -200,7 +201,13 @@ constructor(
override fun onConfigChanged(newConfig: Configuration?) {
if (newConfig == null) return
isRtl = newConfig.layoutDirection == View.LAYOUT_DIRECTION_RTL
- updatePlayers(recreateMedia = true)
+ val newOrientation = newConfig.orientation
+ if (lastOrientation != newOrientation) {
+ // The players actually depend on the orientation possibly, so we have to
+ // recreate them (at least on large screen devices)
+ lastOrientation = newOrientation
+ updatePlayers(recreateMedia = true)
+ }
}
override fun onUiModeChanged() {
@@ -717,6 +724,9 @@ constructor(
private fun updatePlayers(recreateMedia: Boolean) {
pageIndicator.tintList =
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
+ val previousVisibleKey =
+ MediaPlayerData.visiblePlayerKeys()
+ .elementAtOrNull(mediaCarouselScrollHandler.visibleMediaIndex)
MediaPlayerData.mediaData().forEach { (key, data, isSsMediaRec) ->
if (isSsMediaRec) {
@@ -741,6 +751,9 @@ constructor(
isSsReactivated = isSsReactivated
)
}
+ if (recreateMedia) {
+ reorderAllPlayers(previousVisibleKey)
+ }
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
index 6ca34e0bb7ce..039dd4d92eb4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
@@ -17,6 +17,7 @@
package com.android.systemui.media.controls.ui
import android.app.PendingIntent
+import android.content.res.Configuration
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import androidx.test.filters.SmallTest
@@ -86,6 +87,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
@Mock lateinit var mediaViewController: MediaViewController
@Mock lateinit var smartspaceMediaData: SmartspaceMediaData
@Captor lateinit var listener: ArgumentCaptor<MediaDataManager.Listener>
+ @Captor
+ lateinit var configListener: ArgumentCaptor<ConfigurationController.ConfigurationListener>
+ @Captor lateinit var newConfig: ArgumentCaptor<Configuration>
@Captor lateinit var visualStabilityCallback: ArgumentCaptor<OnReorderingAllowedListener>
private val clock = FakeSystemClock()
@@ -111,6 +115,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
logger,
debugLogger
)
+ verify(configurationController).addCallback(capture(configListener))
verify(mediaDataManager).addListener(capture(listener))
verify(visualStabilityProvider)
.addPersistentReorderingAllowedListener(capture(visualStabilityCallback))
@@ -662,4 +667,39 @@ class MediaCarouselControllerTest : SysuiTestCase() {
mediaCarouselController.updatePageIndicatorAlpha()
assertEquals(mediaCarouselController.pageIndicator.alpha, 1.0F, delta)
}
+
+ @Ignore("b/253229241")
+ @Test
+ fun testOnConfigChanged_playersAreAddedBack() {
+ listener.value.onMediaDataLoaded(
+ "playing local",
+ null,
+ DATA.copy(
+ active = true,
+ isPlaying = true,
+ playbackLocation = MediaData.PLAYBACK_LOCAL,
+ resumption = false
+ )
+ )
+ listener.value.onMediaDataLoaded(
+ "paused local",
+ null,
+ DATA.copy(
+ active = true,
+ isPlaying = false,
+ playbackLocation = MediaData.PLAYBACK_LOCAL,
+ resumption = false
+ )
+ )
+
+ val playersSize = MediaPlayerData.players().size
+
+ configListener.value.onConfigChanged(capture(newConfig))
+
+ assertEquals(playersSize, MediaPlayerData.players().size)
+ assertEquals(
+ MediaPlayerData.getMediaPlayerIndex("playing local"),
+ mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
+ )
+ }
}