Merge "Reorder media players when orientation changes" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b4abaa6b07
@@ -184,6 +184,7 @@ constructor(
|
|||||||
|
|
||||||
private val configListener =
|
private val configListener =
|
||||||
object : ConfigurationController.ConfigurationListener {
|
object : ConfigurationController.ConfigurationListener {
|
||||||
|
var lastOrientation = -1
|
||||||
|
|
||||||
override fun onDensityOrFontScaleChanged() {
|
override fun onDensityOrFontScaleChanged() {
|
||||||
// System font changes should only happen when UMO is offscreen or a flicker may
|
// System font changes should only happen when UMO is offscreen or a flicker may
|
||||||
@@ -200,7 +201,13 @@ constructor(
|
|||||||
override fun onConfigChanged(newConfig: Configuration?) {
|
override fun onConfigChanged(newConfig: Configuration?) {
|
||||||
if (newConfig == null) return
|
if (newConfig == null) return
|
||||||
isRtl = newConfig.layoutDirection == View.LAYOUT_DIRECTION_RTL
|
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() {
|
override fun onUiModeChanged() {
|
||||||
@@ -717,6 +724,9 @@ constructor(
|
|||||||
private fun updatePlayers(recreateMedia: Boolean) {
|
private fun updatePlayers(recreateMedia: Boolean) {
|
||||||
pageIndicator.tintList =
|
pageIndicator.tintList =
|
||||||
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
|
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
|
||||||
|
val previousVisibleKey =
|
||||||
|
MediaPlayerData.visiblePlayerKeys()
|
||||||
|
.elementAtOrNull(mediaCarouselScrollHandler.visibleMediaIndex)
|
||||||
|
|
||||||
MediaPlayerData.mediaData().forEach { (key, data, isSsMediaRec) ->
|
MediaPlayerData.mediaData().forEach { (key, data, isSsMediaRec) ->
|
||||||
if (isSsMediaRec) {
|
if (isSsMediaRec) {
|
||||||
@@ -741,6 +751,9 @@ constructor(
|
|||||||
isSsReactivated = isSsReactivated
|
isSsReactivated = isSsReactivated
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (recreateMedia) {
|
||||||
|
reorderAllPlayers(previousVisibleKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.systemui.media.controls.ui
|
package com.android.systemui.media.controls.ui
|
||||||
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.testing.AndroidTestingRunner
|
import android.testing.AndroidTestingRunner
|
||||||
import android.testing.TestableLooper
|
import android.testing.TestableLooper
|
||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
@@ -86,6 +87,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
|||||||
@Mock lateinit var mediaViewController: MediaViewController
|
@Mock lateinit var mediaViewController: MediaViewController
|
||||||
@Mock lateinit var smartspaceMediaData: SmartspaceMediaData
|
@Mock lateinit var smartspaceMediaData: SmartspaceMediaData
|
||||||
@Captor lateinit var listener: ArgumentCaptor<MediaDataManager.Listener>
|
@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>
|
@Captor lateinit var visualStabilityCallback: ArgumentCaptor<OnReorderingAllowedListener>
|
||||||
|
|
||||||
private val clock = FakeSystemClock()
|
private val clock = FakeSystemClock()
|
||||||
@@ -111,6 +115,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
|||||||
logger,
|
logger,
|
||||||
debugLogger
|
debugLogger
|
||||||
)
|
)
|
||||||
|
verify(configurationController).addCallback(capture(configListener))
|
||||||
verify(mediaDataManager).addListener(capture(listener))
|
verify(mediaDataManager).addListener(capture(listener))
|
||||||
verify(visualStabilityProvider)
|
verify(visualStabilityProvider)
|
||||||
.addPersistentReorderingAllowedListener(capture(visualStabilityCallback))
|
.addPersistentReorderingAllowedListener(capture(visualStabilityCallback))
|
||||||
@@ -662,4 +667,39 @@ class MediaCarouselControllerTest : SysuiTestCase() {
|
|||||||
mediaCarouselController.updatePageIndicatorAlpha()
|
mediaCarouselController.updatePageIndicatorAlpha()
|
||||||
assertEquals(mediaCarouselController.pageIndicator.alpha, 1.0F, delta)
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user