Error drawable now looks better with the dark theme
This commit is contained in:
parent
fe413d52d6
commit
08f2cd2472
@ -4,7 +4,6 @@ import android.view.View
|
|||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||||
import kotlinx.android.synthetic.main.item_catalogue_grid.view.*
|
import kotlinx.android.synthetic.main.item_catalogue_grid.view.*
|
||||||
@ -44,7 +43,6 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA
|
|||||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.skipMemoryCache(true)
|
.skipMemoryCache(true)
|
||||||
.error(R.drawable.ic_broken_image_grey_24dp)
|
|
||||||
.placeholder(android.R.color.transparent)
|
.placeholder(android.R.color.transparent)
|
||||||
.into(StateImageViewTarget(view.thumbnail, view.progress))
|
.into(StateImageViewTarget(view.thumbnail, view.progress))
|
||||||
|
|
||||||
|
@ -1,25 +1,30 @@
|
|||||||
package eu.kanade.tachiyomi.widget
|
package eu.kanade.tachiyomi.widget
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.support.graphics.drawable.VectorDrawableCompat
|
||||||
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ImageView.ScaleType
|
import android.widget.ImageView.ScaleType
|
||||||
import android.widget.ProgressBar
|
|
||||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable
|
import com.bumptech.glide.load.resource.drawable.GlideDrawable
|
||||||
import com.bumptech.glide.request.animation.GlideAnimation
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget
|
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.util.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.gone
|
import eu.kanade.tachiyomi.util.gone
|
||||||
import eu.kanade.tachiyomi.util.visible
|
import eu.kanade.tachiyomi.util.visible
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A glide target to display an image with an optional progress bar and a configurable scale type
|
* A glide target to display an image with an optional view to show while loading and a configurable
|
||||||
* for the error drawable.
|
* error drawable.
|
||||||
*
|
*
|
||||||
* @param view the view where the image will be loaded
|
* @param view the view where the image will be loaded
|
||||||
* @param progress an optional progress bar to show when the image is loading.
|
* @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 errorScaleType the scale type for the error drawable, [ScaleType.CENTER] by default.
|
||||||
*/
|
*/
|
||||||
class StateImageViewTarget(view: ImageView,
|
class StateImageViewTarget(view: ImageView,
|
||||||
val progress: ProgressBar? = null,
|
val progress: View? = null,
|
||||||
|
val errorDrawableRes: Int = R.drawable.ic_broken_image_grey_24dp,
|
||||||
val errorScaleType: ScaleType = ScaleType.CENTER) :
|
val errorScaleType: ScaleType = ScaleType.CENTER) :
|
||||||
GlideDrawableImageViewTarget(view) {
|
GlideDrawableImageViewTarget(view) {
|
||||||
|
|
||||||
@ -33,7 +38,10 @@ class StateImageViewTarget(view: ImageView,
|
|||||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||||
progress?.gone()
|
progress?.gone()
|
||||||
view.scaleType = errorScaleType
|
view.scaleType = errorScaleType
|
||||||
super.onLoadFailed(e, errorDrawable)
|
|
||||||
|
val vector = VectorDrawableCompat.create(view.context.resources, errorDrawableRes, null)
|
||||||
|
vector?.setTint(view.context.getResourceColor(android.R.attr.textColorSecondary))
|
||||||
|
view.setImageDrawable(vector)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
Loading…
Reference in New Issue
Block a user