diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 3d5d65d02..f20ace6ce 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -23,7 +23,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { private val authorPaint = TextPaint() private var name: String? = null private var author: String? = null - private var loadField = false + private var loadFailed = false constructor(context: Context) : super(context) @@ -85,7 +85,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { canvas.clipPath(path) } super.onDraw(canvas) - if (!loadField) return + if (!loadFailed) return name?.let { namePaint.color = Color.WHITE namePaint.style = Paint.Style.STROKE @@ -104,7 +104,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setText(name: String?, author: String?) { + fun setHeight(height: Int) { + val width = height * 5 / 7 + minimumWidth = width + } + + private fun setText(name: String?, author: String?) { this.name = when { name == null -> null @@ -119,11 +124,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setHeight(height: Int) { - val width = height * 5 / 7 - minimumWidth = width - } - fun load(path: String?, name: String?, author: String?) { setText(name, author) ImageLoader.load(context, path)//Glide自动识别http://和file:// @@ -136,7 +136,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { target: Target?, isFirstResource: Boolean ): Boolean { - loadField = true + loadFailed = true return false } @@ -147,7 +147,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { dataSource: DataSource?, isFirstResource: Boolean ): Boolean { - loadField = false + loadFailed = false return false }