From 922d17d0261a9a9effc23e4a1b7b75c24739c323 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Wed, 18 Mar 2020 16:19:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2=E6=97=B6ca?= =?UTF-8?q?sh=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/search/DiffCallBack.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 07a3b16c5..d0c2f2973 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -49,28 +49,29 @@ class DiffCallBack(private val oldItems: List, private val newItems: } override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { - val oldItem = oldItems[oldItemPosition] - val newItem = newItems[newItemPosition] val payload = Bundle() - if (oldItem.name != newItem.name) { + val newItem: SearchBook? = if ((newItemPosition >= 0) && (newItemPosition < newItems.size)) newItems[newItemPosition] else null + val oldItem: SearchBook? = if ((oldItemPosition >= 0) && (oldItemPosition < oldItems.size)) oldItems[oldItemPosition] else null + if (newItem == null) return payload + if (oldItem?.name != newItem.name) { payload.putString("name", newItem.name) } - if (oldItem.author != newItem.author) { + if (oldItem?.author != newItem.author) { payload.putString("author", newItem.author) } - if (oldItem.origins.size != newItem.origins.size) { + if (oldItem?.origins?.size != newItem.origins.size) { payload.putInt("origins", newItem.origins.size) } - if (oldItem.coverUrl != newItem.coverUrl) { + if (oldItem?.coverUrl != newItem.coverUrl) { payload.putString("cover", newItem.coverUrl) } - if (oldItem.kind != newItem.kind) { + if (oldItem?.kind != newItem.kind) { payload.putString("kind", newItem.kind) } - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + if (oldItem?.latestChapterTitle != newItem.latestChapterTitle) { payload.putString("last", newItem.latestChapterTitle) } - if (oldItem.intro != newItem.intro) { + if (oldItem?.intro != newItem.intro) { payload.putString("intro", newItem.intro) } return payload