From 421a0cfcc52d3c9adcf4d7d314aea565ab512eac Mon Sep 17 00:00:00 2001 From: Robb <35880555+robbwatershed@users.noreply.github.com> Date: Sat, 1 Apr 2023 23:34:44 +0200 Subject: [PATCH] Clear search immediately closes search --- .../hentoid/activities/LibraryActivity.java | 26 ++++++++++++++----- .../hentoid/fragments/queue/ErrorsFragment.kt | 7 +++++ .../hentoid/fragments/queue/QueueFragment.kt | 7 +++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/me/devsaki/hentoid/activities/LibraryActivity.java b/app/src/main/java/me/devsaki/hentoid/activities/LibraryActivity.java index fb7a184ad..b9a38029f 100644 --- a/app/src/main/java/me/devsaki/hentoid/activities/LibraryActivity.java +++ b/app/src/main/java/me/devsaki/hentoid/activities/LibraryActivity.java @@ -317,13 +317,7 @@ public void onDrawerClosed(View view) { searchRecords.addAll(records); }); - searchClearDebouncer = new Debouncer<>(this, 1500, i -> { - setQuery(""); - getAdvSearchCriteria().setQuery(""); - signalCurrentFragment(EV_SEARCH, getQuery()); - searchClearButton.setVisibility(View.GONE); - searchSaveButton.setVisibility(View.GONE); - }); + searchClearDebouncer = new Debouncer<>(this, 1500, i -> clearSearch()); if (!Preferences.getRecentVisibility()) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); @@ -539,6 +533,16 @@ public boolean onMenuItemActionCollapse(MenuItem item) { actionSearchView.setImeOptions(IME_FLAG_NO_PERSONALIZED_LEARNING); actionSearchView.setIconifiedByDefault(true); actionSearchView.setQueryHint(getString(R.string.library_search_hint)); + + View clearButton = actionSearchView.findViewById(androidx.appcompat.R.id.search_close_btn); + if (clearButton != null) + clearButton.setOnClickListener(v -> { + invalidateNextQueryTextChange = true; + actionSearchView.setQuery("", false); + actionSearchView.setIconified(true); + clearSearch(); // Immediately; don't use the debouncer + }); + // Change display when text query is typed actionSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override @@ -561,6 +565,14 @@ public boolean onQueryTextChange(String s) { }); } + private void clearSearch() { + setQuery(""); + getAdvSearchCriteria().setQuery(""); + signalCurrentFragment(EV_SEARCH, getQuery()); + searchClearButton.setVisibility(View.GONE); + searchSaveButton.setVisibility(View.GONE); + } + public void initFragmentToolbars( @NonNull final SelectExtension selectExtension, @NonNull final Toolbar.OnMenuItemClickListener toolbarOnItemClicked, diff --git a/app/src/main/java/me/devsaki/hentoid/fragments/queue/ErrorsFragment.kt b/app/src/main/java/me/devsaki/hentoid/fragments/queue/ErrorsFragment.kt index dad25477d..7f3dff817 100644 --- a/app/src/main/java/me/devsaki/hentoid/fragments/queue/ErrorsFragment.kt +++ b/app/src/main/java/me/devsaki/hentoid/fragments/queue/ErrorsFragment.kt @@ -257,6 +257,13 @@ class ErrorsFragment : Fragment(R.layout.fragment_queue_errors), ItemTouchCallba activity.get()?.getToolbar()?.let { val searchMenu = it.menu.findItem(R.id.action_search) val mainSearchView = searchMenu?.actionView as SearchView? + mainSearchView?.findViewById(androidx.appcompat.R.id.search_close_btn) + ?.setOnClickListener { + invalidateNextQueryTextChange = true + mainSearchView.setQuery("", false) + mainSearchView.isIconified = true + viewModel.searchErrorContentUniversal("") + } searchMenu?.setOnActionExpandListener( object : MenuItem.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem): Boolean { diff --git a/app/src/main/java/me/devsaki/hentoid/fragments/queue/QueueFragment.kt b/app/src/main/java/me/devsaki/hentoid/fragments/queue/QueueFragment.kt index 74261cf6e..dd595d018 100644 --- a/app/src/main/java/me/devsaki/hentoid/fragments/queue/QueueFragment.kt +++ b/app/src/main/java/me/devsaki/hentoid/fragments/queue/QueueFragment.kt @@ -279,6 +279,13 @@ class QueueFragment : Fragment(R.layout.fragment_queue), ItemTouchCallback, activity.get()?.getToolbar()?.let { val searchMenu = it.menu.findItem(R.id.action_search) val mainSearchView = searchMenu?.actionView as SearchView? + mainSearchView?.findViewById(androidx.appcompat.R.id.search_close_btn) + ?.setOnClickListener { + invalidateNextQueryTextChange = true + mainSearchView.setQuery("", false) + mainSearchView.isIconified = true + viewModel.searchQueueUniversal("") + } searchMenu.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem): Boolean { invalidateNextQueryTextChange = true