pull/1738/head
kunfei 3 years ago
parent 77d35687e4
commit 7c8010c39a
  1. 7
      app/src/main/java/io/legado/app/help/BlurTransformation.kt
  2. 13
      app/src/main/java/io/legado/app/model/BookCover.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)

@ -63,11 +63,6 @@ object BookCover {
}.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null))
}
private fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> {
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<Drawable> {
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()
}
}

Loading…
Cancel
Save