更换默认封面,去除封面文字

pull/1319/head
gedoor 3 years ago
parent fc9bfe5395
commit ba88464266
  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. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  5. 8
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  6. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt
  7. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt
  8. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt
  9. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt
  10. 95
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt
  11. BIN
      app/src/main/res/drawable/image_cover_default.jpg
  12. BIN
      app/src/main/res/drawable/image_cover_default.png

@ -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, item.name, item.author) ivCover.load(item.coverUrl)
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, item.name, item.author) ivCover.load(item.coverUrl)
} }
} }

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

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

@ -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, searchBook.name, searchBook.author) ivCover.load(searchBook.coverUrl)
} }
} }
@ -94,11 +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( "cover" -> ivCover.load(searchBook.coverUrl)
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(), item.name, item.author) ivCover.load(item.getDisplayCover())
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(), item.name, item.author) "cover" -> ivCover.load(item.getDisplayCover())
"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(), item.name, item.author) ivCover.load(item.getDisplayCover())
upRefresh(binding, item) upRefresh(binding, item)
} else { } else {
tvRead.text = item.durChapterTitle tvRead.text = item.durChapterTitle
@ -39,7 +39,7 @@ class BooksAdapterList(context: Context, private val 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(), item.name, item.author) "cover" -> ivCover.load(item.getDisplayCover())
"refresh" -> upRefresh(binding, item) "refresh" -> upRefresh(binding, item)
} }
} }

@ -71,11 +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( "cover" -> ivCover.load(item.getDisplayCover())
item.getDisplayCover(),
item.name,
item.author
)
"refresh" -> upRefresh(this, item) "refresh" -> upRefresh(this, item)
} }
} }
@ -110,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(), item.name, item.author) ivCover.load(item.getDisplayCover())
upRefresh(this, item) upRefresh(this, item)
} }
root.setOnClickListener { root.setOnClickListener {

@ -72,11 +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( "cover" -> ivCover.load(item.getDisplayCover())
item.getDisplayCover(),
item.name,
item.author
)
"refresh" -> upRefresh(this, item) "refresh" -> upRefresh(this, item)
} }
} }
@ -121,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(), item.name, item.author) ivCover.load(item.getDisplayCover())
flHasNew.visible() flHasNew.visible()
ivAuthor.visible() ivAuthor.visible()
ivLast.visible() ivLast.visible()

@ -2,14 +2,10 @@ 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.* import android.graphics.Canvas
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.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -32,27 +28,7 @@ class CoverImageView @JvmOverloads constructor(
internal var height: Float = 0.toFloat() internal var height: Float = 0.toFloat()
var path: String? = null var path: String? = null
private set private set
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
}
private var name: String? = null
private var author: String? = null
private var loadFailed = false
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredWidth = MeasureSpec.getSize(widthMeasureSpec)
@ -67,13 +43,6 @@ 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()
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) {
@ -94,23 +63,6 @@ class CoverImageView @JvmOverloads constructor(
canvas.clipPath(path) canvas.clipPath(path)
} }
super.onDraw(canvas) super.onDraw(canvas)
if (!loadFailed || !showBookName) return
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) {
@ -118,24 +70,8 @@ class CoverImageView @JvmOverloads constructor(
minimumWidth = width minimumWidth = width
} }
private fun setText(name: String?, author: String?) { fun load(path: String? = null) {
this.name =
when {
name == null -> null
name.length > 5 -> name.substring(0, 4) + ""
else -> name
}
this.author =
when {
author == null -> null
author.length > 8 -> author.substring(0, 7) + ""
else -> author
}
}
fun load(path: String? = null, name: String? = null, author: String? = null) {
this.path = path this.path = path
setText(name, author)
if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
ImageLoader.load(context, defaultDrawable) ImageLoader.load(context, defaultDrawable)
.centerCrop() .centerCrop()
@ -144,29 +80,6 @@ class CoverImageView @JvmOverloads constructor(
ImageLoader.load(context, path)//Glide自动识别http://,content://和file:// ImageLoader.load(context, path)//Glide自动识别http://,content://和file://
.placeholder(defaultDrawable) .placeholder(defaultDrawable)
.error(defaultDrawable) .error(defaultDrawable)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
loadFailed = true
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
loadFailed = false
return false
}
})
.centerCrop() .centerCrop()
.into(this) .into(this)
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Loading…
Cancel
Save