pull/1333/head
gedoor 3 years ago
parent 155f969ef3
commit c89f2fd7e0
  1. 2
      app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  7. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt
  8. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt
  9. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt
  10. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt
  11. 106
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt

@ -35,7 +35,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) :
item: SearchBook, item: SearchBook,
payloads: MutableList<Any> payloads: MutableList<Any>
) = binding.run { ) = binding.run {
ivCover.load(item.coverUrl) ivCover.load(item.coverUrl, item.name, item.author)
tvSource.text = item.originName tvSource.text = item.originName
} }

@ -42,7 +42,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
llKind.visible() llKind.visible()
llKind.setLabels(kinds) llKind.setLabels(kinds)
} }
ivCover.load(item.coverUrl) ivCover.load(item.coverUrl, item.name, item.author)
} }
} }

@ -77,12 +77,12 @@ class GroupEditDialog() : BaseDialogFragment() {
} else { } else {
bookGroup?.let { bookGroup?.let {
it.groupName = groupName it.groupName = groupName
it.cover = binding.ivCover.path it.cover = binding.ivCover.bitmapPath
viewModel.upGroup(it) { viewModel.upGroup(it) {
dismiss() dismiss()
} }
} ?: let { } ?: let {
viewModel.addGroup(groupName, binding.ivCover.path) { viewModel.addGroup(groupName, binding.ivCover.bitmapPath) {
dismiss() dismiss()
} }
} }

@ -207,7 +207,7 @@ class BookInfoActivity :
} }
private fun showCover(book: Book) { private fun showCover(book: Book) {
binding.ivCover.load(book.getDisplayCover()) binding.ivCover.load(book.getDisplayCover(), book.name, book.author)
ImageLoader.load(this, book.getDisplayCover()) ImageLoader.load(this, book.getDisplayCover())
.transition(DrawableTransitionOptions.withCrossFade(1500)) .transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(defaultCover()) .thumbnail(defaultCover())

@ -76,7 +76,7 @@ class BookInfoEditActivity :
private fun upCover() { private fun upCover() {
viewModel.book.let { viewModel.book.let {
binding.ivCover.load(it?.getDisplayCover()) binding.ivCover.load(it?.getDisplayCover(), it?.name, it?.author)
} }
} }

@ -81,7 +81,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
upLasted(binding, searchBook.latestChapterTitle) upLasted(binding, searchBook.latestChapterTitle)
tvIntroduce.text = searchBook.trimIntro(context) tvIntroduce.text = searchBook.trimIntro(context)
upKind(binding, searchBook.getKindList()) upKind(binding, searchBook.getKindList())
ivCover.load(searchBook.coverUrl) ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author)
} }
} }
@ -94,7 +94,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
"last" -> upLasted(binding, searchBook.latestChapterTitle) "last" -> upLasted(binding, searchBook.latestChapterTitle)
"intro" -> tvIntroduce.text = searchBook.trimIntro(context) "intro" -> tvIntroduce.text = searchBook.trimIntro(context)
"kind" -> upKind(binding, searchBook.getKindList()) "kind" -> upKind(binding, searchBook.getKindList())
"cover" -> ivCover.load(searchBook.coverUrl) "cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author)
} }
} }
} }

@ -27,13 +27,13 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
val bundle = payloads.getOrNull(0) as? Bundle val bundle = payloads.getOrNull(0) as? Bundle
if (bundle == null) { if (bundle == null) {
tvName.text = item.name tvName.text = item.name
ivCover.load(item.getDisplayCover()) ivCover.load(item.getDisplayCover(), item.name, item.author)
upRefresh(binding, item) upRefresh(binding, item)
} else { } else {
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
"cover" -> ivCover.load(item.getDisplayCover()) "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"refresh" -> upRefresh(binding, item) "refresh" -> upRefresh(binding, item)
} }
} }

@ -30,7 +30,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
tvAuthor.text = item.author tvAuthor.text = item.author
tvRead.text = item.durChapterTitle tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle tvLast.text = item.latestChapterTitle
ivCover.load(item.getDisplayCover()) ivCover.load(item.getDisplayCover(), item.name, item.author)
upRefresh(binding, item) upRefresh(binding, item)
} else { } else {
tvRead.text = item.durChapterTitle tvRead.text = item.durChapterTitle

@ -71,7 +71,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
"cover" -> ivCover.load(item.getDisplayCover()) "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"refresh" -> upRefresh(this, item) "refresh" -> upRefresh(this, item)
} }
} }
@ -106,7 +106,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
val item = callBack.getItem(position) val item = callBack.getItem(position)
if (item is Book) { if (item is Book) {
tvName.text = item.name tvName.text = item.name
ivCover.load(item.getDisplayCover()) ivCover.load(item.getDisplayCover(), item.name, item.author)
upRefresh(this, item) upRefresh(this, item)
} }
root.setOnClickListener { root.setOnClickListener {

@ -72,7 +72,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
when (it) { when (it) {
"name" -> tvName.text = item.name "name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author "author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(item.getDisplayCover()) "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author)
"refresh" -> upRefresh(this, item) "refresh" -> upRefresh(this, item)
} }
} }
@ -117,7 +117,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
tvAuthor.text = item.author tvAuthor.text = item.author
tvRead.text = item.durChapterTitle tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle tvLast.text = item.latestChapterTitle
ivCover.load(item.getDisplayCover()) ivCover.load(item.getDisplayCover(), item.name, item.author)
flHasNew.visible() flHasNew.visible()
ivAuthor.visible() ivAuthor.visible()
ivLast.visible() ivLast.visible()

@ -2,9 +2,9 @@ package io.legado.app.ui.widget.image
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Canvas import android.graphics.*
import android.graphics.Path
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.text.TextPaint
import android.util.AttributeSet import android.util.AttributeSet
import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.load.engine.GlideException
@ -29,11 +29,32 @@ class CoverImageView @JvmOverloads constructor(
context, context,
attrs attrs
) { ) {
internal var width: Float = 0.toFloat() private var filletPath = Path()
internal var height: Float = 0.toFloat() private var width: Float = 0.toFloat()
var path: String? = null private var height: Float = 0.toFloat()
private set
private var defaultCover = true private var defaultCover = true
var bitmapPath: String? = null
private set
private var name: String? = null
private var author: String? = null
private var nameHeight = 0f
private var authorHeight = 0f
private val namePaint by lazy {
val textPaint = TextPaint()
textPaint.typeface = Typeface.DEFAULT_BOLD
textPaint.isAntiAlias = true
textPaint.textAlign = Paint.Align.CENTER
textPaint.textSkewX = -0.2f
textPaint
}
private val authorPaint by lazy {
val textPaint = TextPaint()
textPaint.typeface = Typeface.DEFAULT
textPaint.isAntiAlias = true
textPaint.textAlign = Paint.Align.CENTER
textPaint.textSkewX = -0.1f
textPaint
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredWidth = MeasureSpec.getSize(widthMeasureSpec)
@ -48,26 +69,57 @@ class CoverImageView @JvmOverloads constructor(
super.onLayout(changed, left, top, right, bottom) super.onLayout(changed, left, top, right, bottom)
width = getWidth().toFloat() width = getWidth().toFloat()
height = getHeight().toFloat() height = getHeight().toFloat()
filletPath.reset()
if (width > 10 && height > 10) {
filletPath.apply {
moveTo(10f, 0f)
lineTo(width - 10, 0f)
quadTo(width, 0f, width, 10f)
lineTo(width, height - 10)
quadTo(width, height, width - 10, height)
lineTo(10f, height)
quadTo(0f, height, 0f, height - 10)
lineTo(0f, 10f)
quadTo(0f, 0f, 10f, 0f)
close()
}
}
namePaint.textSize = width / 6
namePaint.strokeWidth = namePaint.textSize / 10
authorPaint.textSize = width / 9
authorPaint.strokeWidth = authorPaint.textSize / 10
val fm = namePaint.fontMetrics
nameHeight = height * 0.5f + (fm.bottom - fm.top) * 0.5f
authorHeight = nameHeight + (fm.bottom - fm.top) * 0.6f
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
if (width >= 10 && height > 10) { if (!filletPath.isEmpty) {
@SuppressLint("DrawAllocation") canvas.clipPath(filletPath)
val path = Path()
//四个圆角
path.moveTo(10f, 0f)
path.lineTo(width - 10, 0f)
path.quadTo(width, 0f, width, 10f)
path.lineTo(width, height - 10)
path.quadTo(width, height, width - 10, height)
path.lineTo(10f, height)
path.quadTo(0f, height, 0f, height - 10)
path.lineTo(0f, 10f)
path.quadTo(0f, 0f, 10f, 0f)
canvas.clipPath(path)
} }
super.onDraw(canvas) super.onDraw(canvas)
if (defaultCover && drawBookName) {
drawName(canvas)
}
}
private fun drawName(canvas: Canvas) {
name?.let {
namePaint.color = Color.WHITE
namePaint.style = Paint.Style.STROKE
canvas.drawText(it, width / 2, nameHeight, namePaint)
namePaint.color = Color.RED
namePaint.style = Paint.Style.FILL
canvas.drawText(it, width / 2, nameHeight, namePaint)
}
author?.let {
authorPaint.color = Color.WHITE
authorPaint.style = Paint.Style.STROKE
canvas.drawText(it, width / 2, authorHeight, authorPaint)
authorPaint.color = Color.RED
authorPaint.style = Paint.Style.FILL
canvas.drawText(it, width / 2, authorHeight, authorPaint)
}
} }
fun setHeight(height: Int) { fun setHeight(height: Int) {
@ -102,8 +154,10 @@ class CoverImageView @JvmOverloads constructor(
} }
} }
fun load(path: String? = null) { fun load(path: String? = null, name: String? = null, author: String? = null) {
this.path = path this.bitmapPath = path
this.name = name
this.author = author
if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
ImageLoader.load(context, defaultDrawable) ImageLoader.load(context, defaultDrawable)
.centerCrop() .centerCrop()
@ -119,7 +173,7 @@ class CoverImageView @JvmOverloads constructor(
} }
companion object { companion object {
private var showBookName = true private var drawBookName = true
lateinit var defaultDrawable: Drawable lateinit var defaultDrawable: Drawable
init { init {
@ -134,10 +188,10 @@ class CoverImageView @JvmOverloads constructor(
defaultDrawable = Drawable.createFromPath(path)?.let { defaultDrawable = Drawable.createFromPath(path)?.let {
val showNameKey = if (isNightTheme) PreferKey.defaultCoverDarkShowName val showNameKey = if (isNightTheme) PreferKey.defaultCoverDarkShowName
else PreferKey.defaultCoverShowName else PreferKey.defaultCoverShowName
showBookName = appCtx.getPrefBoolean(showNameKey) drawBookName = appCtx.getPrefBoolean(showNameKey)
return@let it return@let it
} ?: let { } ?: let {
showBookName = true drawBookName = true
return@let appCtx.resources.getDrawable(R.drawable.image_cover_default, null) return@let appCtx.resources.getDrawable(R.drawable.image_cover_default, null)
} }
} }

Loading…
Cancel
Save