Init MediaHost with KeyguardMediaController's initialization, not wait until the controller is attached.
This fixes the bug where media control doesn't show on lock screen. This is because the instance of MediaHost being added as MediaDataManager.Listener is not the same instance the KeyguardMediaController holds. Init media host during the controller's initialization instead of attach fixes this issue. Fixes: 185510540 Test: Studio builds Change-Id: I821b97efe0558c09dcab4497e5043c744d82a9e1
This commit is contained in:
@@ -54,6 +54,14 @@ class KeyguardMediaController @Inject constructor(
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// First let's set the desired state that we want for this host
|
||||
mediaHost.expansion = MediaHostState.COLLAPSED
|
||||
mediaHost.showsOnlyActiveMedia = true
|
||||
mediaHost.falsingProtectionNeeded = true
|
||||
|
||||
// Let's now initialize this view, which also creates the host view for us.
|
||||
mediaHost.init(MediaHierarchyManager.LOCATION_LOCKSCREEN)
|
||||
}
|
||||
|
||||
var visibilityChangedListener: ((Boolean) -> Unit)? = null
|
||||
@@ -71,13 +79,7 @@ class KeyguardMediaController @Inject constructor(
|
||||
*/
|
||||
fun attachSinglePaneContainer(mediaView: MediaHeaderView?) {
|
||||
singlePaneContainer = mediaView
|
||||
// First let's set the desired state that we want for this host
|
||||
mediaHost.expansion = MediaHostState.COLLAPSED
|
||||
mediaHost.showsOnlyActiveMedia = true
|
||||
mediaHost.falsingProtectionNeeded = true
|
||||
|
||||
// Let's now initialize this view, which also creates the host view for us.
|
||||
mediaHost.init(MediaHierarchyManager.LOCATION_LOCKSCREEN)
|
||||
// Required to show it for the first time, afterwards visibility is managed automatically
|
||||
mediaHost.visible = true
|
||||
mediaHost.addVisibilityChangeListener { visible ->
|
||||
@@ -133,6 +135,10 @@ class KeyguardMediaController @Inject constructor(
|
||||
}
|
||||
// might be called a few times for the same view, no need to add hostView again
|
||||
if (activeContainer?.childCount == 0) {
|
||||
// Detach the hostView from its parent view if exists
|
||||
mediaHost.hostView.parent ?.let {
|
||||
(it as? ViewGroup)?.removeView(mediaHost.hostView)
|
||||
}
|
||||
activeContainer.addView(mediaHost.hostView)
|
||||
}
|
||||
setVisibility(activeContainer, View.VISIBLE)
|
||||
|
||||
@@ -25,6 +25,8 @@ class MediaHost constructor(
|
||||
|
||||
private val tmpLocationOnScreen: IntArray = intArrayOf(0, 0)
|
||||
|
||||
private var inited: Boolean = false
|
||||
|
||||
/**
|
||||
* Get the current bounds on the screen. This makes sure the state is fresh and up to date
|
||||
*/
|
||||
@@ -84,6 +86,11 @@ class MediaHost constructor(
|
||||
* transitions.
|
||||
*/
|
||||
fun init(@MediaLocation location: Int) {
|
||||
if (inited) {
|
||||
return
|
||||
}
|
||||
inited = true
|
||||
|
||||
this.location = location
|
||||
hostView = mediaHierarchyManager.register(this)
|
||||
hostView.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
|
||||
|
||||
Reference in New Issue
Block a user