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

Commit 7b23d937 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez Committed by Android (Google) Code Review
Browse files

Merge "Starting long-press effect coroutines on CREATED" into main

parents 3fbb8193 5d0df8ec
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