renamed to "restricted mode"

This commit is contained in:
Vincent Nagel 2020-04-11 17:26:16 -05:00
parent 5a193d50f6
commit 63087a4311
8 changed files with 38 additions and 31 deletions

View file

@ -137,7 +137,7 @@ public class App extends Application {
getApplicationContext());
final String key = getApplicationContext().getString(R.string.recaptcha_cookies_key);
downloader.setCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY, prefs.getString(key, ""));
downloader.updateAgeRestrictedContentCookies(getApplicationContext());
downloader.updateRestrictedModeCookies(getApplicationContext());
}
private void configureRxJavaErrorHandler() {

View file

@ -44,10 +44,9 @@ import static org.schabi.newpipe.MainActivity.DEBUG;
public final class DownloaderImpl extends Downloader {
public static final String USER_AGENT
= "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0";
public static final String YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY =
"youtube_age_restricted_content_cookie_key";
public static final String YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE = "PREF=f2=8000000";
public static final String YOUTUBE_RESTRICTED_MODE_COOKIE_KEY
= "youtube_restricted_mode_key";
public static final String YOUTUBE_RESTRICTED_MODE_COOKIE = "PREF=f2=8000000";
public static final String YOUTUBE_DOMAIN = "youtube.com";
private static DownloaderImpl instance;
@ -134,7 +133,7 @@ public final class DownloaderImpl extends Downloader {
public String getCookies(final String url) {
List<String> resultCookies = new ArrayList<>();
if (url.contains(YOUTUBE_DOMAIN)) {
String youtubeCookie = getCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY);
String youtubeCookie = getCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY);
if (youtubeCookie != null) {
resultCookies.add(youtubeCookie);
}
@ -159,20 +158,20 @@ public final class DownloaderImpl extends Downloader {
mCookies.remove(key);
}
public void updateAgeRestrictedContentCookies(final Context context) {
String showAgeRestrictedContentKey =
context.getString(R.string.show_age_restricted_content);
boolean showAgeRestrictedContent = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(showAgeRestrictedContentKey, false);
updateAgeRestrictedContentCookies(showAgeRestrictedContent);
public void updateRestrictedModeCookies(final Context context) {
String restrictedModeEnabledKey =
context.getString(R.string.restricted_mode_enabled);
boolean restrictedModeEnabled = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(restrictedModeEnabledKey, false);
updateRestrictedModeCookies(restrictedModeEnabled);
}
public void updateAgeRestrictedContentCookies(final boolean showAgeRestrictedContent) {
if (!showAgeRestrictedContent) {
setCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY,
YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE);
public void updateRestrictedModeCookies(final boolean restrictedModeEnabled) {
if (restrictedModeEnabled) {
setCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY,
YOUTUBE_RESTRICTED_MODE_COOKIE);
} else {
removeCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY);
removeCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY);
}
InfoCache.getInstance().clearCache();
}

View file

@ -46,8 +46,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
private boolean hasTabsChanged = false;
private boolean previousShowAgeRestrictedContent;
private String showAgeRestrictedContentKey;
private boolean previousRestrictedModeEnabled;
private String restrictedModeEnabledKey;
/*//////////////////////////////////////////////////////////////////////////
// Fragment's LifeCycle
@ -70,10 +70,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
}
});
showAgeRestrictedContentKey = getString(R.string.show_age_restricted_content);
previousShowAgeRestrictedContent =
restrictedModeEnabledKey = getString(R.string.restricted_mode_enabled);
previousRestrictedModeEnabled =
PreferenceManager.getDefaultSharedPreferences(getContext())
.getBoolean(showAgeRestrictedContentKey, false);
.getBoolean(restrictedModeEnabledKey, false);
}
@Override
@ -100,11 +100,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public void onResume() {
super.onResume();
boolean showAgeRestrictedContent =
boolean restrictedModeEnabled =
PreferenceManager.getDefaultSharedPreferences(getContext())
.getBoolean(showAgeRestrictedContentKey, false);
if (previousShowAgeRestrictedContent != showAgeRestrictedContent) {
previousShowAgeRestrictedContent = showAgeRestrictedContent;
.getBoolean(restrictedModeEnabledKey, false);
if (previousRestrictedModeEnabled != restrictedModeEnabled) {
previousRestrictedModeEnabled = restrictedModeEnabled;
setupTabs();
} else if (hasTabsChanged) {
setupTabs();

View file

@ -58,7 +58,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
private File newpipeSettings;
private String thumbnailLoadToggleKey;
private String showAgeRestrictedContentKey;
private String restrictedModeEnabledKey;
private Localization initialSelectedLocalization;
private ContentCountry initialSelectedContentCountry;
@ -68,7 +68,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
thumbnailLoadToggleKey = getString(R.string.download_thumbnail_key);
showAgeRestrictedContentKey = getString(R.string.show_age_restricted_content);
restrictedModeEnabledKey = getString(R.string.restricted_mode_enabled);
initialSelectedLocalization = org.schabi.newpipe.util.Localization
.getPreferredLocalization(requireContext());
@ -90,10 +90,10 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
Toast.LENGTH_SHORT).show();
}
if (preference.getKey().equals(showAgeRestrictedContentKey)) {
if (preference.getKey().equals(restrictedModeEnabledKey)) {
Context context = getContext();
if (context != null) {
DownloaderImpl.getInstance().updateAgeRestrictedContentCookies(context);
DownloaderImpl.getInstance().updateRestrictedModeCookies(context);
} else {
Log.w(TAG, "onPreferenceTreeClick: null context");
}