Actually fix library search properly

(cherry picked from commit 98a4d1e763e7c756ffb4b7fa0c62618a907a54b6)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
This commit is contained in:
arkon 2020-07-31 12:54:23 -04:00 committed by Jobobby04
parent 09c9e15281
commit 337d270d2a

View File

@ -47,7 +47,6 @@ import exh.ui.LoaderManager
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlinx.android.synthetic.main.main_activity.tabs import kotlinx.android.synthetic.main.main_activity.tabs
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.dropWhile
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -408,19 +407,13 @@ class LibraryController(
searchView.clearFocus() searchView.clearFocus()
performSearch() performSearch()
}
searchView.queryTextChanges() // Workaround for weird behavior where searchview gets empty text change despite
// Ignore events if this controller isn't at the top to avoid query being reset // query being set already
.filter { router.backstack.lastOrNull()?.controller() == this } searchView.postDelayed({ initSearchHandler(searchView) }, 500)
// If we re-enter the controller with a prior search still active, but searchview } else {
// content sometimes appears empty. initSearchHandler(searchView)
.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. // Mutate the filter icon because it needs to be tinted and the resource is shared.
menu.findItem(R.id.action_filter).icon.mutate() menu.findItem(R.id.action_filter).icon.mutate()
@ -432,7 +425,17 @@ class LibraryController(
fun search(query: String) { fun search(query: String) {
this.query = query 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() { private fun performSearch() {