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

Commit 851230d6 authored by Matt Pietal's avatar Matt Pietal
Browse files

Controls UI - Fix crash on missing control

Properly clean up state when switching structures. Due to events
coming in from the listing controller, do not assume controls that
were initially created are still present.

Bug: 152678308
Test: manual, switch structures after reboot
Change-Id: Ic60782c5a7e292ea633ad812f3313efd33574cc6
parent 33696c1c
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
@@ -170,11 +170,17 @@ class ControlsUiControllerImpl @Inject constructor (
    private fun reload(parent: ViewGroup) {
        if (hidden) return

        controlsListingController.get().removeCallback(listingCallback)
        controlsController.get().unsubscribe()

        val fadeAnim = ObjectAnimator.ofFloat(parent, "alpha", 1.0f, 0.0f)
        fadeAnim.setInterpolator(AccelerateInterpolator(1.0f))
        fadeAnim.setDuration(FADE_IN_MILLIS)
        fadeAnim.addListener(object : AnimatorListenerAdapter() {
            override fun onAnimationEnd(animation: Animator) {
                controlViewsById.clear()
                controlsById.clear()

                show(parent, dismissGlobalActions)
                val showAnim = ObjectAnimator.ofFloat(parent, "alpha", 0.0f, 1.0f)
                showAnim.setInterpolator(DecelerateInterpolator(1.0f))
@@ -448,6 +454,8 @@ class ControlsUiControllerImpl @Inject constructor (
        val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup
        var lastRow: ViewGroup = createRow(inflater, listView)
        selectedStructure.controls.forEach {
            val key = ControlKey(selectedStructure.componentName, it.controlId)
            controlsById.get(key)?.let {
                if (lastRow.getChildCount() == maxColumns) {
                    lastRow = createRow(inflater, listView)
                }
@@ -460,10 +468,10 @@ class ControlsUiControllerImpl @Inject constructor (
                    uiExecutor,
                    bgExecutor
                )
            val key = ControlKey(selectedStructure.componentName, it.controlId)
            cvh.bindData(controlsById.getValue(key))
                cvh.bindData(it)
                controlViewsById.put(key, cvh)
            }
        }

        // add spacers if necessary to keep control size consistent
        val mod = selectedStructure.controls.size % maxColumns
@@ -528,7 +536,6 @@ class ControlsUiControllerImpl @Inject constructor (
        if (newSelection != selectedStructure) {
            selectedStructure = newSelection
            updatePreferences(selectedStructure)
            controlsListingController.get().removeCallback(listingCallback)
            reload(parent)
        }
    }
@@ -545,6 +552,7 @@ class ControlsUiControllerImpl @Inject constructor (
        parent.removeAllViews()
        controlsById.clear()
        controlViewsById.clear()

        controlsListingController.get().removeCallback(listingCallback)

        RenderInfo.clearCache()