Fully extend search view, hiding menu items

This commit is contained in:
Jays2Kings 2021-05-07 23:16:29 -04:00
parent 491915aa22
commit 090e9ee005
9 changed files with 32 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import android.graphics.Color
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
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)
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()
}
}

View File

@ -3,14 +3,17 @@ package eu.kanade.tachiyomi.ui.base.controller
import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.forEach
import androidx.viewbinding.ViewBinding
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.removeQueryListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
@ -111,6 +114,7 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :
setOnActionExpandListener(
object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
hideItemsIfExpanded(item, activityBinding?.cardToolbar?.menu, 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() {
fixExpand { invalidateMenuOnExpand() }
}

View File

@ -1510,6 +1510,7 @@ class LibraryController(
searchItem.expandActionView()
searchView.setQuery(query, true)
searchView.clearFocus()
search(query)
}
setOnQueryTextChangeListener(searchView) {
@ -1534,6 +1535,7 @@ class LibraryController(
true
}
)
hideItemsIfExpanded(searchItem, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -619,6 +619,7 @@ class RecentsController(bundle: Bundle? = null) :
true
}
searchItem.fixExpandInvalidate()
hideItemsIfExpanded(searchItem, menu)
}
}

View File

@ -488,11 +488,13 @@ class BrowseController :
// Change hint to show global search.
searchView.queryHint = view?.context?.getString(R.string.global_search)
searchItem.fixExpandInvalidate()
// Create query listener which opens the global search view.
setOnQueryTextChangeListener(searchView, true) {
if (!it.isNullOrBlank()) performGlobalSearch(it)
true
}
hideItemsIfExpanded(searchItem, menu)
}
}

View File

@ -257,6 +257,7 @@ open class BrowseSourceController(bundle: Bundle) :
}
setIcon(icon)
}
hideItemsIfExpanded(searchItem, menu)
}
override fun onPrepareOptionsMenu(menu: Menu) {

View File

@ -5,7 +5,7 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_search_24dp"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"
app:showAsAction="collapseActionView|ifRoom" />
<item

View File

@ -6,7 +6,7 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_search_24dp"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"
app:showAsAction="collapseActionView|ifRoom" />
<item

View File

@ -6,7 +6,7 @@
android:title="@string/search"
android:icon="@drawable/ic_search_24dp"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"/>
<item
android:id="@+id/action_sort"