Skip to content

Commit 3c5ed2c

Browse files
authored
Merge pull request #4453 from wb9688/clear-cookies
Add button in settings to clear reCAPTCHA cookies
2 parents c4af93c + 2c23678 commit 3c5ed2c

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
import android.content.Intent;
88
import android.content.SharedPreferences;
99
import android.os.Bundle;
10-
import androidx.preference.PreferenceManager;
1110
import android.util.Log;
1211
import android.widget.Toast;
1312

1413
import androidx.annotation.NonNull;
1514
import androidx.annotation.Nullable;
1615
import androidx.preference.Preference;
16+
import androidx.preference.PreferenceManager;
1717

1818
import com.nononsenseapps.filepicker.Utils;
1919
import com.nostra13.universalimageloader.core.ImageLoader;
2020

2121
import org.schabi.newpipe.DownloaderImpl;
2222
import org.schabi.newpipe.NewPipeDatabase;
2323
import org.schabi.newpipe.R;
24+
import org.schabi.newpipe.ReCaptchaActivity;
2425
import org.schabi.newpipe.extractor.NewPipe;
2526
import org.schabi.newpipe.extractor.localization.ContentCountry;
2627
import org.schabi.newpipe.extractor.localization.Localization;
@@ -75,6 +76,22 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
7576
.getPreferredContentCountry(requireContext());
7677
initialLanguage = PreferenceManager
7778
.getDefaultSharedPreferences(requireContext()).getString("app_language_key", "en");
79+
80+
final Preference clearCookiePref = findPreference(getString(R.string.clear_cookie_key));
81+
82+
clearCookiePref.setOnPreferenceClickListener(preference -> {
83+
defaultPreferences.edit()
84+
.putString(getString(R.string.recaptcha_cookies_key), "").apply();
85+
DownloaderImpl.getInstance().setCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY, "");
86+
Toast.makeText(getActivity(), R.string.recaptcha_cookies_cleared,
87+
Toast.LENGTH_SHORT).show();
88+
clearCookiePref.setVisible(false);
89+
return true;
90+
});
91+
92+
if (defaultPreferences.getString(getString(R.string.recaptcha_cookies_key), "").isEmpty()) {
93+
clearCookiePref.setVisible(false);
94+
}
7895
}
7996

8097
@Override

app/src/main/res/values/settings_keys.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
<string name="import_data" translatable="false">import_data</string>
247247
<string name="export_data" translatable="false">export_data</string>
248248

249+
<string name="clear_cookie_key" translatable="false">clear_cookie</string>
250+
249251
<string name="download_thumbnail_key" translatable="false">download_thumbnail_key</string>
250252

251253
<string name="metadata_cache_wipe_key" translatable="false">cache_wipe_key</string>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,11 @@
197197
<string name="switch_to_main">Switch to Main</string>
198198
<string name="import_data_title">Import database</string>
199199
<string name="export_data_title">Export database</string>
200+
<string name="clear_cookie_title">Clear reCAPTCHA cookies</string>
201+
<string name="recaptcha_cookies_cleared">reCAPTCHA cookies have been cleared</string>
200202
<string name="import_data_summary">Overrides your current history and subscriptions</string>
201203
<string name="export_data_summary">Export history, subscriptions and playlists</string>
204+
<string name="clear_cookie_summary">Clear cookies that NewPipe stores when you solve a reCAPTCHA</string>
202205
<string name="clear_views_history_title">Clear watch history</string>
203206
<string name="clear_views_history_summary">Deletes the history of played streams and the playback positions</string>
204207
<string name="delete_view_history_alert">Delete entire watch history?</string>

app/src/main/res/xml/content_settings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
android:title="@string/export_data_title"
9898
app:iconSpaceReserved="false" />
9999

100+
<Preference
101+
android:key="@string/clear_cookie_key"
102+
android:summary="@string/clear_cookie_summary"
103+
android:title="@string/clear_cookie_title"
104+
app:iconSpaceReserved="false" />
105+
100106
<PreferenceCategory
101107
android:layout="@layout/settings_category_header_layout"
102108
android:title="@string/settings_category_feed_title">

0 commit comments

Comments
 (0)