浏览代码

Actually fix library search properly

arkon 4 年之前
父节点
当前提交
98a4d1e763
共有 1 个文件被更改,包括 15 次插入12 次删除
  1. 15 12
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt

+ 15 - 12
app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt

@@ -39,7 +39,6 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
 import eu.kanade.tachiyomi.util.system.toast
 import kotlinx.android.synthetic.main.main_activity.tabs
 import kotlinx.coroutines.flow.drop
-import kotlinx.coroutines.flow.dropWhile
 import kotlinx.coroutines.flow.filter
 import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
@@ -374,27 +373,31 @@ class LibraryController(
             searchView.clearFocus()
 
             performSearch()
+
+            // Workaround for weird behavior where searchview gets empty text change despite
+            // query being set already
+            searchView.postDelayed({ initSearchHandler(searchView) }, 500)
+        } else {
+            initSearchHandler(searchView)
         }
 
+        // Mutate the filter icon because it needs to be tinted and the resource is shared.
+        menu.findItem(R.id.action_filter).icon.mutate()
+    }
+
+    fun search(query: String) {
+        this.query = query
+    }
+
+    private fun initSearchHandler(searchView: SearchView) {
         searchView.queryTextChanges()
             // Ignore events if this controller isn't at the top to avoid query being reset
             .filter { router.backstack.lastOrNull()?.controller() == this }
-            // If we re-enter the controller with a prior search still active, but searchview
-            // content sometimes appears empty.
-            .dropWhile { query.isNotEmpty() && query != it.toString() }
             .onEach {
                 query = it.toString()
                 performSearch()
             }
             .launchIn(scope)
-
-        // Mutate the filter icon because it needs to be tinted and the resource is shared.
-        menu.findItem(R.id.action_filter).icon.mutate()
-    }
-
-    fun search(query: String) {
-        this.query = query
-        performSearch()
     }
 
     private fun performSearch() {