mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
9ffbf1f6aa
commit
3a12c08e83
@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf.style1.books
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.databinding.ItemBookshelfListBinding
|
||||
@ -12,7 +13,11 @@ import io.legado.app.utils.invisible
|
||||
import io.legado.app.utils.toTimeAgo
|
||||
import splitties.views.onLongClick
|
||||
|
||||
class BooksAdapterList(context: Context, private val callBack: CallBack) :
|
||||
class BooksAdapterList(
|
||||
context: Context,
|
||||
private val callBack: CallBack,
|
||||
private val lifecycle: Lifecycle
|
||||
) :
|
||||
BaseBooksAdapter<ItemBookshelfListBinding>(context) {
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemBookshelfListBinding {
|
||||
@ -41,7 +46,15 @@ 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, false, item.origin)
|
||||
"cover" -> ivCover.load(
|
||||
item.getDisplayCover(),
|
||||
item.name,
|
||||
item.author,
|
||||
false,
|
||||
item.origin,
|
||||
lifecycle
|
||||
)
|
||||
|
||||
"refresh" -> upRefresh(binding, item)
|
||||
"lastUpdateTime" -> upLastUpdateTime(binding, item)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
private val bookshelfLayout by lazy { AppConfig.bookshelfLayout }
|
||||
private val booksAdapter: BaseBooksAdapter<*> by lazy {
|
||||
if (bookshelfLayout == 0) {
|
||||
BooksAdapterList(requireContext(), this)
|
||||
BooksAdapterList(requireContext(), this, lifecycle)
|
||||
} else {
|
||||
BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.graphics.Typeface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextPaint
|
||||
import android.util.AttributeSet
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.bumptech.glide.load.DataSource
|
||||
import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
@ -180,7 +181,8 @@ class CoverImageView @JvmOverloads constructor(
|
||||
name: String? = null,
|
||||
author: String? = null,
|
||||
loadOnlyWifi: Boolean = false,
|
||||
sourceOrigin: String? = null
|
||||
sourceOrigin: String? = null,
|
||||
lifecycle: Lifecycle? = null
|
||||
) {
|
||||
this.bitmapPath = path
|
||||
this.name = name?.replace(AppPattern.bdRegex, "")?.trim()
|
||||
@ -195,8 +197,12 @@ class CoverImageView @JvmOverloads constructor(
|
||||
if (sourceOrigin != null) {
|
||||
options = options.set(OkHttpModelLoader.sourceOriginOption, sourceOrigin)
|
||||
}
|
||||
ImageLoader.load(context, path)//Glide自动识别http://,content://和file://
|
||||
.apply(options)
|
||||
val builder = if (lifecycle != null) {
|
||||
ImageLoader.load(lifecycle, path)
|
||||
} else {
|
||||
ImageLoader.load(context, path)//Glide自动识别http://,content://和file://
|
||||
}
|
||||
builder.apply(options)
|
||||
.placeholder(BookCover.defaultDrawable)
|
||||
.error(BookCover.defaultDrawable)
|
||||
.listener(glideListener)
|
||||
|
@ -8,8 +8,6 @@ import com.bumptech.glide.RequestManager
|
||||
fun RequestManager.lifecycle(lifecycle: Lifecycle): RequestManager {
|
||||
|
||||
val observer = object : DefaultLifecycleObserver {
|
||||
override fun onStart(owner: LifecycleOwner) = onStart()
|
||||
override fun onStop(owner: LifecycleOwner) = onStop()
|
||||
override fun onResume(owner: LifecycleOwner) = onStart()
|
||||
override fun onPause(owner: LifecycleOwner) = onStop()
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
|
Loading…
Reference in New Issue
Block a user