From d97ede312d9b1a7e6f2aba51327ca2e469e2dfe6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 29 Mar 2022 08:51:48 +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/model/BookCover.kt | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) 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 73fe7bec9..ae8be52e5 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -64,23 +64,29 @@ object BookCover { }.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null)) } + /** + * 加载封面 + */ fun load( context: Context, path: String?, loadOnlyWifi: Boolean = false ): RequestBuilder { - return if (AppConfig.useDefaultCover) { - ImageLoader.load(context, defaultDrawable) + if (AppConfig.useDefaultCover) { + return ImageLoader.load(context, defaultDrawable) .centerCrop() - } else { - val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) - ImageLoader.load(context, path) - .apply(options) - .placeholder(defaultDrawable) - .error(defaultDrawable) } + val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) + return ImageLoader.load(context, path) + .apply(options) + .placeholder(defaultDrawable) + .error(defaultDrawable) + .centerCrop() } + /** + * 加载模糊封面 + */ fun loadBlur( context: Context, path: String?, @@ -88,16 +94,15 @@ object BookCover { ): RequestBuilder { val loadBlur = ImageLoader.load(context, defaultDrawable) .transform(BlurTransformation(25), CenterCrop()) - return if (AppConfig.useDefaultCover) { - loadBlur - } else { - val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) - ImageLoader.load(context, path) - .apply(options) - .transform(BlurTransformation(25), CenterCrop()) - .transition(DrawableTransitionOptions.withCrossFade(1500)) - .thumbnail(loadBlur) + if (AppConfig.useDefaultCover) { + return loadBlur } + val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) + return ImageLoader.load(context, path) + .apply(options) + .transform(BlurTransformation(25), CenterCrop()) + .transition(DrawableTransitionOptions.withCrossFade(1500)) + .thumbnail(loadBlur) } suspend fun searchCover(book: Book): String? {