feat: 优化代码

pull/169/head
kunfei 5 years ago
parent e13f7b0f9c
commit e9f40e699e
  1. 22
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt

@ -50,30 +50,32 @@ class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems:
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val payload = Bundle()
val newItem = newItems.getOrNull(newItemPosition)
val oldItem = oldItems.getOrNull(oldItemPosition)
if (newItem == null) return payload
if (oldItem?.name != newItem.name) {
val newItem = newItems[newItemPosition]
val oldItem = oldItems[oldItemPosition]
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)
}
if (payload.isEmpty) {
return null
}
return payload
}
}
Loading…
Cancel
Save