Migrate to TransitionManager from custom animations
parent
15c570979b
commit
ccf4e4d285
@ -1,9 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.utils.anim
|
|
||||||
|
|
||||||
import androidx.annotation.IntegerRes
|
|
||||||
|
|
||||||
enum class Duration(@IntegerRes val resId: Int) {
|
|
||||||
SHORT(android.R.integer.config_shortAnimTime),
|
|
||||||
MEDIUM(android.R.integer.config_mediumAnimTime),
|
|
||||||
LONG(android.R.integer.config_longAnimTime)
|
|
||||||
}
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.utils.anim
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewPropertyAnimator
|
|
||||||
import android.view.animation.AccelerateInterpolator
|
|
||||||
import android.view.animation.DecelerateInterpolator
|
|
||||||
import org.koitharu.kotatsu.utils.ext.measureHeight
|
|
||||||
|
|
||||||
sealed class Motion {
|
|
||||||
|
|
||||||
abstract fun reset(v: View)
|
|
||||||
|
|
||||||
abstract fun hideView(v: View)
|
|
||||||
|
|
||||||
abstract fun hide(v: View, anim: ViewPropertyAnimator)
|
|
||||||
|
|
||||||
abstract fun show(v: View, anim: ViewPropertyAnimator)
|
|
||||||
|
|
||||||
object CrossFade : Motion() {
|
|
||||||
override fun reset(v: View) {
|
|
||||||
v.alpha = 1f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hideView(v: View) {
|
|
||||||
v.alpha = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hide(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.alpha(0f)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun show(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.alpha(1f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object SlideBottom : Motion() {
|
|
||||||
override fun reset(v: View) {
|
|
||||||
v.translationY = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hideView(v: View) {
|
|
||||||
v.translationY = v.measureHeight().toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hide(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.translationY(v.measureHeight().toFloat())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun show(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.translationY(0f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object SlideTop : Motion() {
|
|
||||||
override fun reset(v: View) {
|
|
||||||
v.translationY = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hideView(v: View) {
|
|
||||||
v.translationY = -v.measureHeight().toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hide(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.translationY(-v.measureHeight().toFloat())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun show(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.translationY(0f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object Toast : Motion() {
|
|
||||||
override fun reset(v: View) {
|
|
||||||
v.alpha = 1f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hideView(v: View) {
|
|
||||||
v.alpha = 0f
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hide(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.alpha(0f)
|
|
||||||
anim.translationY(v.measureHeight().toFloat())
|
|
||||||
anim.interpolator = AccelerateInterpolator()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun show(v: View, anim: ViewPropertyAnimator) {
|
|
||||||
anim.alpha(1f)
|
|
||||||
anim.translationY(0f)
|
|
||||||
anim.interpolator = DecelerateInterpolator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.utils.ext
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import org.koitharu.kotatsu.utils.anim.Duration
|
|
||||||
import org.koitharu.kotatsu.utils.anim.Motion
|
|
||||||
|
|
||||||
fun View.showAnimated(
|
|
||||||
effect: Motion,
|
|
||||||
duration: Duration = Duration.MEDIUM,
|
|
||||||
onDone: (() -> Unit)? = null
|
|
||||||
) {
|
|
||||||
if (this.visibility == View.VISIBLE) {
|
|
||||||
onDone?.invoke()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.clearAnimation()
|
|
||||||
effect.hideView(this)
|
|
||||||
this.visibility = View.VISIBLE
|
|
||||||
this.animate().also {
|
|
||||||
it.duration = context.resources.getInteger(duration.resId).toLong()
|
|
||||||
effect.show(this, it)
|
|
||||||
}.withEndAction(onDone)
|
|
||||||
.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View.hideAnimated(
|
|
||||||
effect: Motion,
|
|
||||||
duration: Duration = Duration.MEDIUM,
|
|
||||||
onDone: (() -> Unit)? = null
|
|
||||||
) {
|
|
||||||
if (this.visibility != View.VISIBLE) {
|
|
||||||
onDone?.invoke()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.clearAnimation()
|
|
||||||
this.animate().also {
|
|
||||||
it.duration = context.resources.getInteger(duration.resId).toLong()
|
|
||||||
effect.hide(this, it)
|
|
||||||
}.withEndAction {
|
|
||||||
this.visibility = View.GONE
|
|
||||||
effect.reset(this)
|
|
||||||
onDone?.invoke()
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View.showOrHideAnimated(
|
|
||||||
predicate: Boolean,
|
|
||||||
effect: Motion,
|
|
||||||
duration: Duration = Duration.MEDIUM,
|
|
||||||
onDone: (() -> Unit)? = null
|
|
||||||
) {
|
|
||||||
if (predicate) {
|
|
||||||
showAnimated(effect, duration, onDone)
|
|
||||||
} else {
|
|
||||||
hideAnimated(effect, duration, onDone)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue