From 3075b4b3e64b768d6b33b479c231da56c259131e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 6 Jun 2020 20:48:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/search/DiffCallBack.kt | 62 ++++++------------- 1 file changed, 19 insertions(+), 43 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 b03e54fb7..4125489b8 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 @@ -18,64 +18,40 @@ class DiffCallBack(private val oldItems: List, private val newItems: override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - if (oldItem.name != newItem.name) { - return false + return when { + oldItem.name != newItem.name -> false + oldItem.author != newItem.author -> false + else -> true } - if (oldItem.author != newItem.author) { - return false - } - return true } override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - if (oldItem.origins.size != newItem.origins.size) { - return false - } - if (oldItem.coverUrl != newItem.coverUrl) { - return false - } - if (oldItem.kind != newItem.kind) { - return false - } - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { - return false + return when { + oldItem.origins.size != newItem.origins.size -> false + oldItem.coverUrl != newItem.coverUrl -> false + oldItem.kind != newItem.kind -> false + oldItem.latestChapterTitle != newItem.latestChapterTitle -> false + oldItem.intro != newItem.intro -> false + else -> true } - if (oldItem.intro != newItem.intro) { - return false - } - return true } override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { val payload = Bundle() val newItem = newItems[newItemPosition] val oldItem = oldItems[oldItemPosition] - if (oldItem.name != newItem.name) { - payload.putString("name", newItem.name) - } - if (oldItem.author != newItem.author) { - payload.putString("author", newItem.author) - } - if (oldItem.origins.size != newItem.origins.size) { + if (oldItem.name != newItem.name) payload.putString("name", newItem.name) + if (oldItem.author != newItem.author) payload.putString("author", newItem.author) + if (oldItem.origins.size != newItem.origins.size) payload.putInt("origins", newItem.origins.size) - } - if (oldItem.coverUrl != newItem.coverUrl) { - payload.putString("cover", newItem.coverUrl) - } - if (oldItem.kind != newItem.kind) { - payload.putString("kind", newItem.kind) - } - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + if (oldItem.coverUrl != newItem.coverUrl) payload.putString("cover", newItem.coverUrl) + if (oldItem.kind != newItem.kind) payload.putString("kind", newItem.kind) + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) payload.putString("last", newItem.latestChapterTitle) - } - if (oldItem.intro != newItem.intro) { - payload.putString("intro", newItem.intro) - } - if (payload.isEmpty) { - return null - } + if (oldItem.intro != newItem.intro) payload.putString("intro", newItem.intro) + if (payload.isEmpty) return null return payload } } \ No newline at end of file