mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 15:21:51 +01:00
Perform a global search while seatching in the library
There's a button at the top of the list to do it
This commit is contained in:
parent
183f28b382
commit
2c79b97815
@ -208,5 +208,6 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
||||
fun allSelected(position: Int): Boolean
|
||||
fun toggleCategoryVisibility(position: Int)
|
||||
fun manageCategory(position: Int)
|
||||
fun globalSearch(query: String)
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ import eu.kanade.tachiyomi.ui.main.RootSearchInterface
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
||||
import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.ui.source.global_search.SourceSearchController
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
@ -145,6 +146,7 @@ class LibraryController(
|
||||
private set
|
||||
|
||||
private var observeLater: Boolean = false
|
||||
var searchItem = SearchGlobalItem()
|
||||
|
||||
var snack: Snackbar? = null
|
||||
|
||||
@ -285,9 +287,11 @@ class LibraryController(
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
if (libraryLayout == 0) return 1
|
||||
val item = this@LibraryController.adapter.getItem(position)
|
||||
return if (item is LibraryHeaderItem) recycler.manager.spanCount
|
||||
else if (item is LibraryItem && item.manga.isBlank()) recycler.manager.spanCount
|
||||
else 1
|
||||
return if (item is LibraryHeaderItem || item is SearchGlobalItem || (item is LibraryItem && item.manga.isBlank())) {
|
||||
recycler.manager.spanCount
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
})
|
||||
recycler.setHasFixedSize(true)
|
||||
@ -799,6 +803,15 @@ class LibraryController(
|
||||
|
||||
fun search(query: String?): Boolean {
|
||||
this.query = query ?: ""
|
||||
if (this.query.isNotBlank() && adapter.scrollableHeaders.isEmpty()) {
|
||||
searchItem.string = this.query
|
||||
adapter.addScrollableHeader(searchItem)
|
||||
} else if (this.query.isNotBlank()) {
|
||||
searchItem.string = this.query
|
||||
(recycler.findViewHolderForAdapterPosition(0) as? SearchGlobalItem.Holder)?.bind(this.query)
|
||||
} else if (this.query.isBlank() && adapter.scrollableHeaders.isNotEmpty()) {
|
||||
adapter.removeAllScrollableHeaders()
|
||||
}
|
||||
adapter.setFilter(query)
|
||||
adapter.performFilter()
|
||||
return true
|
||||
@ -915,7 +928,7 @@ class LibraryController(
|
||||
* @param position the position of the element clicked.
|
||||
*/
|
||||
override fun onItemLongClick(position: Int) {
|
||||
if (adapter.getItem(position) is LibraryHeaderItem) return
|
||||
if (adapter.getItem(position) !is LibraryItem) return
|
||||
createActionModeIfNeeded()
|
||||
when {
|
||||
lastClickPosition == -1 -> setSelection(position)
|
||||
@ -930,6 +943,10 @@ class LibraryController(
|
||||
lastClickPosition = position
|
||||
}
|
||||
|
||||
override fun globalSearch(query: String) {
|
||||
router.pushController(SourceSearchController(query).withFadeTransaction())
|
||||
}
|
||||
|
||||
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
||||
val position = viewHolder?.adapterPosition ?: return
|
||||
swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_DRAG
|
||||
|
@ -0,0 +1,84 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||
import kotlinx.android.synthetic.main.material_text_button.*
|
||||
|
||||
class SearchGlobalItem : AbstractFlexibleItem<SearchGlobalItem.Holder>() {
|
||||
|
||||
var string = ""
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.material_text_button
|
||||
}
|
||||
|
||||
override fun createViewHolder(
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
): Holder {
|
||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
width = MATCH_PARENT
|
||||
}
|
||||
return Holder(view, adapter)
|
||||
}
|
||||
|
||||
override fun isSelectable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun isSwipeable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun isDraggable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun bindViewHolder(
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||
holder: Holder,
|
||||
position: Int,
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
holder.bind(string)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return this === other
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return -100
|
||||
}
|
||||
|
||||
class Holder(val view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) :
|
||||
BaseFlexibleViewHolder(view, adapter, true) {
|
||||
|
||||
init {
|
||||
button.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
width = MATCH_PARENT
|
||||
}
|
||||
button.setOnClickListener {
|
||||
val query = (adapter.getItem(adapterPosition) as SearchGlobalItem).string
|
||||
(adapter as? LibraryCategoryAdapter)?.libraryListener?.globalSearch(query)
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(string: String) {
|
||||
button.text = view.context.getString(R.string.search_globally, string)
|
||||
}
|
||||
|
||||
override fun onLongClick(view: View?): Boolean {
|
||||
super.onLongClick(view)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.button.MaterialButton style="@style/Theme.Widget.Button.TextButton"
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_as_default_for_all"
|
||||
|
@ -119,6 +119,7 @@
|
||||
<string name="collapse_all_categories">Collapse all categories</string>
|
||||
<string name="reorder_filters">Reorder filters</string>
|
||||
<string name="_unread">%d unread</string>
|
||||
<string name="search_globally">Search \"%1$s\" globally</string>
|
||||
|
||||
<string name="read_progress">Read progress</string>
|
||||
<string name="series_type">Series type</string>
|
||||
|
Loading…
Reference in New Issue
Block a user