pull/84/head
kunfei 5 years ago
parent 303d234ece
commit da891e1227
  1. 16
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  3. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  4. 59
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt

@ -106,11 +106,6 @@ class BookInfoActivity :
return super.onMenuOpened(featureId, menu)
}
private fun defaultCover(): RequestBuilder<Drawable> {
return ImageLoader.load(this, R.drawable.image_cover_default)
.apply(bitmapTransform(BlurTransformation(this, 25)))
}
private fun showBook(book: Book) {
showCover(book)
tv_name.text = book.name
@ -152,17 +147,18 @@ class BookInfoActivity :
}
private fun showCover(book: Book) {
book.getDisplayCover()?.let {
ImageLoader.load(this, it)
.centerCrop()
.into(iv_cover)
ImageLoader.load(this, it)
iv_cover.load(book.getDisplayCover(), book.name)
ImageLoader.load(this, book.getDisplayCover())
.transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(defaultCover())
.centerCrop()
.apply(bitmapTransform(BlurTransformation(this, 25)))
.into(bg_book) //模糊、渐变、缩小效果
}
private fun defaultCover(): RequestBuilder<Drawable> {
return ImageLoader.load(this, R.drawable.image_cover_default)
.apply(bitmapTransform(BlurTransformation(this, 25)))
}
private fun showChapter(chapterList: List<BookChapter>) {

@ -5,7 +5,6 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.*
@ -21,13 +20,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
ATH.applyBackgroundTint(this)
tv_name.text = item.name
bv_author.text = item.author
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
iv_cover.load(item.getDisplayCover(), item.name)
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)

@ -5,7 +5,6 @@ import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
@ -23,13 +22,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
tv_author.text = item.author
tv_read.text = item.durChapterTitle
tv_last.text = item.latestChapterTitle
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
iv_cover.load(item.getDisplayCover(), item.name)
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)

@ -4,9 +4,15 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.graphics.drawable.Drawable
import android.text.TextPaint
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 {
@ -26,16 +32,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
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) {
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec)
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) {
if (width >= 10 && height > 10) {
@SuppressLint("DrawAllocation")
@ -77,4 +80,38 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
val width = height * 5 / 7
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)
}
}
}

Loading…
Cancel
Save