Fix library search query being lost when returning (closes #3473)
(cherry picked from commit f762598c5c54bd8fcb9ff308af94715c9dc31c35) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt
This commit is contained in:
parent
057ccf74ce
commit
09c9e15281
@ -260,7 +260,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
*
|
*
|
||||||
* @param event the event received.
|
* @param event the event received.
|
||||||
*/
|
*/
|
||||||
suspend fun onNextLibraryManga(cScope: CoroutineScope, event: LibraryMangaEvent) {
|
private suspend fun onNextLibraryManga(cScope: CoroutineScope, event: LibraryMangaEvent) {
|
||||||
// Get the manga list for this category.
|
// Get the manga list for this category.
|
||||||
// SY -->
|
// SY -->
|
||||||
val sortingMode = preferences.librarySortingMode().get()
|
val sortingMode = preferences.librarySortingMode().get()
|
||||||
|
@ -46,8 +46,9 @@ import exh.favorites.FavoritesSyncStatus
|
|||||||
import exh.ui.LoaderManager
|
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.distinctUntilChanged
|
|
||||||
import kotlinx.coroutines.flow.drop
|
import kotlinx.coroutines.flow.drop
|
||||||
|
import kotlinx.coroutines.flow.dropWhile
|
||||||
|
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
|
||||||
import reactivecircus.flowbinding.android.view.clicks
|
import reactivecircus.flowbinding.android.view.clicks
|
||||||
@ -81,7 +82,7 @@ class LibraryController(
|
|||||||
/**
|
/**
|
||||||
* Library search query.
|
* Library search query.
|
||||||
*/
|
*/
|
||||||
private var query: String? = ""
|
private var query: String = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently selected mangas.
|
* Currently selected mangas.
|
||||||
@ -401,19 +402,20 @@ class LibraryController(
|
|||||||
searchView.maxWidth = Int.MAX_VALUE
|
searchView.maxWidth = Int.MAX_VALUE
|
||||||
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
|
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
|
||||||
|
|
||||||
if (!query.isNullOrEmpty()) {
|
if (query.isNotEmpty()) {
|
||||||
searchItem.expandActionView()
|
searchItem.expandActionView()
|
||||||
searchView.setQuery(query, true)
|
searchView.setQuery(query, true)
|
||||||
searchView.clearFocus()
|
searchView.clearFocus()
|
||||||
|
|
||||||
// If we re-enter the controller with a prior search still active
|
performSearch()
|
||||||
view?.post {
|
|
||||||
performSearch()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchView.queryTextChanges()
|
searchView.queryTextChanges()
|
||||||
.distinctUntilChanged()
|
// 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 {
|
.onEach {
|
||||||
query = it.toString()
|
query = it.toString()
|
||||||
performSearch()
|
performSearch()
|
||||||
@ -428,17 +430,14 @@ class LibraryController(
|
|||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search(query: String?) {
|
fun search(query: String) {
|
||||||
// Delay to let contents load first for searches from manga info
|
this.query = query
|
||||||
view?.post {
|
performSearch()
|
||||||
this.query = query
|
|
||||||
performSearch()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun performSearch() {
|
private fun performSearch() {
|
||||||
searchRelay.call(query)
|
searchRelay.call(query)
|
||||||
if (!query.isNullOrEmpty()) {
|
if (query.isNotEmpty()) {
|
||||||
binding.btnGlobalSearch.isVisible = true
|
binding.btnGlobalSearch.isVisible = true
|
||||||
binding.btnGlobalSearch.text =
|
binding.btnGlobalSearch.text =
|
||||||
resources?.getString(R.string.action_global_search_query, query)
|
resources?.getString(R.string.action_global_search_query, query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user