pull/84/head
kunfei 5 years ago
parent 40a8c6f174
commit 501a9273dc
  1. 10
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt

@ -23,6 +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
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@ -84,6 +85,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
canvas.clipPath(path) canvas.clipPath(path)
} }
super.onDraw(canvas) super.onDraw(canvas)
if (!loadField) return
name?.let { name?.let {
namePaint.color = Color.WHITE namePaint.color = Color.WHITE
namePaint.style = Paint.Style.STROKE namePaint.style = Paint.Style.STROKE
@ -102,7 +104,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
} }
} }
fun setName(name: String?, author: String?) { fun setText(name: String?, author: String?) {
this.name = this.name =
when { when {
name == null -> null name == null -> null
@ -115,7 +117,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
author.length > 8 -> author.substring(0, 7) + "" author.length > 8 -> author.substring(0, 7) + ""
else -> author else -> author
} }
invalidate()
} }
fun setHeight(height: Int) { fun setHeight(height: Int) {
@ -124,6 +125,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
} }
fun load(path: String?, name: String?, author: String?) { fun load(path: String?, name: String?, author: String?) {
setText(name, author)
ImageLoader.load(context, path)//Glide自动识别http://和file:// ImageLoader.load(context, path)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default) .placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default) .error(R.drawable.image_cover_default)
@ -134,7 +136,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
target: Target<Drawable>?, target: Target<Drawable>?,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
setName(name, author) loadField = true
return false return false
} }
@ -145,7 +147,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
dataSource: DataSource?, dataSource: DataSource?,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
setName(null, null) loadField = false
return false return false
} }

Loading…
Cancel
Save