|
|
@ -4,9 +4,15 @@ import android.annotation.SuppressLint |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Path |
|
|
|
import android.graphics.Path |
|
|
|
|
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.text.TextPaint |
|
|
|
import android.text.TextPaint |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.AttributeSet |
|
|
|
import io.legado.app.utils.dp |
|
|
|
import com.bumptech.glide.load.DataSource |
|
|
|
|
|
|
|
import com.bumptech.glide.load.engine.GlideException |
|
|
|
|
|
|
|
import com.bumptech.glide.request.RequestListener |
|
|
|
|
|
|
|
import com.bumptech.glide.request.target.Target |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
@ -26,16 +32,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
defStyleAttr |
|
|
|
defStyleAttr |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
textPaint.textSize = 13.dp.toFloat() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { |
|
|
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom) |
|
|
|
|
|
|
|
width = getWidth().toFloat() |
|
|
|
|
|
|
|
height = getHeight().toFloat() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { |
|
|
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { |
|
|
|
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) |
|
|
|
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) |
|
|
|
val measuredHeight = measuredWidth * 7 / 5 |
|
|
|
val measuredHeight = measuredWidth * 7 / 5 |
|
|
@ -45,6 +41,13 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { |
|
|
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom) |
|
|
|
|
|
|
|
width = getWidth().toFloat() |
|
|
|
|
|
|
|
height = getHeight().toFloat() |
|
|
|
|
|
|
|
textPaint.textSize = width / 9 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
if (width >= 10 && height > 10) { |
|
|
|
if (width >= 10 && height > 10) { |
|
|
|
@SuppressLint("DrawAllocation") |
|
|
|
@SuppressLint("DrawAllocation") |
|
|
@ -77,4 +80,38 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { |
|
|
|
val width = height * 5 / 7 |
|
|
|
val width = height * 5 / 7 |
|
|
|
minimumWidth = width |
|
|
|
minimumWidth = width |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun load(path: String?, name: String) { |
|
|
|
|
|
|
|
if (path.isNullOrEmpty()) { |
|
|
|
|
|
|
|
setName(name) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ImageLoader.load(context, path)//Glide自动识别http://和file:// |
|
|
|
|
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
|
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
|
|
|
|
.listener(object : RequestListener<Drawable> { |
|
|
|
|
|
|
|
override fun onLoadFailed( |
|
|
|
|
|
|
|
e: GlideException?, |
|
|
|
|
|
|
|
model: Any?, |
|
|
|
|
|
|
|
target: Target<Drawable>?, |
|
|
|
|
|
|
|
isFirstResource: Boolean |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
|
|
|
|
setName(name) |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onResourceReady( |
|
|
|
|
|
|
|
resource: Drawable?, |
|
|
|
|
|
|
|
model: Any?, |
|
|
|
|
|
|
|
target: Target<Drawable>?, |
|
|
|
|
|
|
|
dataSource: DataSource?, |
|
|
|
|
|
|
|
isFirstResource: Boolean |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.centerCrop() |
|
|
|
|
|
|
|
.into(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|