pull/84/head
kunfei 5 years ago
parent b9f37c2601
commit 5987b2c2e2
  1. 20
      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 val authorPaint = TextPaint()
private var name: String? = null private var name: String? = null
private var author: String? = null private var author: String? = null
private var loadField = false private var loadFailed = false
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@ -85,7 +85,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
canvas.clipPath(path) canvas.clipPath(path)
} }
super.onDraw(canvas) super.onDraw(canvas)
if (!loadField) return if (!loadFailed) return
name?.let { name?.let {
namePaint.color = Color.WHITE namePaint.color = Color.WHITE
namePaint.style = Paint.Style.STROKE 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 = this.name =
when { when {
name == null -> null 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?) { fun load(path: String?, name: String?, author: String?) {
setText(name, author) setText(name, author)
ImageLoader.load(context, path)//Glide自动识别http://和file:// ImageLoader.load(context, path)//Glide自动识别http://和file://
@ -136,7 +136,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
target: Target<Drawable>?, target: Target<Drawable>?,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
loadField = true loadFailed = true
return false return false
} }
@ -147,7 +147,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
dataSource: DataSource?, dataSource: DataSource?,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
loadField = false loadFailed = false
return false return false
} }

Loading…
Cancel
Save