Horis 3 سال پیش
والد
کامیت
b880196526
1فایلهای تغییر یافته به همراه4 افزوده شده و 10 حذف شده
  1. 4 10
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt

+ 4 - 10
app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt

@@ -75,7 +75,6 @@ class SearchContentActivity :
         searchView.onActionViewExpanded()
         searchView.onActionViewExpanded()
         searchView.isSubmitButtonEnabled = true
         searchView.isSubmitButtonEnabled = true
         searchView.queryHint = getString(R.string.search)
         searchView.queryHint = getString(R.string.search)
-        searchView.clearFocus()
         searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
         searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
             override fun onQueryTextSubmit(query: String): Boolean {
             override fun onQueryTextSubmit(query: String): Boolean {
                 startContentSearch(query.trim())
                 startContentSearch(query.trim())
@@ -153,12 +152,12 @@ class SearchContentActivity :
             viewModel.lastQuery = query
             viewModel.lastQuery = query
             searchJob = launch {
             searchJob = launch {
                 kotlin.runCatching {
                 kotlin.runCatching {
+                    binding.refreshProgressBar.isAutoLoading = true
+                    binding.fbStop.visible()
                     withContext(IO) {
                     withContext(IO) {
                         appDb.bookChapterDao.getChapterList(viewModel.bookUrl)
                         appDb.bookChapterDao.getChapterList(viewModel.bookUrl)
                     }.forEach { bookChapter ->
                     }.forEach { bookChapter ->
                         ensureActive()
                         ensureActive()
-                        binding.refreshProgressBar.isAutoLoading = true
-                        binding.fbStop.visible()
                         val searchResults = withContext(IO) {
                         val searchResults = withContext(IO) {
                             if (isLocalBook || viewModel.cacheChapterNames.contains(bookChapter.getFileName())) {
                             if (isLocalBook || viewModel.cacheChapterNames.contains(bookChapter.getFileName())) {
                                 viewModel.searchChapter(query, bookChapter)
                                 viewModel.searchChapter(query, bookChapter)
@@ -171,24 +170,19 @@ class SearchContentActivity :
                         ensureActive()
                         ensureActive()
                         if (searchResults != null && searchResults.isNotEmpty()) {
                         if (searchResults != null && searchResults.isNotEmpty()) {
                             viewModel.searchResultList.addAll(searchResults)
                             viewModel.searchResultList.addAll(searchResults)
-                            binding.refreshProgressBar.isAutoLoading = false
                             adapter.addItems(searchResults)
                             adapter.addItems(searchResults)
                         }
                         }
                     }
                     }
-                    binding.refreshProgressBar.isAutoLoading = false
                     if (viewModel.searchResultCounts == 0) {
                     if (viewModel.searchResultCounts == 0) {
                         val noSearchResult =
                         val noSearchResult =
                             SearchResult(resultText = getString(R.string.search_content_empty))
                             SearchResult(resultText = getString(R.string.search_content_empty))
                         adapter.addItem(noSearchResult)
                         adapter.addItem(noSearchResult)
                     }
                     }
                 }.onFailure {
                 }.onFailure {
-                    binding.fbStop.invisible()
-                    binding.refreshProgressBar.isAutoLoading = false
                     AppLog.put("全文搜索出错\n${it.localizedMessage}", it)
                     AppLog.put("全文搜索出错\n${it.localizedMessage}", it)
-                }.onSuccess {
-                    binding.fbStop.invisible()
-                    binding.refreshProgressBar.isAutoLoading = false
                 }
                 }
+                binding.fbStop.invisible()
+                binding.refreshProgressBar.isAutoLoading = false
             }
             }
         }
         }
     }
     }