From 13ab8c35b8157a6d8404a8d5ed5bb825b7aaf728 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Mar 2020 19:17:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/search/DiffCallBack.kt | 22 ++++++++++--------- .../app/ui/book/search/SearchViewModel.kt | 2 +- 2 files changed, 13 insertions(+), 11 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 999f2a941..6f14699a9 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,31 +49,33 @@ 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() - 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 } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 1e00157a2..191ceeafc 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -55,7 +55,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { WebBook(item).searchBook( searchKey, searchPage, - scope = this@execute, + scope = this, context = searchPool ) .timeout(30000L)