Merge pull request #4453 from wb9688/clear-cookies

Add button in settings to clear reCAPTCHA cookies
This commit is contained in:
Tobias Groza 2020-10-16 17:25:19 +02:00 committed by GitHub
commit 3c5ed2c885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -246,6 +246,8 @@
<string name="import_data" translatable="false">import_data</string>
<string name="export_data" translatable="false">export_data</string>
<string name="clear_cookie_key" translatable="false">clear_cookie</string>
<string name="download_thumbnail_key" translatable="false">download_thumbnail_key</string>
<string name="metadata_cache_wipe_key" translatable="false">cache_wipe_key</string>

View File

@ -197,8 +197,11 @@
<string name="switch_to_main">Switch to Main</string>
<string name="import_data_title">Import database</string>
<string name="export_data_title">Export database</string>
<string name="clear_cookie_title">Clear reCAPTCHA cookies</string>
<string name="recaptcha_cookies_cleared">reCAPTCHA cookies have been cleared</string>
<string name="import_data_summary">Overrides your current history and subscriptions</string>
<string name="export_data_summary">Export history, subscriptions and playlists</string>
<string name="clear_cookie_summary">Clear cookies that NewPipe stores when you solve a reCAPTCHA</string>
<string name="clear_views_history_title">Clear watch history</string>
<string name="clear_views_history_summary">Deletes the history of played streams and the playback positions</string>
<string name="delete_view_history_alert">Delete entire watch history?</string>

View File

@ -97,6 +97,12 @@
android:title="@string/export_data_title"
app:iconSpaceReserved="false" />
<Preference
android:key="@string/clear_cookie_key"
android:summary="@string/clear_cookie_summary"
android:title="@string/clear_cookie_title"
app:iconSpaceReserved="false" />
<PreferenceCategory
android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_feed_title">