mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 22:09:16 +01:00
Add shortcut to global search query from library (closes #2183)
This commit is contained in:
parent
1813dbbf59
commit
763da19c9d
@ -129,6 +129,9 @@ open class ExtensionController :
|
||||
val searchView = searchItem.actionView as SearchView
|
||||
searchView.maxWidth = Int.MAX_VALUE
|
||||
|
||||
// Fixes problem with the overflow icon showing up in lieu of search
|
||||
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
|
||||
|
||||
if (query.isNotEmpty()) {
|
||||
searchItem.expandActionView()
|
||||
searchView.setQuery(query, true)
|
||||
@ -142,9 +145,6 @@ open class ExtensionController :
|
||||
drawExtensions()
|
||||
}
|
||||
.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 {
|
||||
|
@ -33,18 +33,22 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.hasCustomCover
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.main_activity.tabs
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
import reactivecircus.flowbinding.appcompat.queryTextChanges
|
||||
import reactivecircus.flowbinding.viewpager.pageSelections
|
||||
import rx.Subscription
|
||||
@ -77,7 +81,7 @@ class LibraryController(
|
||||
/**
|
||||
* Library search query.
|
||||
*/
|
||||
private var query = ""
|
||||
private var query: String? = ""
|
||||
|
||||
/**
|
||||
* Currently selected mangas.
|
||||
@ -204,6 +208,14 @@ class LibraryController(
|
||||
binding.downloadedOnly.visible()
|
||||
}
|
||||
|
||||
binding.btnGlobalSearch.clicks()
|
||||
.onEach {
|
||||
router.pushController(
|
||||
GlobalSearchController(query).withFadeTransaction()
|
||||
)
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.actionToolbar.offsetAppbarHeight(activity!!)
|
||||
}
|
||||
|
||||
@ -364,33 +376,48 @@ class LibraryController(
|
||||
val searchItem = menu.findItem(R.id.action_search)
|
||||
val searchView = searchItem.actionView as SearchView
|
||||
searchView.maxWidth = Int.MAX_VALUE
|
||||
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
|
||||
|
||||
searchView.queryTextChanges()
|
||||
// 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()) {
|
||||
if (!query.isNullOrEmpty()) {
|
||||
searchItem.expandActionView()
|
||||
searchView.setQuery(query, true)
|
||||
searchView.clearFocus()
|
||||
|
||||
// Manually trigger the search since the binding doesn't trigger for some reason
|
||||
searchRelay.call(query)
|
||||
// If we re-enter the controller with a prior search still active
|
||||
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.
|
||||
menu.findItem(R.id.action_filter).icon.mutate()
|
||||
}
|
||||
|
||||
fun search(query: String) {
|
||||
this.query = query
|
||||
fun search(query: String?) {
|
||||
// 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) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -14,7 +15,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/pale_green"
|
||||
android:visibility="gone">
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@ -26,6 +28,17 @@
|
||||
|
||||
</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
|
||||
android:id="@+id/library_pager"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -448,6 +448,7 @@
|
||||
<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="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="browse">Browse</string>
|
||||
<string name="local_source_help_guide">Local source guide</string>
|
||||
|
Loading…
Reference in New Issue
Block a user