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) 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) { private fun showBook(book: Book) {
showCover(book) showCover(book)
tv_name.text = book.name tv_name.text = book.name
@ -152,17 +147,18 @@ class BookInfoActivity :
} }
private fun showCover(book: Book) { private fun showCover(book: Book) {
book.getDisplayCover()?.let { iv_cover.load(book.getDisplayCover(), book.name)
ImageLoader.load(this, it) ImageLoader.load(this, book.getDisplayCover())
.centerCrop()
.into(iv_cover)
ImageLoader.load(this, it)
.transition(DrawableTransitionOptions.withCrossFade(1500)) .transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(defaultCover()) .thumbnail(defaultCover())
.centerCrop() .centerCrop()
.apply(bitmapTransform(BlurTransformation(this, 25))) .apply(bitmapTransform(BlurTransformation(this, 25)))
.into(bg_book) //模糊、渐变、缩小效果 .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>) { 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.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* import kotlinx.android.synthetic.main.item_bookshelf_grid.view.*
@ -21,13 +20,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
tv_name.text = item.name tv_name.text = item.name
bv_author.text = item.author bv_author.text = item.author
item.getDisplayCover()?.let { iv_cover.load(item.getDisplayCover(), item.name)
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
onClick { callBack.open(item) } onClick { callBack.open(item) }
onLongClick { onLongClick {
callBack.openBookInfo(item) callBack.openBookInfo(item)

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

@ -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)
}
}
} }

Loading…
Cancel
Save