aboutsummaryrefslogtreecommitdiff
path: root/adapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt
blob: e968cdadeda73c2980154a1941a98da6e8a6be6f (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
package ca.allanwang.kau.animators

import android.support.v7.widget.RecyclerView
import android.view.ViewPropertyAnimator

/**
 * Created by Allan Wang on 2017-06-29.
 */
open class FadeScaleAnimator(val scaleFactor: Float = 0.7f, itemDelayFactor: Float = 0.125f) : BaseDelayAnimator(itemDelayFactor) {

    override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) {
        with(holder.itemView) {
            scaleX = scaleFactor
            scaleY = scaleFactor
            alpha = 0f
        }
    }

    override final fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator {
        return super.addAnimation(holder).apply {
            scaleX(1f)
            scaleY(1f)
            alpha(1f)
        }
    }


    final override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) {
        with(holder.itemView) {
            scaleX = 1f
            scaleY = 1f
            alpha = 1f
        }
    }

    override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator {
        return super.removeAnimation(holder).apply {
            scaleX(scaleFactor)
            scaleY(scaleFactor)
            alpha(0f)
        }
    }

    override final fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) {
        with(holder.itemView) {
            translationY = 0f
            translationX = 0f
            alpha = 1f
        }
    }
}