diff options
| author | 2024-05-06 23:44:20 +0000 | |
|---|---|---|
| committer | 2024-05-06 23:44:20 +0000 | |
| commit | 4e2eb1b377df9f65baed6bb715445279e749f713 (patch) | |
| tree | 14cc66771fcbaac7959d619159abff5c2ca3064b | |
| parent | 8b31c7b30423128bc0e2baa3a7fd6d6bdf24ab26 (diff) | |
| parent | a03c8dd5d2438d348bf08650f1837b15781f0bb1 (diff) | |
Merge "Filtering null emissions from the long-press effect StateFlow." into main
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt | 97 |
1 files changed, 45 insertions, 52 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt index c464ed1d29bb..4875f481cce6 100644 --- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt @@ -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,64 +50,56 @@ object QSLongPressEffectViewBinder { launch({ "${tileSpec ?: "unknownTileSpec"}#LongPressEffect#action" }) { var effectAnimator: ValueAnimator? = null - qsLongPressEffect.actionType.collect { action -> - action?.let { - when (it) { - QSLongPressEffect.ActionType.CLICK -> { - tile.performClick() - qsLongPressEffect.clearActionType() - } - QSLongPressEffect.ActionType.LONG_PRESS -> { - tile.prepareForLaunch() - tile.performLongClick() - qsLongPressEffect.clearActionType() - } - QSLongPressEffect.ActionType.RESET_AND_LONG_PRESS -> { - tile.resetLongPressEffectProperties() - tile.performLongClick() - qsLongPressEffect.clearActionType() - } - QSLongPressEffect.ActionType.START_ANIMATOR -> { - if (effectAnimator?.isRunning != true) { - effectAnimator = - ValueAnimator.ofFloat(0f, 1f).apply { - this.duration = - qsLongPressEffect.effectDuration.toLong() - interpolator = AccelerateDecelerateInterpolator() + qsLongPressEffect.actionType.filterNotNull().collect { action -> + when (action) { + QSLongPressEffect.ActionType.CLICK -> { + tile.performClick() + qsLongPressEffect.clearActionType() + } + QSLongPressEffect.ActionType.LONG_PRESS -> { + tile.prepareForLaunch() + tile.performLongClick() + qsLongPressEffect.clearActionType() + } + QSLongPressEffect.ActionType.RESET_AND_LONG_PRESS -> { + tile.resetLongPressEffectProperties() + tile.performLongClick() + qsLongPressEffect.clearActionType() + } + QSLongPressEffect.ActionType.START_ANIMATOR -> { + if (effectAnimator?.isRunning != true) { + effectAnimator = + ValueAnimator.ofFloat(0f, 1f).apply { + this.duration = + qsLongPressEffect.effectDuration.toLong() + interpolator = AccelerateDecelerateInterpolator() - doOnStart { - qsLongPressEffect.handleAnimationStart() + doOnStart { qsLongPressEffect.handleAnimationStart() } + addUpdateListener { + val value = animatedValue as Float + if (value == 0f) { + tile.bringToFront() + } else { + tile.updateLongPressEffectProperties(value) } - addUpdateListener { - val value = animatedValue as Float - if (value == 0f) { - tile.bringToFront() - } else { - tile.updateLongPressEffectProperties(value) - } - } - doOnEnd { - qsLongPressEffect.handleAnimationComplete() - } - doOnCancel { - qsLongPressEffect.handleAnimationCancel() - } - start() } - } + doOnEnd { qsLongPressEffect.handleAnimationComplete() } + doOnCancel { qsLongPressEffect.handleAnimationCancel() } + start() + } } - QSLongPressEffect.ActionType.REVERSE_ANIMATOR -> { - effectAnimator?.let { - val pausedProgress = it.animatedFraction - qsLongPressEffect.playReverseHaptics(pausedProgress) - it.reverse() - } - } - QSLongPressEffect.ActionType.CANCEL_ANIMATOR -> { - tile.resetLongPressEffectProperties() - effectAnimator?.cancel() + } + QSLongPressEffect.ActionType.REVERSE_ANIMATOR -> { + effectAnimator?.let { + val pausedProgress = it.animatedFraction + qsLongPressEffect.playReverseHaptics(pausedProgress) + it.reverse() } } + QSLongPressEffect.ActionType.CANCEL_ANIMATOR -> { + tile.resetLongPressEffectProperties() + effectAnimator?.cancel() + } } } } |