自定义默认封面

pull/276/head
gedoor 4 years ago
parent a15cd5a78a
commit 8d995f8246
  1. 15
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt

@ -92,7 +92,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
canvas.clipPath(path)
}
super.onDraw(canvas)
if (!loadFailed) return
if (!loadFailed || !showBookName) return
name?.let {
namePaint.color = Color.WHITE
namePaint.style = Paint.Style.STROKE
@ -164,7 +164,8 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
}
companion object {
lateinit var defaultDrawable: Drawable
private var showBookName = false
private lateinit var defaultDrawable: Drawable
init {
upDefaultCover()
@ -172,8 +173,14 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
fun upDefaultCover() {
val path = App.INSTANCE.getPrefString(PreferKey.defaultCover)
defaultDrawable = Drawable.createFromPath(path)
?: App.INSTANCE.resources.getDrawable(R.drawable.image_cover_default, null)
var dw = Drawable.createFromPath(path)
if (dw == null) {
showBookName = true
dw = App.INSTANCE.resources.getDrawable(R.drawable.image_cover_default, null)
} else {
showBookName = false
}
defaultDrawable = dw!!
}
}

Loading…
Cancel
Save