Advertisement
Driics

Untitled

Jul 15th, 2023
1,546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.99 KB | None | 0 0
  1. class AnimationHandler(private val animationFactory: AnimatorFactory, private val animationListProvider: vg2.a<List<wg2.a>, Payload>) {
  2.  
  3.     private val animationList = mutableListOf<Animation>()
  4.     private val animationObserver = vg2.c<List<wg2.a>, Unit>(emptyList())
  5.     private val animator = AnimatorFactory.createAnimator(animationFactory, 0.5f, 0.0f, AccelerateDecelerateInterpolator(), 2, null)
  6.  
  7.     init {
  8.         animationListProvider.registerObserver(AnimationObserver(this))
  9.     }
  10.  
  11.     private fun updateAnimationList() {
  12.         val animations = if (animator.isRunning) animationList else animationListProvider.get()
  13.         vg2.c.update(animationObserver, animations, null, 2, null)
  14.     }
  15.  
  16.     private fun createAnimation(animation: wg2.a, animate: Boolean): wg2.a {
  17.         val animationList = if (animate) listOf(tg2.createAnimation(animation.x(), animation.c())) else emptyList()
  18.         return yg2.b(tg2.h(animationList))
  19.     }
  20.  
  21.     fun getAnimationObserver(): vg2.a<List<wg2.a>, Unit> {
  22.         return animationObserver
  23.     }
  24.  
  25.     fun isAnimatorRunning(): Boolean {
  26.         return animator.isRunning
  27.     }
  28.  
  29.     fun updateAnimations(animations: List<wg2.a>, payload: Payload?) {
  30.         val animate = payload?.isAnimate() ?: false
  31.         if (!animate) {
  32.             qg2.a.stopAnimator(animator, false, 1, null)
  33.             updateAnimationList()
  34.             return
  35.         }
  36.         animationList.clear()
  37.         animations.forEach { animation ->
  38.             animationList.add(createAnimation(animation, true))
  39.         }
  40.         while (animations.size < animationList.size) {
  41.             animations.add(createAnimation(animations.last(), true))
  42.         }
  43.         animationList.clear()
  44.         for (i in animations.indices) {
  45.             animationList.add(Animation(animationList[i], animations[i]))
  46.         }
  47.         animator.animate(0.0f, 1.0f, animate)
  48.     }
  49.  
  50.     fun updateAnimationProgress() {
  51.         if (animator.isRunning) {
  52.             val progress = animator.progress
  53.             for (i in animationList.indices) {
  54.                 animationList[i].updateProgress(progress)
  55.             }
  56.             updateAnimationList()
  57.         }
  58.     }
  59.  
  60.     class Payload(private val animate: Boolean) {
  61.  
  62.         fun isAnimate(): Boolean {
  63.             return animate
  64.         }
  65.  
  66.         override fun equals(other: Any?): Boolean {
  67.             if (this === other) return true
  68.             if (other !is Payload) return false
  69.             return animate == other.animate
  70.         }
  71.  
  72.         override fun hashCode(): Int {
  73.             return animate.hashCode()
  74.         }
  75.  
  76.         override fun toString(): String {
  77.             return "Payload(animate=$animate)"
  78.         }
  79.     }
  80.  
  81.     class Animation(private val animation1: wg2.a, private val animation2: wg2.a) {
  82.         // The rest of the class implementation goes here
  83.     }
  84.  
  85.     class AnimationObserver(private val handler: AnimationHandler) : Observer {
  86.         // The rest of the class implementation goes here
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement