瀏覽代碼

Fix library query being lost

inorichi 7 年之前
父節點
當前提交
1292c0ecea
共有 1 個文件被更改,包括 11 次插入5 次删除
  1. 11 5
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt

+ 11 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt

@@ -118,6 +118,8 @@ class LibraryController(
 
     private var tabsVisibilitySubscription: Subscription? = null
 
+    private var searchViewSubscription: Subscription? = null
+
     init {
         setHasOptionsMenu(true)
         retainViewMode = RetainViewMode.RETAIN_DETACH
@@ -332,10 +334,14 @@ class LibraryController(
         // Mutate the filter icon because it needs to be tinted and the resource is shared.
         menu.findItem(R.id.action_filter).icon.mutate()
 
-        searchView.queryTextChanges().subscribeUntilDestroy {
-            query = it.toString()
-            searchRelay.call(query)
-        }
+        searchViewSubscription?.unsubscribe()
+        searchViewSubscription = searchView.queryTextChanges()
+                // Ignore events if this controller isn't at the top
+                .filter { router.backstack.lastOrNull()?.controller() == this }
+                .subscribeUntilDestroy {
+                    query = it.toString()
+                    searchRelay.call(query)
+                }
 
         searchItem.fixExpand()
     }
@@ -518,4 +524,4 @@ class LibraryController(
         const val REQUEST_IMAGE_OPEN = 101
     }
 
-}
+}