From 95e7ce34794caf0e222ac2fd2da62f9c10f229b3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 28 Aug 2020 14:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/webBook/SearchBookModel.kt | 1 + .../java/io/legado/app/ui/book/search/SearchViewModel.kt | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt index c252c567f..1224979af 100644 --- a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt +++ b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt @@ -54,6 +54,7 @@ class SearchBookModel(private val scope: CoroutineScope, private val callBack: C } else { searchPage++ } + searchIndex = -1 for (i in 0 until threadCount) { search(searchId) } 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 564b2bb3e..179b2cd9b 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 @@ -30,13 +30,16 @@ class SearchViewModel(application: Application) : BaseViewModel(application), * 开始搜索 */ fun search(key: String) { - if ((searchKey != key && key.isEmpty()) || key.isNotEmpty()) { + if ((searchKey == key) || key.isNotEmpty()) { searchBookModel.cancelSearch() searchBooks.clear() searchBookLiveData.postValue(searchBooks) searchID = System.currentTimeMillis() searchKey = key } + if (searchKey.isEmpty()) { + return + } searchBookModel.search(searchID, searchKey) } @@ -111,7 +114,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application), && item.author == searchBook.author ) { hasSame = true - searchBook.addOrigin(item.bookUrl) + searchBook.addOrigin(item.origin) break } }