diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 3b3a90d13..7b355cb90 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -47,7 +47,6 @@ import exh.ui.LoaderManager import java.util.concurrent.TimeUnit 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 @@ -408,19 +407,13 @@ class LibraryController( searchView.clearFocus() performSearch() - } - 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) + // 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() @@ -432,7 +425,17 @@ class LibraryController( fun search(query: String) { this.query = query - performSearch() + } + + 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 } + .onEach { + query = it.toString() + performSearch() + } + .launchIn(scope) } private fun performSearch() {