优化搜索

pull/346/head
gedoor 4 years ago
parent f65f553d83
commit 95e7ce3479
  1. 1
      app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.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)
}

@ -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
}
}

Loading…
Cancel
Save