From 2c23678fb9026f1800951357eccace8f08c5d815 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Thu, 8 Oct 2020 19:32:47 +0200 Subject: [PATCH] Add button in settings to clear reCAPTCHA cookies --- .../settings/ContentSettingsFragment.java | 19 ++++++++++++++++++- app/src/main/res/values/settings_keys.xml | 2 ++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/content_settings.xml | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index df30a21f3..37431fa58 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -7,13 +7,13 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.preference.PreferenceManager; import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import com.nononsenseapps.filepicker.Utils; import com.nostra13.universalimageloader.core.ImageLoader; @@ -21,6 +21,7 @@ import com.nostra13.universalimageloader.core.ImageLoader; import org.schabi.newpipe.DownloaderImpl; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; +import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; @@ -75,6 +76,22 @@ public class ContentSettingsFragment extends BasePreferenceFragment { .getPreferredContentCountry(requireContext()); initialLanguage = PreferenceManager .getDefaultSharedPreferences(requireContext()).getString("app_language_key", "en"); + + final Preference clearCookiePref = findPreference(getString(R.string.clear_cookie_key)); + + clearCookiePref.setOnPreferenceClickListener(preference -> { + defaultPreferences.edit() + .putString(getString(R.string.recaptcha_cookies_key), "").apply(); + DownloaderImpl.getInstance().setCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY, ""); + Toast.makeText(getActivity(), R.string.recaptcha_cookies_cleared, + Toast.LENGTH_SHORT).show(); + clearCookiePref.setVisible(false); + return true; + }); + + if (defaultPreferences.getString(getString(R.string.recaptcha_cookies_key), "").isEmpty()) { + clearCookiePref.setVisible(false); + } } @Override diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index e7a35041c..ba40ab931 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -246,6 +246,8 @@ import_data export_data + clear_cookie + download_thumbnail_key cache_wipe_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d93288ea8..8fe832276 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -197,8 +197,11 @@ Switch to Main Import database Export database + Clear reCAPTCHA cookies + reCAPTCHA cookies have been cleared Overrides your current history and subscriptions Export history, subscriptions and playlists + Clear cookies that NewPipe stores when you solve a reCAPTCHA Clear watch history Deletes the history of played streams and the playback positions Delete entire watch history? diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index e2af18540..c36e7f0e2 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -97,6 +97,12 @@ android:title="@string/export_data_title" app:iconSpaceReserved="false" /> + +