mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
9e2ef90337
commit
5df6c303ad
@ -1,34 +0,0 @@
|
||||
package io.legado.app.ui.main.explore
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import io.legado.app.data.entities.BookSource
|
||||
|
||||
|
||||
class ExploreDiffCallBack(
|
||||
private val oldItems: List<BookSource>,
|
||||
private val newItems: List<BookSource>
|
||||
) :
|
||||
DiffUtil.Callback() {
|
||||
|
||||
override fun getOldListSize(): Int {
|
||||
return oldItems.size
|
||||
}
|
||||
|
||||
override fun getNewListSize(): Int {
|
||||
return newItems.size
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
val oldItem = oldItems[oldItemPosition]
|
||||
val newItem = newItems[newItemPosition]
|
||||
if (oldItem.bookSourceName != newItem.bookSourceName) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package io.legado.app.ui.main.explore
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import io.legado.app.data.entities.BookSource
|
||||
|
||||
|
||||
class ExploreDiffItemCallBack : DiffUtil.ItemCallback<BookSource>() {
|
||||
|
||||
override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
|
||||
if (oldItem.bookSourceName != newItem.bookSourceName) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,6 @@ import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.isGone
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legado.app.R
|
||||
@ -128,10 +127,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
|
||||
}
|
||||
exploreFlow.collect {
|
||||
binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty()
|
||||
val diffResult = DiffUtil
|
||||
.calculateDiff(ExploreDiffCallBack(ArrayList(adapter.getItems()), it))
|
||||
adapter.setItems(it)
|
||||
diffResult.dispatchUpdatesTo(adapter)
|
||||
adapter.setItems(it, ExploreDiffItemCallBack())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user