优化
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user