From 80ff82767133b8efe73198eada1beda55dbf3f63 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 30 Oct 2019 08:28:09 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/book/search/SearchActivity.kt | 2 +- .../io/legado/app/ui/book/search/SearchViewModel.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 36ebf13af..43dbeca82 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -171,7 +171,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } private fun scrollToBottom() { - if (!viewModel.isLoading) { + if (!viewModel.isLoading && viewModel.searchKey.isNotEmpty()) { viewModel.search("") } } 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 a271f794a..9700fafb0 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 @@ -27,17 +27,20 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { fun search(key: String) { task?.cancel() - if (key.isEmpty()) { + if (key.isEmpty() && searchKey.isEmpty()) { + return + } else if (key.isEmpty()) { + isLoading = true searchPage++ - } else { + } else if (key.isNotEmpty()) { + isLoading = true + searchPage = 0 searchKey = key searchBooks.clear() } - if (searchKey.isEmpty()) return startTime = System.currentTimeMillis() callBack?.startSearch() task = execute { - isLoading = true val searchGroup = context.getPrefString("searchGroup") ?: "" val bookSourceList = if (searchGroup.isBlank()) { App.db.bookSourceDao().allEnabled