aboutsummaryrefslogtreecommitdiff
path: root/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt
diff options
context:
space:
mode:
Diffstat (limited to 'adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt')
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt64
1 files changed, 64 insertions, 0 deletions
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt b/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt
new file mode 100644
index 0000000..f8f71a5
--- /dev/null
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt
@@ -0,0 +1,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
+} \ No newline at end of file