diff options
author | Allan Wang <allanwang@google.com> | 2020-01-13 15:29:13 -0800 |
---|---|---|
committer | Allan Wang <allanwang@google.com> | 2020-01-13 15:29:13 -0800 |
commit | f24a2cfb20d86b6dae8aa9ccf16eb4d038955874 (patch) | |
tree | 5108660ee6d008383fae95292742ced47c668e08 | |
parent | 986664c999cc4940161e84fdd271b1633d3f19c3 (diff) | |
download | kau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.tar.gz kau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.tar.bz2 kau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.zip |
Misc fixes
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt index f735f4d..486dc7f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt @@ -33,7 +33,7 @@ class ProgressAnimator private constructor() : ValueAnimator() { companion object { - fun ofFloat(builder: ProgressAnimator.() -> Unit): ProgressAnimator = ProgressAnimator().apply { + fun ofFloat(builder: ProgressAnimator.() -> Unit = {}): ProgressAnimator = ProgressAnimator().apply { setFloatValues(0f, 1f) addUpdateListener { apply(it.animatedValue as Float) } addListener(object : AnimatorListenerAdapter() { @@ -143,30 +143,36 @@ class ProgressAnimator private constructor() : ValueAnimator() { } } - fun withRangeAnimator(min: Float, max: Float, start: Float, end: Float, progress: Float, action: ProgressAction) { - if (min >= max) { - throw IllegalArgumentException("Range animator must have min < max; currently min=$min, max=$max") - } + fun withRangeAnimator(min: Float, max: Float, start: Float, end: Float, action: ProgressAction) { + require(min < max) { "Range animator must have min < max; currently min=$min, max=$max" } withDisposableAnimator { when { it > max -> true it < min -> false else -> { - action(progress(start, end, progress, min, max)) + action(progress(start, end, it, min, max)) false } } } } - fun withPointAnimator(point: Float, action: ProgressAction) { + @Deprecated(level = DeprecationLevel.WARNING, + message = "Renamed to withPointAction", + replaceWith = ReplaceWith("withPointAction(point, action)")) + fun withPointAnimator(point: Float, action: ProgressAction) = withPointAction(point, isAscendingProgress = true, action = action) + + fun withPointAction(point: Float, isAscendingProgress: Boolean = true, action: ProgressAction) { animators.add { - action.runIf(it >= point, it) + action.runIf((isAscendingProgress && (it >= point) || !isAscendingProgress && (it <= point)), it) } } fun withDelayedStartAction(skipCount: Int, action: ProgressAction) { var count = 0 + withStartAction { + count = 0 + } animators.add { action.runIf(count++ >= skipCount, it) } |