diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt index 957213945..4ce482e96 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceAdapter.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.changesource import android.content.Context +import android.os.Bundle import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -15,8 +16,9 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_change_source) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { + val bundle = payloads.getOrNull(0) as? Bundle holder.itemView.apply { - if (payloads.isEmpty()) { + if (bundle == null) { this.onClick { callBack.changeTo(item) } tv_origin.text = item.originName tv_last.text = item.getDisplayLastChapterTitle() @@ -26,8 +28,12 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : iv_checked.invisible() } } else { - tv_origin.text = item.originName - tv_last.text = item.getDisplayLastChapterTitle() + bundle.keySet().map { + when (it) { + "name" -> tv_origin.text = item.originName + "latest" -> tv_last.text = item.getDisplayLastChapterTitle() + } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt index 2cb911204..91e640ac3 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt @@ -1,16 +1,12 @@ package io.legado.app.ui.changesource +import android.os.Bundle import androidx.recyclerview.widget.DiffUtil import io.legado.app.data.entities.SearchBook class DiffCallBack(private val oldItems: List, private val newItems: List) : DiffUtil.Callback() { - - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return oldItems[oldItemPosition].bookUrl == newItems[newItemPosition].bookUrl - } - override fun getOldListSize(): Int { return oldItems.size } @@ -19,18 +15,38 @@ class DiffCallBack(private val oldItems: List, private val newItems: return newItems.size } + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.bookUrl == newItem.bookUrl + } + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return oldItems[oldItemPosition].originName == newItems[newItemPosition].originName - && oldItems[oldItemPosition].latestChapterTitle == newItems[newItemPosition].latestChapterTitle + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + if (oldItem.originName != newItem.originName) { + return false + } + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + return false + } + return true } override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - if (oldItem.originName != newItem.originName || oldItem.latestChapterTitle != newItem.latestChapterTitle) { - return true + val payload = Bundle() + if (oldItem.originName != newItem.originName) { + payload.putString("name", newItem.originName) + } + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + payload.putString("latest", newItem.latestChapterTitle) + } + if (payload.isEmpty) { + return null } - return null + return payload } } \ No newline at end of file