From a8230ad574fb5c5dfa22a571862890e414649215 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:14:04 +0800 Subject: [PATCH] Fix browse search query display and keyboard focus (#8781) --- .../kanade/presentation/components/AppBar.kt | 1 + .../source/browse/BrowseSourceScreenModel.kt | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt index db26ca0a49..48c6cff853 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt @@ -319,6 +319,7 @@ fun SearchToolbar( ) LaunchedEffect(searchClickCount) { if (searchQuery == null) return@LaunchedEffect + if (searchClickCount == 0 && searchQuery.isNotEmpty()) return@LaunchedEffect try { focusRequester.requestFocus() } catch (_: Throwable) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index 799d266ad5..a9068ab3c5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -103,6 +103,24 @@ class BrowseSourceScreenModel( val source = sourceManager.get(sourceId) as CatalogueSource + init { + mutableState.update { + var query: String? = null + var listing = it.listing + + if (listing is Listing.Search) { + query = listing.query + listing = Listing.Search(query, source.getFilterList()) + } + + it.copy( + listing = listing, + filters = source.getFilterList(), + toolbarQuery = query, + ) + } + } + /** * Sheet containing filter items. */ @@ -132,22 +150,6 @@ class BrowseSourceScreenModel( } .stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow()) - init { - mutableState.update { - val initialListing = it.listing - val listing = if (initialListing is Listing.Search) { - initialListing.copy(filters = source.getFilterList()) - } else { - initialListing - } - - it.copy( - listing = listing, - filters = source.getFilterList(), - ) - } - } - fun getColumnsPreference(orientation: Int): GridCells { val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE val columns = if (isLandscape) {