blob: f8f71a5ab849bb9fd9960288c8d81690b5f46830 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
package ca.allanwang.kau.animators
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewPropertyAnimator
import ca.allanwang.kau.utils.KAU_BOTTOM
import ca.allanwang.kau.utils.KAU_LEFT
import ca.allanwang.kau.utils.KAU_RIGHT
import ca.allanwang.kau.utils.KAU_TOP
/**
* Created by Allan Wang on 2017-07-11.
*/
class SlideAnimatorAdd(val fromEdge: Int, val slideFactor: Float = 1f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorAdd {
override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = {
when (fromEdge) {
KAU_TOP -> translationY = slideFactor * -height
KAU_LEFT -> translationX = slideFactor * -width
KAU_BOTTOM -> translationY = slideFactor * height
KAU_RIGHT -> translationX = slideFactor * width
else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*")
}
alpha = 0f
}
override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = {
translationY(0f)
translationX(0f)
alpha(1f)
}
override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = {
translationY = 0f
translationX = 0f
alpha = 1f
}
override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L
}
class SlideAnimatorRemove(val fromEdge: Int, val slideFactor: Float = 1f, override var itemDelayFactor: Float = 0.125f) : KauAnimatorRemove {
override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = {
with(holder.itemView) {
when (fromEdge) {
KAU_TOP -> translationY(slideFactor * -height)
KAU_LEFT -> translationX(slideFactor * -width)
KAU_BOTTOM -> translationY(slideFactor * height)
KAU_RIGHT -> translationX(slideFactor * width)
else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*")
}
}
alpha(0f)
}
override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = {
translationY = 0f
translationX = 0f
alpha = 1f
}
override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L
}
|