* 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
This commit is contained in:
Ivan Iskandar
2021-04-28 19:32:00 +07:00
committed by GitHub
parent 7d23fd8ef5
commit 93e6136795
39 changed files with 492 additions and 797 deletions

View File

@@ -3,61 +3,41 @@ package eu.kanade.tachiyomi.widget
import android.graphics.drawable.Drawable
import android.view.View
import android.widget.ImageView
import android.widget.ImageView.ScaleType
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.isVisible
import com.bumptech.glide.request.target.ImageViewTarget
import com.bumptech.glide.request.transition.Transition
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.getResourceColor
import coil.drawable.CrossfadeDrawable
import coil.target.ImageViewTarget
/**
* A glide target to display an image with an optional view to show while loading and a configurable
* error drawable.
* A Coil target to display an image with an optional view to show while loading.
*
* @param view the view where the image will be loaded
* @param progress an optional view to show when the image is loading.
* @param errorDrawableRes the error drawable resource to show.
* @param errorScaleType the scale type for the error drawable, [ScaleType.CENTER] by default.
* @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(
view: ImageView,
val progress: View? = null,
private val errorDrawableRes: Int = R.drawable.ic_broken_image_grey_24dp,
private val errorScaleType: ScaleType = ScaleType.CENTER
) : ImageViewTarget<Drawable>(view) {
private var resource: Drawable? = null
private val imageScaleType = view.scaleType
override fun setResource(resource: Drawable?) {
view.setImageDrawable(resource)
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 onLoadStarted(placeholder: Drawable?) {
progress?.isVisible = true
super.onLoadStarted(placeholder)
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 onLoadFailed(errorDrawable: Drawable?) {
progress?.isVisible = false
view.scaleType = errorScaleType
val vector = AppCompatResources.getDrawable(view.context, errorDrawableRes)
vector?.setTint(view.context.getResourceColor(R.attr.colorOnBackground, 0.38f))
view.setImageDrawable(vector)
}
override fun onLoadCleared(placeholder: Drawable?) {
progress?.isVisible = false
super.onLoadCleared(placeholder)
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
progress?.isVisible = false
view.scaleType = imageScaleType
super.onResourceReady(resource, transition)
this.resource = resource
override fun onError(error: Drawable?) {
progress.isVisible = false
if (error != null) {
target.setImageDrawable(error)
}
}
}