mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
ad5bcf4145
commit
2e19bf6978
@ -2,6 +2,7 @@ package io.legado.app.ui.book.toc
|
||||
|
||||
import android.content.Context
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.RecyclerAdapter
|
||||
@ -16,6 +17,22 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
|
||||
|
||||
val cacheFileNames = hashSetOf<String>()
|
||||
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
|
||||
|
||||
override fun areItemsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean {
|
||||
return oldItem.index == newItem.index
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean {
|
||||
return oldItem.bookUrl == newItem.bookUrl
|
||||
&& oldItem.url == newItem.url
|
||||
&& oldItem.isVip == newItem.isVip
|
||||
&& oldItem.isPay == newItem.isPay
|
||||
&& oldItem.title == newItem.title
|
||||
&& oldItem.tag == newItem.tag
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding {
|
||||
return ItemChapterListBinding.inflate(inflater, parent, false)
|
||||
|
@ -112,7 +112,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
|
||||
searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl)
|
||||
else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey)
|
||||
}.collect {
|
||||
adapter.setItems(it)
|
||||
adapter.setItems(it, adapter.diffCallBack)
|
||||
if (searchKey.isNullOrBlank() && !scrollToDurChapter) {
|
||||
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
|
||||
scrollToDurChapter = true
|
||||
|
Loading…
Reference in New Issue
Block a user