Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8b8f862 authored by Cecilia Hong's avatar Cecilia Hong Committed by Android (Google) Code Review
Browse files

Merge "Init MediaHost with KeyguardMediaController's initialization, not wait...

Merge "Init MediaHost with KeyguardMediaController's initialization, not wait until the controller is attached." into sc-dev
parents 0d2ddfb7 4195d87b
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -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
    var visibilityChangedListener: ((Boolean) -> Unit)? = null
@@ -71,13 +79,7 @@ class KeyguardMediaController @Inject constructor(
     */
     */
    fun attachSinglePaneContainer(mediaView: MediaHeaderView?) {
    fun attachSinglePaneContainer(mediaView: MediaHeaderView?) {
        singlePaneContainer = mediaView
        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
        // Required to show it for the first time, afterwards visibility is managed automatically
        mediaHost.visible = true
        mediaHost.visible = true
        mediaHost.addVisibilityChangeListener { visible ->
        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
        // might be called a few times for the same view, no need to add hostView again
        if (activeContainer?.childCount == 0) {
        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)
            activeContainer.addView(mediaHost.hostView)
        }
        }
        setVisibility(activeContainer, View.VISIBLE)
        setVisibility(activeContainer, View.VISIBLE)
+7 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,8 @@ class MediaHost constructor(


    private val tmpLocationOnScreen: IntArray = intArrayOf(0, 0)
    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
     * 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.
     *                 transitions.
     */
     */
    fun init(@MediaLocation location: Int) {
    fun init(@MediaLocation location: Int) {
        if (inited) {
            return
        }
        inited = true

        this.location = location
        this.location = location
        hostView = mediaHierarchyManager.register(this)
        hostView = mediaHierarchyManager.register(this)
        hostView.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
        hostView.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {