fix checkstyle errors

This commit is contained in:
Vincent Nagel 2020-04-11 16:21:52 -05:00
parent e33cdca1ef
commit 08a6e999b9
3 changed files with 22 additions and 21 deletions

View File

@ -45,7 +45,8 @@ 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_KEY =
"youtube_age_restricted_content_cookie_key";
public static final String YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE = "PREF=f2=8000000";
public static final String YOUTUBE_DOMAIN = "youtube.com";
@ -146,27 +147,30 @@ public final class DownloaderImpl extends Downloader {
return CookieUtils.concatCookies(resultCookies);
}
public String getCookie(final String key){
public String getCookie(final String key) {
return mCookies.get(key);
}
public void setCookie(final String key, final String cookie){
public void setCookie(final String key, final String cookie) {
mCookies.put(key, cookie);
}
public void removeCookie(final String key){
public void removeCookie(final String key) {
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);
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 updateAgeRestrictedContentCookies(boolean showAgeRestrictedContent) {
public void updateAgeRestrictedContentCookies(final boolean showAgeRestrictedContent) {
if (!showAgeRestrictedContent) {
setCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY, YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE);
setCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY,
YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE);
} else {
removeCookie(YOUTUBE_AGE_RESTRICTED_CONTENT_COOKIE_KEY);
}

View File

@ -71,7 +71,9 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
});
showAgeRestrictedContentKey = getString(R.string.show_age_restricted_content);
previousShowAgeRestrictedContent = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(showAgeRestrictedContentKey, false);
previousShowAgeRestrictedContent =
PreferenceManager.getDefaultSharedPreferences(getContext())
.getBoolean(showAgeRestrictedContentKey, false);
}
@Override
@ -98,7 +100,9 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public void onResume() {
super.onResume();
boolean showAgeRestrictedContent = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(showAgeRestrictedContentKey, false);
boolean showAgeRestrictedContent =
PreferenceManager.getDefaultSharedPreferences(getContext())
.getBoolean(showAgeRestrictedContentKey, false);
if (previousShowAgeRestrictedContent != showAgeRestrictedContent) {
previousShowAgeRestrictedContent = showAgeRestrictedContent;
setupTabs();

View File

@ -1,24 +1,17 @@
package org.schabi.newpipe.util;
import android.content.Context;
import android.preference.PreferenceManager;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.R;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class CookieUtils {
public final class CookieUtils {
private CookieUtils() {
}
public static String concatCookies(Collection<String> cookieStrings) {
public static String concatCookies(final Collection<String> cookieStrings) {
Set<String> cookieSet = new HashSet<>();
for (String cookies : cookieStrings) {
cookieSet.addAll(splitCookies(cookies));
@ -26,7 +19,7 @@ public class CookieUtils {
return StringUtil.join(cookieSet, "; ").trim();
}
public static Set<String> splitCookies(String cookies) {
public static Set<String> splitCookies(final String cookies) {
return new HashSet<>(Arrays.asList(cookies.split("; *")));
}
}