From ab97ccee85641cdcfb74926319b7e34c7da629e5 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 15:56:24 +0200 Subject: [PATCH] Added Search History Toggle and Clear in Settings --- .../java/com/github/libretube/SearchFragment.kt | 3 ++- .../java/com/github/libretube/SettingsActivity.kt | 8 ++++++++ app/src/main/res/drawable/ic_trash.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings.xml | 15 +++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_trash.xml diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 2bf76c3ed..bc553a4d8 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -136,7 +136,8 @@ class SearchFragment : Fragment() { GlobalScope.launch { fetchSuggestions(s.toString(), autoTextView) delay(1000) - addtohistory(s.toString()) + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + if (sharedPreferences.getBoolean("search_history_toggle", true)) addtohistory(s.toString()) fetchSearch(s.toString()) } } diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt index 0fb13644e..7e1347b6f 100644 --- a/app/src/main/java/com/github/libretube/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt @@ -9,6 +9,7 @@ import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.os.Bundle +import android.system.Os.remove import android.text.TextUtils import android.util.Log import android.view.View @@ -224,6 +225,13 @@ class SettingsActivity : AppCompatActivity(), true } + val clearHistory = findPreference("clear_history") + clearHistory?.setOnPreferenceClickListener { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + sharedPreferences.edit().remove("search_history").commit() + true + } + val about = findPreference("about") about?.setOnPreferenceClickListener { val uri = Uri.parse("https://libre-tube.github.io/") diff --git a/app/src/main/res/drawable/ic_trash.xml b/app/src/main/res/drawable/ic_trash.xml new file mode 100644 index 000000000..d52cfe83e --- /dev/null +++ b/app/src/main/res/drawable/ic_trash.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 662bdfa3c..6e7281ea0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,4 +77,7 @@ All Playlists Ok + History + Search History + Clear History diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 56ae14456..6a2755c1c 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -93,6 +93,21 @@ + + + + + + + +