mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 05:59:17 +01:00
Fully extend search view, hiding menu items
This commit is contained in:
parent
491915aa22
commit
090e9ee005
@ -6,6 +6,7 @@ import android.graphics.Color
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
@ -37,4 +38,14 @@ class MiniSearchView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
val searchMagIconImageView = findViewById<ImageView>(androidx.appcompat.R.id.search_mag_icon)
|
val searchMagIconImageView = findViewById<ImageView>(androidx.appcompat.R.id.search_mag_icon)
|
||||||
searchMagIconImageView?.layoutParams = LinearLayout.LayoutParams(0, 0)
|
searchMagIconImageView?.layoutParams = LinearLayout.LayoutParams(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActionViewExpanded() {
|
||||||
|
super.onActionViewExpanded()
|
||||||
|
layoutParams?.let {
|
||||||
|
val params = it
|
||||||
|
params.width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
layoutParams = params
|
||||||
|
}
|
||||||
|
requestLayout()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,17 @@ package eu.kanade.tachiyomi.ui.base.controller
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.view.forEach
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||||
import com.bluelinelabs.conductor.ControllerChangeType
|
import com.bluelinelabs.conductor.ControllerChangeType
|
||||||
|
import eu.kanade.tachiyomi.util.view.activityBinding
|
||||||
import eu.kanade.tachiyomi.util.view.removeQueryListener
|
import eu.kanade.tachiyomi.util.view.removeQueryListener
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
@ -111,6 +114,7 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
|
|||||||
setOnActionExpandListener(
|
setOnActionExpandListener(
|
||||||
object : MenuItem.OnActionExpandListener {
|
object : MenuItem.OnActionExpandListener {
|
||||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
|
hideItemsIfExpanded(item, activityBinding?.cardToolbar?.menu, true)
|
||||||
return onExpand?.invoke(item) ?: true
|
return onExpand?.invoke(item) ?: true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +132,14 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hideItemsIfExpanded(searchItem: MenuItem?, menu: Menu?, isExpanded: Boolean = false) {
|
||||||
|
menu ?: return
|
||||||
|
searchItem ?: return
|
||||||
|
if (searchItem.isActionViewExpanded || isExpanded) {
|
||||||
|
menu.forEach { it.isVisible = false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun MenuItem.fixExpandInvalidate() {
|
fun MenuItem.fixExpandInvalidate() {
|
||||||
fixExpand { invalidateMenuOnExpand() }
|
fixExpand { invalidateMenuOnExpand() }
|
||||||
}
|
}
|
||||||
|
@ -1510,6 +1510,7 @@ class LibraryController(
|
|||||||
searchItem.expandActionView()
|
searchItem.expandActionView()
|
||||||
searchView.setQuery(query, true)
|
searchView.setQuery(query, true)
|
||||||
searchView.clearFocus()
|
searchView.clearFocus()
|
||||||
|
search(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnQueryTextChangeListener(searchView) {
|
setOnQueryTextChangeListener(searchView) {
|
||||||
@ -1534,6 +1535,7 @@ class LibraryController(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
hideItemsIfExpanded(searchItem, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
@ -619,6 +619,7 @@ class RecentsController(bundle: Bundle? = null) :
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
searchItem.fixExpandInvalidate()
|
searchItem.fixExpandInvalidate()
|
||||||
|
hideItemsIfExpanded(searchItem, menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,11 +488,13 @@ class BrowseController :
|
|||||||
// Change hint to show global search.
|
// Change hint to show global search.
|
||||||
searchView.queryHint = view?.context?.getString(R.string.global_search)
|
searchView.queryHint = view?.context?.getString(R.string.global_search)
|
||||||
|
|
||||||
|
searchItem.fixExpandInvalidate()
|
||||||
// Create query listener which opens the global search view.
|
// Create query listener which opens the global search view.
|
||||||
setOnQueryTextChangeListener(searchView, true) {
|
setOnQueryTextChangeListener(searchView, true) {
|
||||||
if (!it.isNullOrBlank()) performGlobalSearch(it)
|
if (!it.isNullOrBlank()) performGlobalSearch(it)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
hideItemsIfExpanded(searchItem, menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +257,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
}
|
}
|
||||||
setIcon(icon)
|
setIcon(icon)
|
||||||
}
|
}
|
||||||
|
hideItemsIfExpanded(searchItem, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:id="@+id/action_search"
|
android:id="@+id/action_search"
|
||||||
android:icon="@drawable/ic_search_24dp"
|
android:icon="@drawable/ic_search_24dp"
|
||||||
android:title="@string/search"
|
android:title="@string/search"
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"
|
||||||
app:showAsAction="collapseActionView|ifRoom" />
|
app:showAsAction="collapseActionView|ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:id="@+id/action_search"
|
android:id="@+id/action_search"
|
||||||
android:icon="@drawable/ic_search_24dp"
|
android:icon="@drawable/ic_search_24dp"
|
||||||
android:title="@string/search"
|
android:title="@string/search"
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"
|
||||||
app:showAsAction="collapseActionView|ifRoom" />
|
app:showAsAction="collapseActionView|ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:title="@string/search"
|
android:title="@string/search"
|
||||||
android:icon="@drawable/ic_search_24dp"
|
android:icon="@drawable/ic_search_24dp"
|
||||||
app:showAsAction="collapseActionView|ifRoom"
|
app:showAsAction="collapseActionView|ifRoom"
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
|
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_sort"
|
android:id="@+id/action_sort"
|
||||||
|
Loading…
Reference in New Issue
Block a user