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

Commit a03c8dd5 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Filtering null emissions from the long-press effect StateFlow.

The null values of the actionType flow only represent an idle state
where nothing happens. It is not necessary to collect them and add
coroutine continuation points just for this values.

Test: presubmit
Flag: ACONFIG quick_settings_visual_haptics_longpress TEAMFOOD
Bug: 333987986
Change-Id: I9219deb2cfb77c8a7fb8306c4a7879b767d0a0a4
parent 1fc80a64
Loading
Loading
Loading
Loading
+45 −52
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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.flow.filterNotNull

object QSLongPressEffectViewBinder {

@@ -49,9 +50,8 @@ object QSLongPressEffectViewBinder {
                launch({ "${tileSpec ?: "unknownTileSpec"}#LongPressEffect#action" }) {
                    var effectAnimator: ValueAnimator? = null

                    qsLongPressEffect.actionType.collect { action ->
                        action?.let {
                            when (it) {
                    qsLongPressEffect.actionType.filterNotNull().collect { action ->
                        when (action) {
                            QSLongPressEffect.ActionType.CLICK -> {
                                tile.performClick()
                                qsLongPressEffect.clearActionType()
@@ -74,9 +74,7 @@ object QSLongPressEffectViewBinder {
                                                qsLongPressEffect.effectDuration.toLong()
                                            interpolator = AccelerateDecelerateInterpolator()

                                                doOnStart {
                                                    qsLongPressEffect.handleAnimationStart()
                                                }
                                            doOnStart { qsLongPressEffect.handleAnimationStart() }
                                            addUpdateListener {
                                                val value = animatedValue as Float
                                                if (value == 0f) {
@@ -85,12 +83,8 @@ object QSLongPressEffectViewBinder {
                                                    tile.updateLongPressEffectProperties(value)
                                                }
                                            }
                                                doOnEnd {
                                                    qsLongPressEffect.handleAnimationComplete()
                                                }
                                                doOnCancel {
                                                    qsLongPressEffect.handleAnimationCancel()
                                                }
                                            doOnEnd { qsLongPressEffect.handleAnimationComplete() }
                                            doOnCancel { qsLongPressEffect.handleAnimationCancel() }
                                            start()
                                        }
                                }
@@ -112,7 +106,6 @@ object QSLongPressEffectViewBinder {
            }
        }
    }
    }

    @SuppressLint("ClickableViewAccessibility")
    private fun setTouchListener(tile: QSTileViewImpl, longPressEffect: QSLongPressEffect?) {