diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 323dbfc05..c8c546e82 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -35,7 +35,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : item: SearchBook, payloads: MutableList ) = binding.run { - ivCover.load(item.coverUrl, item.name, item.author) + ivCover.load(item.coverUrl) tvSource.text = item.originName } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index 99d6b9285..d4f7cc10f 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -42,7 +42,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : llKind.visible() llKind.setLabels(kinds) } - ivCover.load(item.coverUrl, item.name, item.author) + ivCover.load(item.coverUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index d7743a4ac..b39626e94 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -204,7 +204,7 @@ class BookInfoActivity : } private fun showCover(book: Book) { - binding.ivCover.load(book.getDisplayCover(), book.name, book.author) + binding.ivCover.load(book.getDisplayCover()) ImageLoader.load(this, book.getDisplayCover()) .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 8d6ca1099..bf976e303 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -77,7 +77,7 @@ class BookInfoEditActivity : private fun upCover() { viewModel.book.let { - binding.ivCover.load(it?.getDisplayCover(), it?.name, it?.author) + binding.ivCover.load(it?.getDisplayCover()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index e36c11fe1..c54d293ec 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -81,7 +81,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : upLasted(binding, searchBook.latestChapterTitle) tvIntroduce.text = searchBook.trimIntro(context) 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) "intro" -> tvIntroduce.text = searchBook.trimIntro(context) "kind" -> upKind(binding, searchBook.getKindList()) - "cover" -> ivCover.load( - searchBook.coverUrl, - searchBook.name, - searchBook.author - ) + "cover" -> ivCover.load(searchBook.coverUrl) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt index b029e5eed..eedcbbfac 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt @@ -27,13 +27,13 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { tvName.text = item.name - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover()) upRefresh(binding, item) } else { bundle.keySet().forEach { when (it) { "name" -> tvName.text = item.name - "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author) + "cover" -> ivCover.load(item.getDisplayCover()) "refresh" -> upRefresh(binding, item) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt index 813ead01b..39604b9dd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt @@ -30,7 +30,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : tvAuthor.text = item.author tvRead.text = item.durChapterTitle tvLast.text = item.latestChapterTitle - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover()) upRefresh(binding, item) } else { tvRead.text = item.durChapterTitle @@ -39,7 +39,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : when (it) { "name" -> tvName.text = item.name "author" -> tvAuthor.text = item.author - "cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author) + "cover" -> ivCover.load(item.getDisplayCover()) "refresh" -> upRefresh(binding, item) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt index aec465be4..664bc4d21 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt @@ -71,11 +71,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) : bundle.keySet().forEach { when (it) { "name" -> tvName.text = item.name - "cover" -> ivCover.load( - item.getDisplayCover(), - item.name, - item.author - ) + "cover" -> ivCover.load(item.getDisplayCover()) "refresh" -> upRefresh(this, item) } } @@ -110,7 +106,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) : val item = callBack.getItem(position) if (item is Book) { tvName.text = item.name - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover()) upRefresh(this, item) } root.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt index 98c0cd6be..95d673c50 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt @@ -72,11 +72,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) : when (it) { "name" -> tvName.text = item.name "author" -> tvAuthor.text = item.author - "cover" -> ivCover.load( - item.getDisplayCover(), - item.name, - item.author - ) + "cover" -> ivCover.load(item.getDisplayCover()) "refresh" -> upRefresh(this, item) } } @@ -121,7 +117,7 @@ class BooksAdapterList(context: Context, callBack: CallBack) : tvAuthor.text = item.author tvRead.text = item.durChapterTitle tvLast.text = item.latestChapterTitle - ivCover.load(item.getDisplayCover(), item.name, item.author) + ivCover.load(item.getDisplayCover()) flHasNew.visible() ivAuthor.visible() ivLast.visible() diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 0105fe933..58a4ddcb6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -2,14 +2,10 @@ package io.legado.app.ui.widget.image import android.annotation.SuppressLint import android.content.Context -import android.graphics.* +import android.graphics.Canvas +import android.graphics.Path import android.graphics.drawable.Drawable -import android.text.TextPaint 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.constant.PreferKey import io.legado.app.help.AppConfig @@ -32,27 +28,7 @@ class CoverImageView @JvmOverloads constructor( internal var height: Float = 0.toFloat() var path: String? = null 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) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) @@ -67,13 +43,6 @@ class CoverImageView @JvmOverloads constructor( super.onLayout(changed, left, top, right, bottom) width = getWidth().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) { @@ -94,23 +63,6 @@ class CoverImageView @JvmOverloads constructor( canvas.clipPath(path) } 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) { @@ -118,24 +70,8 @@ class CoverImageView @JvmOverloads constructor( minimumWidth = width } - private fun setText(name: String?, author: String?) { - 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) { + fun load(path: String? = null) { this.path = path - setText(name, author) if (AppConfig.useDefaultCover) { ImageLoader.load(context, defaultDrawable) .centerCrop() @@ -144,29 +80,6 @@ class CoverImageView @JvmOverloads constructor( ImageLoader.load(context, path)//Glide自动识别http://,content://和file:// .placeholder(defaultDrawable) .error(defaultDrawable) - .listener(object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target?, - isFirstResource: Boolean - ): Boolean { - loadFailed = true - return false - } - - override fun onResourceReady( - resource: Drawable?, - model: Any?, - target: Target?, - dataSource: DataSource?, - isFirstResource: Boolean - ): Boolean { - loadFailed = false - return false - } - - }) .centerCrop() .into(this) } diff --git a/app/src/main/res/drawable/image_cover_default.jpg b/app/src/main/res/drawable/image_cover_default.jpg deleted file mode 100644 index 0b502033c..000000000 Binary files a/app/src/main/res/drawable/image_cover_default.jpg and /dev/null differ diff --git a/app/src/main/res/drawable/image_cover_default.png b/app/src/main/res/drawable/image_cover_default.png new file mode 100644 index 000000000..3845eb9c7 Binary files /dev/null and b/app/src/main/res/drawable/image_cover_default.png differ