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