feat: 修复bug

pull/238/head
gedoor 5 years ago
parent fccdf41ea8
commit 3075b4b3e6
  1. 62
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt

@ -18,64 +18,40 @@ class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems:
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
if (oldItem.name != newItem.name) { return when {
return false 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 { override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
if (oldItem.origins.size != newItem.origins.size) { return when {
return false oldItem.origins.size != newItem.origins.size -> false
} oldItem.coverUrl != newItem.coverUrl -> false
if (oldItem.coverUrl != newItem.coverUrl) { oldItem.kind != newItem.kind -> false
return false oldItem.latestChapterTitle != newItem.latestChapterTitle -> false
} oldItem.intro != newItem.intro -> false
if (oldItem.kind != newItem.kind) { else -> true
return false
}
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) {
return false
} }
if (oldItem.intro != newItem.intro) {
return false
}
return true
} }
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val payload = Bundle() val payload = Bundle()
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
if (oldItem.name != newItem.name) { if (oldItem.name != newItem.name) payload.putString("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.author != newItem.author) {
payload.putString("author", newItem.author)
}
if (oldItem.origins.size != newItem.origins.size) {
payload.putInt("origins", newItem.origins.size) payload.putInt("origins", newItem.origins.size)
} if (oldItem.coverUrl != newItem.coverUrl) payload.putString("cover", newItem.coverUrl)
if (oldItem.coverUrl != newItem.coverUrl) { if (oldItem.kind != newItem.kind) payload.putString("kind", newItem.kind)
payload.putString("cover", newItem.coverUrl) if (oldItem.latestChapterTitle != newItem.latestChapterTitle)
}
if (oldItem.kind != newItem.kind) {
payload.putString("kind", newItem.kind)
}
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) {
payload.putString("last", newItem.latestChapterTitle) payload.putString("last", newItem.latestChapterTitle)
} if (oldItem.intro != newItem.intro) payload.putString("intro", newItem.intro)
if (oldItem.intro != newItem.intro) { if (payload.isEmpty) return null
payload.putString("intro", newItem.intro)
}
if (payload.isEmpty) {
return null
}
return payload return payload
} }
} }
Loading…
Cancel
Save