Apply system animation scale to parts of Tachiyomi that don't respect it by default (#5794)
* Add initial code for scaling animations, apply scale to reader nav overlay * Rename extension function, apply system animator scale to ActionToolbar * Apply system animator scale to expanding manga cover animation * Apply system animator scale to image crossfade (also disables animated covers when browsing) * Add documentation, make MotionScene Transition comment a bit more clear * Disable animated covers in MangaInfoHeaderAdapter if animator duration scale is 0 * Disable animated covers in Library if animator duration scale is 0 * Convert loadAny listener to extension function
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
package eu.kanade.tachiyomi.util.view
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import coil.ImageLoader
|
||||
import coil.imageLoader
|
||||
import coil.loadAny
|
||||
import coil.request.ImageRequest
|
||||
import coil.target.ImageViewTarget
|
||||
import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
|
||||
/**
|
||||
@@ -19,3 +27,30 @@ fun ImageView.setVectorCompat(@DrawableRes drawable: Int, @AttrRes tint: Int? =
|
||||
}
|
||||
setImageDrawable(vector)
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the image referenced by [data] and set it on this [ImageView],
|
||||
* and if the image is animated, this will also disable that animation
|
||||
* if [Context.animatorDurationScale] is 0
|
||||
*/
|
||||
fun ImageView.loadAnyAutoPause(
|
||||
data: Any?,
|
||||
loader: ImageLoader = context.imageLoader,
|
||||
builder: ImageRequest.Builder.() -> Unit = {}
|
||||
) {
|
||||
this.loadAny(data, loader) {
|
||||
// Build the original request so we can add on our success listener
|
||||
val originalBuild = apply(builder).build()
|
||||
listener(
|
||||
onSuccess = { request, metadata ->
|
||||
(request.target as? ImageViewTarget)?.drawable.let {
|
||||
if (it is Animatable && context.animatorDurationScale == 0f) it.stop()
|
||||
}
|
||||
originalBuild.listener?.onSuccess(request, metadata)
|
||||
},
|
||||
onStart = { request -> originalBuild.listener?.onStart(request) },
|
||||
onCancel = { request -> originalBuild.listener?.onCancel(request) },
|
||||
onError = { request, throwable -> originalBuild.listener?.onError(request, throwable) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user