mirror of
https://github.com/mihonapp/mihon.git
synced 2024-10-31 21:20:59 -04:00
93e6136795
* Use Coil * Remove coil-transformations lib * Add MangaCoverFetcher * Remove Glide * MangaCoverFetcher: Allow skipping custom cover usage * Adjust coil caching policy for some non-library items * Allow coil to use RGB565 only on low ram devices * Fix image loading progress view not showing a * Increase coil crossfade duration Same as default glide duration * Add back request clearing
43 lines
1.3 KiB
Kotlin
43 lines
1.3 KiB
Kotlin
package eu.kanade.tachiyomi.widget
|
|
|
|
import android.graphics.drawable.Drawable
|
|
import android.view.View
|
|
import android.widget.ImageView
|
|
import androidx.core.view.isVisible
|
|
import coil.drawable.CrossfadeDrawable
|
|
import coil.target.ImageViewTarget
|
|
|
|
/**
|
|
* A Coil target to display an image with an optional view to show while loading.
|
|
*
|
|
* @param target the view where the image will be loaded
|
|
* @param progress the view to show when the image is loading.
|
|
* @param crossfadeDuration duration in millisecond to crossfade the result drawable
|
|
*/
|
|
class StateImageViewTarget(
|
|
private val target: ImageView,
|
|
private val progress: View,
|
|
private val crossfadeDuration: Int = 0
|
|
) : ImageViewTarget(target) {
|
|
override fun onStart(placeholder: Drawable?) {
|
|
progress.isVisible = true
|
|
}
|
|
|
|
override fun onSuccess(result: Drawable) {
|
|
progress.isVisible = false
|
|
if (crossfadeDuration > 0) {
|
|
val crossfadeResult = CrossfadeDrawable(target.drawable, result, durationMillis = crossfadeDuration)
|
|
target.setImageDrawable(crossfadeResult)
|
|
crossfadeResult.start()
|
|
} else {
|
|
target.setImageDrawable(result)
|
|
}
|
|
}
|
|
|
|
override fun onError(error: Drawable?) {
|
|
progress.isVisible = false
|
|
if (error != null) {
|
|
target.setImageDrawable(error)
|
|
}
|
|
}
|
|
}
|