diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 1a062b4ce..6132ca3dd 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.changecover import android.content.Context import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook @@ -11,6 +12,19 @@ import org.jetbrains.anko.sdk27.listeners.onClick class CoverAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context) { + override val diffItemCallback: DiffUtil.ItemCallback + get() = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return oldItem.bookUrl == newItem.bookUrl + } + + override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return oldItem.originName == newItem.originName + && oldItem.coverUrl == newItem.coverUrl + } + + } + override fun getViewBinding(parent: ViewGroup): ItemCoverBinding { return ItemCoverBinding.inflate(inflater, parent, false) } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index e3b96fe45..48a9dfcc1 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.PopupMenu +import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -19,6 +20,19 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ChangeSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context) { + override val diffItemCallback: DiffUtil.ItemCallback + get() = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return oldItem.bookUrl == newItem.bookUrl + } + + override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return oldItem.originName == newItem.originName + && oldItem.getDisplayLastChapterTitle() == newItem.getDisplayLastChapterTitle() + } + + } + override fun getViewBinding(parent: ViewGroup): ItemChangeSourceBinding { return ItemChangeSourceBinding.inflate(inflater, parent, false) }