From 7c8010c39a477adb47e68143b96aee08a4a83b8d Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 18 Mar 2022 14:56:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/BlurTransformation.kt | 7 ++++++- app/src/main/java/io/legado/app/model/BookCover.kt | 13 +++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BlurTransformation.kt b/app/src/main/java/io/legado/app/help/BlurTransformation.kt index af4ab506a..e1cdeb880 100644 --- a/app/src/main/java/io/legado/app/help/BlurTransformation.kt +++ b/app/src/main/java/io/legado/app/help/BlurTransformation.kt @@ -8,6 +8,7 @@ import android.renderscript.Allocation import android.renderscript.Element import android.renderscript.RenderScript import android.renderscript.ScriptIntrinsicBlur +import androidx.annotation.IntRange import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool import com.bumptech.glide.load.resource.bitmap.CenterCrop import java.security.MessageDigest @@ -19,7 +20,11 @@ import kotlin.math.roundToInt * 模糊 * @radius: 0..25 */ -class BlurTransformation(context: Context, private val radius: Int) : CenterCrop() { +class BlurTransformation( + context: Context, + @IntRange(from = 0, to = 25) private val radius: Int +) : CenterCrop() { + private val rs: RenderScript = RenderScript.create(context) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) diff --git a/app/src/main/java/io/legado/app/model/BookCover.kt b/app/src/main/java/io/legado/app/model/BookCover.kt index 28123aa39..cca002aaf 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -63,11 +63,6 @@ object BookCover { }.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null)) } - private fun getBlurDefaultCover(context: Context): RequestBuilder { - return ImageLoader.load(context, defaultDrawable) - .apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25))) - } - fun load( context: Context, path: String?, @@ -90,16 +85,18 @@ object BookCover { path: String?, loadOnlyWifi: Boolean = false ): RequestBuilder { + val loadBlur = ImageLoader.load(context, defaultDrawable) + .apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25))) return if (AppConfig.useDefaultCover) { - getBlurDefaultCover(context) - .centerCrop() + loadBlur.centerCrop() } else { val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) ImageLoader.load(context, path) .apply(options) .transition(DrawableTransitionOptions.withCrossFade(1500)) - .thumbnail(getBlurDefaultCover(context)) + .thumbnail(loadBlur) .apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25))) + .centerCrop() } }