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

Commit 5d0df8ec authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Starting long-press effect coroutines on CREATED

To avoid coroutines launching when QS tiles are not used or visible, the
launch is now occurring in the CREATED state of the lifecycle owner.
This optimization avoids unnecessary collection of initial values of the
effect flows.

Test: SystemUITests:QSTileViewImplTest
Bug: 331016727
Flag: ACONFIG quick_settings_visual_haptics_longpress TEAMFOOD

Change-Id: If5a3bffa281172b99ef1d73d10e01bf28975d3ce
parent 8880ecd7
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@ package com.android.systemui.haptics.qs

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.app.tracing.coroutines.launch
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.qs.tileimpl.QSTileViewImpl
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.launch

class QSLongPressEffectViewBinder {

@@ -31,16 +31,18 @@ class QSLongPressEffectViewBinder {

    fun bind(
        tile: QSTileViewImpl,
        tileSpec: String?,
        effect: QSLongPressEffect?,
    ) {
        if (effect == null) return

        handle =
            tile.repeatWhenAttached {
                repeatOnLifecycle(Lifecycle.State.STARTED) {
                repeatOnLifecycle(Lifecycle.State.CREATED) {
                    effect.scope = this
                    val tag = "${tileSpec ?: "unknownTileSpec"}#LongPressEffect"

                    launch {
                    launch("$tag#progress") {
                        effect.effectProgress.collect { progress ->
                            progress?.let {
                                if (it == 0f) {
@@ -51,7 +53,7 @@ class QSLongPressEffectViewBinder {
                        }
                    }

                    launch {
                    launch("$tag#action") {
                        effect.actionType.collect { action ->
                            action?.let {
                                when (it) {
+1 −1
Original line number Diff line number Diff line
@@ -620,7 +620,7 @@ open class QSTileViewImpl @JvmOverloads constructor(
                showRippleEffect = false
                setOnTouchListener(longPressEffect)
                if (!longPressEffectViewBinder.isBound) {
                    longPressEffectViewBinder.bind(this, longPressEffect)
                    longPressEffectViewBinder.bind(this, state.spec, longPressEffect)
                }
            } else {
                // Long-press effects might have been enabled before but the new state does not