Add cover error drawable (#6782)

This commit is contained in:
Ivan Iskandar 2022-03-16 09:21:30 +07:00 committed by GitHub
parent 9c426bc216
commit ddb856edc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 4 deletions

View file

@ -1,19 +1,18 @@
package eu.kanade.tachiyomi.util.view package eu.kanade.tachiyomi.util.view
import android.content.Context import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Animatable import android.graphics.drawable.Animatable
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.widget.ImageView import android.widget.ImageView
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.ColorUtils
import coil.ImageLoader import coil.ImageLoader
import coil.imageLoader import coil.imageLoader
import coil.load import coil.load
import coil.request.ImageRequest import coil.request.ImageRequest
import coil.target.ImageViewTarget import coil.target.ImageViewTarget
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.animatorDurationScale import eu.kanade.tachiyomi.util.system.animatorDurationScale
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
@ -42,8 +41,8 @@ fun ImageView.loadAutoPause(
builder: ImageRequest.Builder.() -> Unit = {} builder: ImageRequest.Builder.() -> Unit = {}
) { ) {
load(data, loader) { load(data, loader) {
val placeholderColor = ColorUtils.setAlphaComponent(Color.GRAY, 0x1F) // 12% gray placeholder(ColorDrawable(context.getColor(R.color.cover_placeholder)))
placeholder(ColorDrawable(placeholderColor)) error(R.drawable.cover_error)
// Build the original request so we can add on our success listener // Build the original request so we can add on our success listener
val originalListener = apply(builder).build().listener val originalListener = apply(builder).build().listener

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidElementNotAllowed -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<item>
<color android:color="@color/cover_placeholder" />
</item>
<item
android:top="48dp"
android:bottom="48dp"
android:left="48dp"
android:right="48dp">
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/cover_placeholder"
android:pathData="M21,5v6.59l-2.29,-2.3c-0.39,-0.39 -1.03,-0.39 -1.42,0L14,12.59 10.71,9.3c-0.39,-0.39 -1.02,-0.39 -1.41,0L6,12.59 3,9.58L3,5c0,-1.1 0.9,-2 2,-2h14c1.1,0 2,0.9 2,2zM18,11.42l3,3.01L21,19c0,1.1 -0.9,2 -2,2L5,21c-1.1,0 -2,-0.9 -2,-2v-6.58l2.29,2.29c0.39,0.39 1.02,0.39 1.41,0l3.3,-3.3 3.29,3.29c0.39,0.39 1.02,0.39 1.41,0l3.3,-3.28z"/>
</vector>
</item>
</layer-list>

View file

@ -2,6 +2,8 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<color name="splash">@color/accent_blue</color> <color name="splash">@color/accent_blue</color>
<color name="cover_placeholder">#1F888888</color>
<color name="error">#BA1B1B</color> <color name="error">#BA1B1B</color>
<color name="errorContainer">#FFDAD4</color> <color name="errorContainer">#FFDAD4</color>
<color name="onError">#FFFFFF</color> <color name="onError">#FFFFFF</color>