From ee64df7fc91eb2214792c8c90d59606e3ddd4b5f Mon Sep 17 00:00:00 2001 From: Don Kimberlin Date: Sat, 20 Jun 2020 06:10:25 -0700 Subject: [PATCH] Clear search history (#173) * Long press on magnifying glass to clear search history * Long press on magnifying glass to clear search history * Long press on magnifying glass to clear search history * Long press on magnifying glass to clear search history * Long press on magnifying glass to clear search history * Long press on magnifying glass to clear search history --- .../peertube/activity/VideoListActivity.java | 22 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 24 insertions(+) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index 54abbc7..107a200 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -19,8 +19,10 @@ package net.schueller.peertube.activity; import android.Manifest; +import android.app.AlertDialog; import android.app.SearchManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -146,6 +148,26 @@ public class VideoListActivity extends CommonActivity { searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setQueryRefinementEnabled(true); + searchMenuItem.getActionView().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + new AlertDialog.Builder(VideoListActivity.this) + .setTitle(getString(R.string.clear_search_history)) + .setMessage(getString(R.string.clear_search_history_prompt)) + .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getApplicationContext(), + SearchSuggestionsProvider.AUTHORITY, + SearchSuggestionsProvider.MODE); + suggestions.clearHistory(); + } + }) + .setNegativeButton(android.R.string.no, null) + .setIcon(android.R.drawable.ic_dialog_alert) + .show(); + return true; + } + }); searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c9cccd5..fdc857d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,6 +65,8 @@ Application Language Select language for application interface. Restart app for change to take effect. + Clear Search History + Do you want to permanently delete the search history? Abkhazian Afar