Refactor animation duraton

This commit is contained in:
Koitharu
2022-07-09 10:56:37 +03:00
parent 53f127987c
commit 4743f40154
10 changed files with 67 additions and 53 deletions

View File

@@ -30,12 +30,11 @@ import com.google.android.material.color.MaterialColors
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.android.material.snackbar.Snackbar
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.databinding.FadingSnackbarLayoutBinding
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
import com.google.android.material.R as materialR
private const val ENTER_DURATION = 300L
private const val EXIT_DURATION = 200L
private const val SHORT_DURATION_MS = 1_500L
private const val LONG_DURATION_MS = 2_750L
@@ -53,6 +52,8 @@ class FadingSnackbar @JvmOverloads constructor(
) : FrameLayout(context, attrs, defStyleAttr) {
private val binding = FadingSnackbarLayoutBinding.inflate(LayoutInflater.from(context), this)
private val enterDuration = context.resources.getInteger(R.integer.config_defaultAnimTime).toLong()
private val exitDuration = context.resources.getInteger(android.R.integer.config_shortAnimTime).toLong()
init {
binding.snackbarLayout.background = createThemedBackground()
@@ -63,7 +64,7 @@ class FadingSnackbar @JvmOverloads constructor(
animate()
.alpha(0f)
.withEndAction { visibility = GONE }
.duration = EXIT_DURATION
.duration = exitDuration
}
}
@@ -90,11 +91,11 @@ class FadingSnackbar @JvmOverloads constructor(
visibility = VISIBLE
animate()
.alpha(1f)
.duration = ENTER_DURATION
.duration = enterDuration
if (duration == Snackbar.LENGTH_INDEFINITE) {
return
}
val durationMs = ENTER_DURATION + if (duration == Snackbar.LENGTH_LONG) LONG_DURATION_MS else SHORT_DURATION_MS
val durationMs = enterDuration + if (duration == Snackbar.LENGTH_LONG) LONG_DURATION_MS else SHORT_DURATION_MS
postDelayed(durationMs) {
dismiss()
onDismiss?.invoke()

View File

@@ -49,7 +49,6 @@ import org.koitharu.kotatsu.utils.ext.*
import kotlin.math.roundToInt
private const val BUBBLE_ANIM_DURATION = 100L
private const val SCROLLBAR_ANIM_DURATION = 300L
private const val SCROLLBAR_HIDE_DELAY = 1000L
private const val TRACK_SNAP_RANGE = 5
@@ -63,6 +62,9 @@ class FastScroller : LinearLayout {
private val Size.textSize get() = resources.getDimension(textSizeId)
private val animationDuration = (context.resources.getInteger(R.integer.config_defaultAnimTime) *
context.animatorDurationScale).toLong()
private val bubbleView: TextView by lazy { findViewById(R.id.fastscroll_bubble) }
private val handleView: ImageView by lazy { findViewById(R.id.fastscroll_handle) }
private val trackView: ImageView by lazy { findViewById(R.id.fastscroll_track) }
@@ -539,14 +541,14 @@ class FastScroller : LinearLayout {
scrollbar.translationX = scrollbarPaddingEnd
scrollbar.isVisible = true
scrollbarAnimator = scrollbar.animate().translationX(0f).alpha(1f)
.setDuration(SCROLLBAR_ANIM_DURATION)
.setDuration(animationDuration)
.setListener(alphaAnimatorListener)
}
}
private fun hideScrollbar() {
scrollbarAnimator = scrollbar.animate().translationX(scrollbarPaddingEnd).alpha(0f)
.setDuration(SCROLLBAR_ANIM_DURATION)
.setDuration(animationDuration)
.setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)

View File

@@ -9,6 +9,7 @@ import coil.request.ImageRequest
import coil.request.ImageResult
import coil.request.SuccessResult
import com.google.android.material.progressindicator.BaseProgressIndicator
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.network.CommonHeaders
import org.koitharu.kotatsu.utils.progress.ImageRequestIndicatorListener
@@ -41,7 +42,12 @@ fun ImageRequest.Builder.indicator(indicator: BaseProgressIndicator<*>): ImageRe
return listener(ImageRequestIndicatorListener(indicator))
}
@Suppress("SpellCheckingInspection")
fun ImageRequest.Builder.crossfade(context: Context?): ImageRequest.Builder {
val scale = context?.animatorDurationScale ?: 1f
return crossfade((300 * scale).toInt())
if (context == null) {
crossfade(true)
return this
}
val duration = context.resources.getInteger(R.integer.config_defaultAnimTime) * context.animatorDurationScale
return crossfade(duration.toInt())
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in">
<translate

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in">
<translate

View File

@@ -1,34 +1,34 @@
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 5 5 L 8 5 L 8 18 L 5 18 Z M 9 3 L 12 3 L 12 18 L 9 18 Z M 3 19 L 21 19 L 21 21 L 3 21 Z"
android:fillColor="#000"
android:strokeWidth="1"/>
<path
android:name="path_1"
android:pathData="M 11.967 4.974 L 15.025 4.031 L 19.034 17.027 L 15.976 17.971 Z"
android:fillColor="#000"
android:strokeWidth="1"/>
</vector>
</aapt:attr>
<target android:name="path_1">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="300"
android:valueFrom="M 15.025 4.031 L 11.967 4.974 L 15.976 17.971 L 19.034 17.027 L 15.025 4.031 M 6.5 11.5 L 6.5 11.5 L 6.5 11.5 L 6.5 11.5 L 6.5 11.5 M 10.5 10.5 L 10.5 10.5 L 10.5 10.5 L 10.5 10.5 L 10.5 10.5 M 12 20 L 12 20 L 12 20 L 12 20 L 12 20"
android:valueTo="M 19.2 4.4 L 16 4.4 L 16 18 L 19.2 18 L 19.2 4.4 M 5 5 L 8 5 L 8 18 L 5 18 L 5 5 M 9 3 L 12 3 L 12 18 L 9 18 L 9 3 M 3 19 L 21 19 L 21 21 L 3 21 L 3 19"
android:valueType="pathType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:fillColor="#000"
android:pathData="M 5 5 L 8 5 L 8 18 L 5 18 Z M 9 3 L 12 3 L 12 18 L 9 18 Z M 3 19 L 21 19 L 21 21 L 3 21 Z"
android:strokeWidth="1" />
<path
android:name="path_1"
android:fillColor="#000"
android:pathData="M 11.967 4.974 L 15.025 4.031 L 19.034 17.027 L 15.976 17.971 Z"
android:strokeWidth="1" />
</vector>
</aapt:attr>
<target android:name="path_1">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:propertyName="pathData"
android:valueFrom="M 15.025 4.031 L 11.967 4.974 L 15.976 17.971 L 19.034 17.027 L 15.025 4.031 M 6.5 11.5 L 6.5 11.5 L 6.5 11.5 L 6.5 11.5 L 6.5 11.5 M 10.5 10.5 L 10.5 10.5 L 10.5 10.5 L 10.5 10.5 L 10.5 10.5 M 12 20 L 12 20 L 12 20 L 12 20 L 12 20"
android:valueTo="M 19.2 4.4 L 16 4.4 L 16 18 L 19.2 18 L 19.2 4.4 M 5 5 L 8 5 L 8 18 L 5 18 L 5 5 M 9 3 L 12 3 L 12 18 L 9 18 L 9 3 M 3 19 L 21 19 L 21 21 L 3 21 L 3 19"
android:valueType="pathType" />
</aapt:attr>
</target>
</animated-vector>

View File

@@ -19,7 +19,7 @@
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="300"
android:duration="@integer/config_defaultAnimTime"
android:valueFrom="M 16 4.4 L 19.2 4.4 L 19.2 18 L 16 18 L 16 4.4 M 9 3 L 9 18 L 12 18 L 12 3 L 9 3 M 5 5 L 5 18 L 8 18 L 8 5 L 5 5 M 3 19 L 21 19 L 21 21 L 3 21 L 3 20 L 3 19"
android:valueTo="M 12 5 L 15 4 L 19 17 L 16 18 L 12 5 M 9 3 L 9 18 L 12 18 L 12 3 L 9 3 M 5 5 L 5 18 L 8 18 L 8 5 L 5 5 M 3 19 L 21 19 L 21 21 L 3 21 L 3 19 L 3 19"
android:valueType="pathType"

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
@@ -47,7 +48,7 @@
<target android:name="compass">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="300"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:propertyName="pathData"
android:valueFrom="M 9.99 9.99 C 9.408 11.242 8.827 12.493 8.245 13.745 C 7.663 14.997 7.082 16.248 6.5 17.5 C 6.5 17.5 6.5 17.5 6.5 17.5 C 9.003 16.337 11.507 15.173 14.01 14.01 C 15.173 11.507 16.337 9.003 17.5 6.5 C 14.997 7.663 12.493 8.827 9.99 9.99 M 12 10.9 C 11.39 10.9 10.9 11.39 10.9 12 C 10.9 12.305 11.023 12.58 11.221 12.779 C 11.42 12.977 11.695 13.1 12 13.1 C 12.61 13.1 13.1 12.61 13.1 12 C 13.1 11.39 12.61 10.9 12 10.9 L 12 10.9 M 12 12 L 12 12 L 12 12 L 12 12 L 12 12 L 12 12 L 12 12 M 12 12 L 12 12 C 12 12 12 12 12 12 C 12 12 12 12 12 12 C 12 12 12 12 12 12 C 12 12 12 12 12 12"
@@ -58,7 +59,7 @@
<target android:name="main_parent">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="300"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:propertyName="rotation"
android:valueFrom="0"

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
@@ -46,7 +47,7 @@
<target android:name="compass">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="300"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:propertyName="pathData"
android:valueFrom="M 12 2 C 6.48 2 2 6.48 2 12 C 2 17.141 5.886 21.38 10.878 21.938 C 11.247 21.979 11.621 22 12 22 C 17.52 22 22 17.52 22 12 C 22 6.48 17.52 2 12 2 L 12 2 M 12 10.9 C 11.695 10.9 11.42 11.023 11.221 11.221 C 11.023 11.42 10.9 11.695 10.9 12 C 10.9 12.61 11.39 13.1 12 13.1 C 12.61 13.1 13.1 12.61 13.1 12 C 13.1 11.39 12.61 10.9 12 10.9 L 12 10.9 M 14.19 14.19 L 6 18 L 6 18 L 9.81 9.81 L 18 6 L 14.19 14.19 L 14.19 14.19 M 12 12 L 12 12 L 12 12 L 12 12 L 12 12 L 12 12"
@@ -57,7 +58,7 @@
<target android:name="main_parent">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="300"
android:duration="@integer/config_defaultAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:propertyName="rotation"
android:valueFrom="180"

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="config_defaultAnimTime">300</integer>
<integer name="manga_badge_max_character_count">3</integer>
<integer name="explore_buttons_columns">2</integer>