aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorAllan Wang <allanwang@google.com>2020-01-13 15:29:13 -0800
committerAllan Wang <allanwang@google.com>2020-01-13 15:29:13 -0800
commitf24a2cfb20d86b6dae8aa9ccf16eb4d038955874 (patch)
tree5108660ee6d008383fae95292742ced47c668e08 /core/src
parent986664c999cc4940161e84fdd271b1633d3f19c3 (diff)
downloadkau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.tar.gz
kau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.tar.bz2
kau-f24a2cfb20d86b6dae8aa9ccf16eb4d038955874.zip
Misc fixes
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt22
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)
}