Add shortcut to global search query from library (closes #2183)

(cherry picked from commit 763da19c9db0fd4e911f27df0d998122fcff3cce)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
This commit is contained in:
arkon 2020-07-10 17:33:16 -04:00 committed by Jobobby04
parent c0a4f4e93a
commit fbb14a35a9
4 changed files with 61 additions and 20 deletions

View File

@ -129,6 +129,9 @@ open class ExtensionController :
val searchView = searchItem.actionView as SearchView val searchView = searchItem.actionView as SearchView
searchView.maxWidth = Int.MAX_VALUE searchView.maxWidth = Int.MAX_VALUE
// Fixes problem with the overflow icon showing up in lieu of search
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
if (query.isNotEmpty()) { if (query.isNotEmpty()) {
searchItem.expandActionView() searchItem.expandActionView()
searchView.setQuery(query, true) searchView.setQuery(query, true)
@ -142,9 +145,6 @@ open class ExtensionController :
drawExtensions() drawExtensions()
} }
.launchIn(scope) .launchIn(scope)
// Fixes problem with the overflow icon showing up in lieu of search
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
} }
override fun onItemClick(view: View, position: Int): Boolean { override fun onItemClick(view: View, position: Int): Boolean {

View File

@ -37,6 +37,7 @@ import eu.kanade.tachiyomi.ui.base.controller.TabbedController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.browse.migration.advanced.design.PreMigrationController import eu.kanade.tachiyomi.ui.browse.migration.advanced.design.PreMigrationController
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesController import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesController
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
import eu.kanade.tachiyomi.ui.manga.MangaAllInOneController import eu.kanade.tachiyomi.ui.manga.MangaAllInOneController
@ -44,16 +45,19 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.hasCustomCover import eu.kanade.tachiyomi.util.hasCustomCover
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import exh.favorites.FavoritesIntroDialog import exh.favorites.FavoritesIntroDialog
import exh.favorites.FavoritesSyncStatus 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.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
import reactivecircus.flowbinding.android.view.clicks
import reactivecircus.flowbinding.appcompat.queryTextChanges import reactivecircus.flowbinding.appcompat.queryTextChanges
import reactivecircus.flowbinding.viewpager.pageSelections import reactivecircus.flowbinding.viewpager.pageSelections
import rx.Subscription import rx.Subscription
@ -87,7 +91,7 @@ class LibraryController(
/** /**
* Library search query. * Library search query.
*/ */
private var query = "" private var query: String? = ""
/** /**
* Currently selected mangas. * Currently selected mangas.
@ -236,6 +240,14 @@ class LibraryController(
binding.downloadedOnly.visible() binding.downloadedOnly.visible()
} }
binding.btnGlobalSearch.clicks()
.onEach {
router.pushController(
GlobalSearchController(query).withFadeTransaction()
)
}
.launchIn(scope)
binding.actionToolbar.offsetAppbarHeight(activity!!) binding.actionToolbar.offsetAppbarHeight(activity!!)
} }
@ -404,26 +416,26 @@ class LibraryController(
val searchItem = menu.findItem(R.id.action_search) val searchItem = menu.findItem(R.id.action_search)
val searchView = searchItem.actionView as SearchView val searchView = searchItem.actionView as SearchView
searchView.maxWidth = Int.MAX_VALUE searchView.maxWidth = Int.MAX_VALUE
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
searchView.queryTextChanges() if (!query.isNullOrEmpty()) {
// Ignore events if this controller isn't at the top
.filter { router.backstack.lastOrNull()?.controller() == this }
.onEach {
query = it.toString()
searchRelay.call(query)
}
.launchIn(scope)
if (query.isNotEmpty()) {
searchItem.expandActionView() searchItem.expandActionView()
searchView.setQuery(query, true) searchView.setQuery(query, true)
searchView.clearFocus() searchView.clearFocus()
// Manually trigger the search since the binding doesn't trigger for some reason // If we re-enter the controller with a prior search still active
searchRelay.call(query) view?.post {
performSearch()
}
} }
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) searchView.queryTextChanges()
.distinctUntilChanged()
.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()
@ -433,8 +445,23 @@ class LibraryController(
// SY <-- // SY <--
} }
fun search(query: String) { fun search(query: String?) {
this.query = query // Delay to let contents load first for searches from manga info
view?.post {
this.query = query
performSearch()
}
}
private fun performSearch() {
searchRelay.call(query)
if (!query.isNullOrEmpty()) {
binding.btnGlobalSearch.visible()
binding.btnGlobalSearch.text =
resources?.getString(R.string.action_global_search_query, query)
} else {
binding.btnGlobalSearch.gone()
}
} }
override fun onPrepareOptionsMenu(menu: Menu) { override fun onPrepareOptionsMenu(menu: Menu) {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -14,7 +15,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/pale_green" android:background="@color/pale_green"
android:visibility="gone"> android:visibility="gone"
tools:visibility="visible">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -26,6 +28,17 @@
</FrameLayout> </FrameLayout>
<Button
android:id="@+id/btn_global_search"
style="@style/Theme.Widget.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textAllCaps="false"
android:visibility="gone"
tools:text="Search"
tools:visibility="visible" />
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:id="@+id/library_pager" android:id="@+id/library_pager"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -446,6 +446,7 @@
<string name="invalid_combination">Default can\'t be selected with other categories</string> <string name="invalid_combination">Default can\'t be selected with other categories</string>
<string name="added_to_library">The manga has been added to your library</string> <string name="added_to_library">The manga has been added to your library</string>
<string name="action_global_search_hint">Global search…</string> <string name="action_global_search_hint">Global search…</string>
<string name="action_global_search_query">Search for \"%1$s\" globally</string>
<string name="latest">Latest</string> <string name="latest">Latest</string>
<string name="browse">Browse</string> <string name="browse">Browse</string>
<string name="local_source_help_guide">Local source guide</string> <string name="local_source_help_guide">Local source guide</string>