Merge "Recreate the media recommendation card after the Display setting is changed." into sc-dev am: cb3cf0b9b6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14809510 Change-Id: I1db477116c821e2874f33b5aed5641fbdd2946bb
This commit is contained in:
@@ -367,7 +367,7 @@ class MediaCarouselController @Inject constructor(
|
|||||||
ViewGroup.LayoutParams.WRAP_CONTENT)
|
ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
newRecs.recommendationViewHolder?.recommendations?.setLayoutParams(lp)
|
newRecs.recommendationViewHolder?.recommendations?.setLayoutParams(lp)
|
||||||
newRecs.bindRecommendation(data.copy(backgroundColor = bgColor))
|
newRecs.bindRecommendation(data.copy(backgroundColor = bgColor))
|
||||||
MediaPlayerData.addMediaRecommendation(key, newRecs, shouldPrioritize)
|
MediaPlayerData.addMediaRecommendation(key, data, newRecs, shouldPrioritize)
|
||||||
updatePlayerToState(newRecs, noAnimation = true)
|
updatePlayerToState(newRecs, noAnimation = true)
|
||||||
reorderAllPlayers()
|
reorderAllPlayers()
|
||||||
updatePageIndicator()
|
updatePageIndicator()
|
||||||
@@ -408,9 +408,18 @@ class MediaCarouselController @Inject constructor(
|
|||||||
bgColor = getBackgroundColor()
|
bgColor = getBackgroundColor()
|
||||||
pageIndicator.tintList = ColorStateList.valueOf(getForegroundColor())
|
pageIndicator.tintList = ColorStateList.valueOf(getForegroundColor())
|
||||||
|
|
||||||
MediaPlayerData.mediaData().forEach { (key, data) ->
|
MediaPlayerData.mediaData().forEach { (key, data, isSsMediaRec) ->
|
||||||
removePlayer(key, dismissMediaData = false, dismissRecommendation = false)
|
if (isSsMediaRec) {
|
||||||
addOrUpdatePlayer(key = key, oldKey = null, data = data)
|
val smartspaceMediaData = MediaPlayerData.smartspaceMediaData
|
||||||
|
removePlayer(key, dismissMediaData = false, dismissRecommendation = false)
|
||||||
|
smartspaceMediaData?.let {
|
||||||
|
addSmartspaceMediaRecommendations(
|
||||||
|
it.targetId, it, MediaPlayerData.shouldPrioritizeSs)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
removePlayer(key, dismissMediaData = false, dismissRecommendation = false)
|
||||||
|
addOrUpdatePlayer(key = key, oldKey = null, data = data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -697,7 +706,10 @@ internal object MediaPlayerData {
|
|||||||
private val EMPTY = MediaData(-1, false, 0, null, null, null, null, null,
|
private val EMPTY = MediaData(-1, false, 0, null, null, null, null, null,
|
||||||
emptyList(), emptyList(), "INVALID", null, null, null, true, null)
|
emptyList(), emptyList(), "INVALID", null, null, null, true, null)
|
||||||
// Whether should prioritize Smartspace card.
|
// Whether should prioritize Smartspace card.
|
||||||
private var shouldPrioritizeSs: Boolean = false
|
internal var shouldPrioritizeSs: Boolean = false
|
||||||
|
private set
|
||||||
|
internal var smartspaceMediaData: SmartspaceMediaData? = null
|
||||||
|
private set
|
||||||
|
|
||||||
data class MediaSortKey(
|
data class MediaSortKey(
|
||||||
// Whether the item represents a Smartspace media recommendation.
|
// Whether the item represents a Smartspace media recommendation.
|
||||||
@@ -724,12 +736,18 @@ internal object MediaPlayerData {
|
|||||||
mediaPlayers.put(sortKey, player)
|
mediaPlayers.put(sortKey, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addMediaRecommendation(key: String, player: MediaControlPanel, shouldPrioritize: Boolean) {
|
fun addMediaRecommendation(
|
||||||
|
key: String,
|
||||||
|
data: SmartspaceMediaData,
|
||||||
|
player: MediaControlPanel,
|
||||||
|
shouldPrioritize: Boolean
|
||||||
|
) {
|
||||||
shouldPrioritizeSs = shouldPrioritize
|
shouldPrioritizeSs = shouldPrioritize
|
||||||
removeMediaPlayer(key)
|
removeMediaPlayer(key)
|
||||||
val sortKey = MediaSortKey(isSsMediaRec = true, EMPTY, System.currentTimeMillis())
|
val sortKey = MediaSortKey(isSsMediaRec = true, EMPTY, System.currentTimeMillis())
|
||||||
mediaData.put(key, sortKey)
|
mediaData.put(key, sortKey)
|
||||||
mediaPlayers.put(sortKey, player)
|
mediaPlayers.put(sortKey, player)
|
||||||
|
smartspaceMediaData = data
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMediaPlayer(key: String, oldKey: String?): MediaControlPanel? {
|
fun getMediaPlayer(key: String, oldKey: String?): MediaControlPanel? {
|
||||||
@@ -742,9 +760,14 @@ internal object MediaPlayerData {
|
|||||||
return mediaData.get(key)?.let { mediaPlayers.get(it) }
|
return mediaData.get(key)?.let { mediaPlayers.get(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeMediaPlayer(key: String) = mediaData.remove(key)?.let { mediaPlayers.remove(it) }
|
fun removeMediaPlayer(key: String) = mediaData.remove(key)?.let {
|
||||||
|
if (it.isSsMediaRec) {
|
||||||
|
smartspaceMediaData = null
|
||||||
|
}
|
||||||
|
mediaPlayers.remove(it)
|
||||||
|
}
|
||||||
|
|
||||||
fun mediaData() = mediaData.entries.map { e -> Pair(e.key, e.value.data) }
|
fun mediaData() = mediaData.entries.map { e -> Triple(e.key, e.value.data, e.value.isSsMediaRec) }
|
||||||
|
|
||||||
fun players() = mediaPlayers.values
|
fun players() = mediaPlayers.values
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user