Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AnimationHandler(private val animationFactory: AnimatorFactory, private val animationListProvider: vg2.a<List<wg2.a>, Payload>) {
- private val animationList = mutableListOf<Animation>()
- private val animationObserver = vg2.c<List<wg2.a>, Unit>(emptyList())
- private val animator = AnimatorFactory.createAnimator(animationFactory, 0.5f, 0.0f, AccelerateDecelerateInterpolator(), 2, null)
- init {
- animationListProvider.registerObserver(AnimationObserver(this))
- }
- private fun updateAnimationList() {
- val animations = if (animator.isRunning) animationList else animationListProvider.get()
- vg2.c.update(animationObserver, animations, null, 2, null)
- }
- private fun createAnimation(animation: wg2.a, animate: Boolean): wg2.a {
- val animationList = if (animate) listOf(tg2.createAnimation(animation.x(), animation.c())) else emptyList()
- return yg2.b(tg2.h(animationList))
- }
- fun getAnimationObserver(): vg2.a<List<wg2.a>, Unit> {
- return animationObserver
- }
- fun isAnimatorRunning(): Boolean {
- return animator.isRunning
- }
- fun updateAnimations(animations: List<wg2.a>, payload: Payload?) {
- val animate = payload?.isAnimate() ?: false
- if (!animate) {
- qg2.a.stopAnimator(animator, false, 1, null)
- updateAnimationList()
- return
- }
- animationList.clear()
- animations.forEach { animation ->
- animationList.add(createAnimation(animation, true))
- }
- while (animations.size < animationList.size) {
- animations.add(createAnimation(animations.last(), true))
- }
- animationList.clear()
- for (i in animations.indices) {
- animationList.add(Animation(animationList[i], animations[i]))
- }
- animator.animate(0.0f, 1.0f, animate)
- }
- fun updateAnimationProgress() {
- if (animator.isRunning) {
- val progress = animator.progress
- for (i in animationList.indices) {
- animationList[i].updateProgress(progress)
- }
- updateAnimationList()
- }
- }
- class Payload(private val animate: Boolean) {
- fun isAnimate(): Boolean {
- return animate
- }
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is Payload) return false
- return animate == other.animate
- }
- override fun hashCode(): Int {
- return animate.hashCode()
- }
- override fun toString(): String {
- return "Payload(animate=$animate)"
- }
- }
- class Animation(private val animation1: wg2.a, private val animation2: wg2.a) {
- // The rest of the class implementation goes here
- }
- class AnimationObserver(private val handler: AnimationHandler) : Observer {
- // The rest of the class implementation goes here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement