Horis 3 years ago
parent
commit
2149bee15b
1 changed files with 13 additions and 9 deletions
  1. 13 9
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

+ 13 - 9
app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@@ -75,15 +75,17 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
      * 开始搜索
      * 开始搜索
      */
      */
     fun search(key: String) {
     fun search(key: String) {
-        if ((searchKey == key) || key.isNotEmpty()) {
-            searchModel.cancelSearch()
-            searchID = System.currentTimeMillis()
-            searchKey = key
-        }
-        if (searchKey.isEmpty()) {
-            return
+        execute {
+            if ((searchKey == key) || key.isNotEmpty()) {
+                searchModel.cancelSearch()
+                searchID = System.currentTimeMillis()
+                searchKey = key
+            }
+            if (searchKey.isEmpty()) {
+                return@execute
+            }
+            searchModel.search(searchID, searchKey)
         }
         }
-        searchModel.search(searchID, searchKey)
     }
     }
 
 
     /**
     /**
@@ -116,7 +118,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
     }
     }
 
 
     fun deleteHistory(searchKeyword: SearchKeyword) {
     fun deleteHistory(searchKeyword: SearchKeyword) {
-        appDb.searchKeywordDao.delete(searchKeyword)
+        execute {
+            appDb.searchKeywordDao.delete(searchKeyword)
+        }
     }
     }
 
 
     override fun onCleared() {
     override fun onCleared() {