From 090e9ee0051504a9b70132a002c2e759b8bec188 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 7 May 2021 23:16:29 -0400 Subject: [PATCH] Fully extend search view, hiding menu items --- .../eu/kanade/tachiyomi/ui/base/MiniSearchView.kt | 11 +++++++++++ .../tachiyomi/ui/base/controller/BaseController.kt | 12 ++++++++++++ .../kanade/tachiyomi/ui/library/LibraryController.kt | 2 ++ .../kanade/tachiyomi/ui/recents/RecentsController.kt | 1 + .../kanade/tachiyomi/ui/source/BrowseController.kt | 2 ++ .../ui/source/browse/BrowseSourceController.kt | 1 + app/src/main/res/menu/extension_main.xml | 2 +- app/src/main/res/menu/manga_details.xml | 2 +- app/src/main/res/menu/settings_sources.xml | 2 +- 9 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MiniSearchView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MiniSearchView.kt index 4a94b0de01..d09edbd615 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MiniSearchView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MiniSearchView.kt @@ -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(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() + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index 93cfce0972..dfcc9f7bb7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -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(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(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() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index abcb752a75..6e90abe616 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 1a07ee6905..39e207f0db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -619,6 +619,7 @@ class RecentsController(bundle: Bundle? = null) : true } searchItem.fixExpandInvalidate() + hideItemsIfExpanded(searchItem, menu) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt index 65340d7940..81750b587e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index 6e461c99ef..bd85227e50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -257,6 +257,7 @@ open class BrowseSourceController(bundle: Bundle) : } setIcon(icon) } + hideItemsIfExpanded(searchItem, menu) } override fun onPrepareOptionsMenu(menu: Menu) { diff --git a/app/src/main/res/menu/extension_main.xml b/app/src/main/res/menu/extension_main.xml index 245c43e221..2895819718 100644 --- a/app/src/main/res/menu/extension_main.xml +++ b/app/src/main/res/menu/extension_main.xml @@ -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" /> + app:actionViewClass="eu.kanade.tachiyomi.ui.base.MiniSearchView"/>