feat: 优化代码

pull/167/head
kunfei 5 years ago
parent a67156b0cf
commit 13ab8c35b8
  1. 22
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

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

@ -55,7 +55,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
WebBook(item).searchBook(
searchKey,
searchPage,
scope = this@execute,
scope = this,
context = searchPool
)
.timeout(30000L)

Loading…
Cancel
Save