pull/1744/head
kunfei 3 years ago
parent 174e383d70
commit d97ede312d
  1. 25
      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)) }.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null))
} }
/**
* 加载封面
*/
fun load( fun load(
context: Context, context: Context,
path: String?, path: String?,
loadOnlyWifi: Boolean = false loadOnlyWifi: Boolean = false
): RequestBuilder<Drawable> { ): RequestBuilder<Drawable> {
return if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
ImageLoader.load(context, defaultDrawable) return ImageLoader.load(context, defaultDrawable)
.centerCrop() .centerCrop()
} else { }
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
ImageLoader.load(context, path) return ImageLoader.load(context, path)
.apply(options) .apply(options)
.placeholder(defaultDrawable) .placeholder(defaultDrawable)
.error(defaultDrawable) .error(defaultDrawable)
} .centerCrop()
} }
/**
* 加载模糊封面
*/
fun loadBlur( fun loadBlur(
context: Context, context: Context,
path: String?, path: String?,
@ -88,17 +94,16 @@ object BookCover {
): RequestBuilder<Drawable> { ): RequestBuilder<Drawable> {
val loadBlur = ImageLoader.load(context, defaultDrawable) val loadBlur = ImageLoader.load(context, defaultDrawable)
.transform(BlurTransformation(25), CenterCrop()) .transform(BlurTransformation(25), CenterCrop())
return if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
loadBlur return loadBlur
} else { }
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
ImageLoader.load(context, path) return ImageLoader.load(context, path)
.apply(options) .apply(options)
.transform(BlurTransformation(25), CenterCrop()) .transform(BlurTransformation(25), CenterCrop())
.transition(DrawableTransitionOptions.withCrossFade(1500)) .transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(loadBlur) .thumbnail(loadBlur)
} }
}
suspend fun searchCover(book: Book): String? { suspend fun searchCover(book: Book): String? {
val config = coverRuleConfig val config = coverRuleConfig

Loading…
Cancel
Save