Skip to content

Commit

Permalink
Clear search immediately closes search
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Apr 1, 2023
1 parent 07330a3 commit 421a0cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>(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
Expand Down

0 comments on commit 421a0cf

Please sign in to comment.