Use final where possible

This commit is contained in:
wb9688 2020-08-16 10:24:58 +02:00
parent d306513319
commit 87228673b4
132 changed files with 1024 additions and 1005 deletions

View file

@ -84,11 +84,11 @@ public final class AnimationUtils {
String id;
try {
id = view.getResources().getResourceEntryName(view.getId());
} catch (Exception e) {
} catch (final Exception e) {
id = view.getId() + "";
}
String msg = String.format("%8s → [%s:%s] [%s %s:%s] execOnEnd=%s", enterOrExit,
final String msg = String.format("%8s → [%s:%s] [%s %s:%s] execOnEnd=%s", enterOrExit,
view.getClass().getSimpleName(), id, animationType, duration, delay, execOnEnd);
Log.d(TAG, "animateView()" + msg);
}
@ -158,7 +158,7 @@ public final class AnimationUtils {
}
final int[][] empty = new int[][]{new int[0]};
ValueAnimator viewPropertyAnimator = ValueAnimator
final ValueAnimator viewPropertyAnimator = ValueAnimator
.ofObject(new ArgbEvaluator(), colorStart, colorEnd);
viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator());
viewPropertyAnimator.setDuration(duration);
@ -201,7 +201,7 @@ public final class AnimationUtils {
+ "colorStart = [" + colorStart + "], colorEnd = [" + colorEnd + "]");
}
ValueAnimator viewPropertyAnimator = ValueAnimator
final ValueAnimator viewPropertyAnimator = ValueAnimator
.ofObject(new ArgbEvaluator(), colorStart, colorEnd);
viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator());
viewPropertyAnimator.setDuration(duration);
@ -233,7 +233,7 @@ public final class AnimationUtils {
+ "from " + height + " to → " + targetHeight + " in: " + view);
}
ValueAnimator animator = ValueAnimator.ofFloat(height, targetHeight);
final ValueAnimator animator = ValueAnimator.ofFloat(height, targetHeight);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(duration);
animator.addUpdateListener(animation -> {
@ -462,7 +462,7 @@ public final class AnimationUtils {
public static void slideUp(final View view, final long duration, final long delay,
@FloatRange(from = 0.0f, to = 1.0f)
final float translationPercent) {
int translationY = (int) (view.getResources().getDisplayMetrics().heightPixels
final int translationY = (int) (view.getResources().getDisplayMetrics().heightPixels
* (translationPercent));
view.animate().setListener(null).cancel();

View file

@ -14,14 +14,14 @@ public final class BitmapUtils {
return null;
}
float sourceWidth = inputBitmap.getWidth();
float sourceHeight = inputBitmap.getHeight();
final float sourceWidth = inputBitmap.getWidth();
final float sourceHeight = inputBitmap.getHeight();
float xScale = newWidth / sourceWidth;
float yScale = newHeight / sourceHeight;
final float xScale = newWidth / sourceWidth;
final float yScale = newHeight / sourceHeight;
float newXScale;
float newYScale;
final float newXScale;
final float newYScale;
if (yScale > xScale) {
newXScale = xScale / yScale;
@ -31,15 +31,14 @@ public final class BitmapUtils {
newYScale = yScale / xScale;
}
float scaledWidth = newXScale * sourceWidth;
float scaledHeight = newYScale * sourceHeight;
final float scaledWidth = newXScale * sourceWidth;
final float scaledHeight = newYScale * sourceHeight;
int left = (int) ((sourceWidth - scaledWidth) / 2);
int top = (int) ((sourceHeight - scaledHeight) / 2);
int width = (int) scaledWidth;
int height = (int) scaledHeight;
final int left = (int) ((sourceWidth - scaledWidth) / 2);
final int top = (int) ((sourceHeight - scaledHeight) / 2);
final int width = (int) scaledWidth;
final int height = (int) scaledHeight;
return Bitmap.createBitmap(inputBitmap, left, top, width, height);
}
}

View file

@ -37,12 +37,12 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
if (!(v instanceof TextView)) {
return false;
}
TextView widget = (TextView) v;
Object text = widget.getText();
final TextView widget = (TextView) v;
final Object text = widget.getText();
if (text instanceof Spanned) {
Spannable buffer = (Spannable) text;
final Spannable buffer = (Spannable) text;
int action = event.getAction();
final int action = event.getAction();
if (action == MotionEvent.ACTION_UP
|| action == MotionEvent.ACTION_DOWN) {
@ -55,11 +55,11 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
final Layout layout = widget.getLayout();
final int line = layout.getLineForVertical(y);
final int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off,
final ClickableSpan[] link = buffer.getSpans(off, off,
ClickableSpan.class);
if (link.length != 0) {
@ -86,17 +86,17 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
private boolean handleUrl(final Context context, final URLSpan urlSpan) {
String url = urlSpan.getURL();
int seconds = -1;
Matcher matcher = TIMESTAMP_PATTERN.matcher(url);
final Matcher matcher = TIMESTAMP_PATTERN.matcher(url);
if (matcher.matches()) {
url = matcher.group(1);
seconds = Integer.parseInt(matcher.group(2));
}
StreamingService service;
StreamingService.LinkType linkType;
final StreamingService service;
final StreamingService.LinkType linkType;
try {
service = NewPipe.getServiceByUrl(url);
linkType = service.getLinkTypeByUrl(url);
} catch (ExtractionException e) {
} catch (final ExtractionException e) {
return false;
}
if (linkType == StreamingService.LinkType.NONE) {
@ -112,18 +112,20 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
private boolean playOnPopup(final Context context, final String url,
final StreamingService service, final int seconds) {
LinkHandlerFactory factory = service.getStreamLHFactory();
String cleanUrl = null;
final LinkHandlerFactory factory = service.getStreamLHFactory();
final String cleanUrl;
try {
cleanUrl = factory.getUrl(factory.getId(url));
} catch (ParsingException e) {
} catch (final ParsingException e) {
return false;
}
Single single = ExtractorHelper.getStreamInfo(service.getServiceId(), cleanUrl, false);
final Single single
= ExtractorHelper.getStreamInfo(service.getServiceId(), cleanUrl, false);
single.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(info -> {
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info, seconds * 1000);
final PlayQueue playQueue
= new SinglePlayQueue((StreamInfo) info, seconds * 1000);
NavigationHelper.playOnPopupPlayer(context, playQueue, false);
});
return true;

View file

@ -12,8 +12,8 @@ public final class CookieUtils {
}
public static String concatCookies(final Collection<String> cookieStrings) {
Set<String> cookieSet = new HashSet<>();
for (String cookies : cookieStrings) {
final Set<String> cookieSet = new HashSet<>();
for (final String cookies : cookieStrings) {
cookieSet.addAll(splitCookies(cookies));
}
return TextUtils.join("; ", cookieSet).trim();

View file

@ -27,7 +27,7 @@ public final class DeviceUtils {
return isTV;
}
PackageManager pm = App.getApp().getPackageManager();
final PackageManager pm = App.getApp().getPackageManager();
// from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check
boolean isTv = ((UiModeManager) context.getSystemService(UI_MODE_SERVICE))
@ -37,7 +37,8 @@ public final class DeviceUtils {
// from https://stackoverflow.com/a/58932366
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
boolean isBatteryAbsent = ((BatteryManager) context.getSystemService(BATTERY_SERVICE))
final boolean isBatteryAbsent
= ((BatteryManager) context.getSystemService(BATTERY_SERVICE))
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) == 0;
isTv = isTv || (isBatteryAbsent
&& !pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)

View file

@ -101,7 +101,7 @@ public final class ExtractorHelper {
public static Single<List<String>> suggestionsFor(final int serviceId, final String query) {
checkServiceId(serviceId);
return Single.fromCallable(() -> {
SuggestionExtractor extractor = NewPipe.getService(serviceId)
final SuggestionExtractor extractor = NewPipe.getService(serviceId)
.getSuggestionExtractor();
return extractor != null
? extractor.suggestionList(query)
@ -212,10 +212,10 @@ public final class ExtractorHelper {
final InfoItem.InfoType infoType,
final Single<I> loadFromNetwork) {
checkServiceId(serviceId);
Single<I> actualLoadFromNetwork = loadFromNetwork
final Single<I> actualLoadFromNetwork = loadFromNetwork
.doOnSuccess(info -> CACHE.putInfo(serviceId, url, info, infoType));
Single<I> load;
final Single<I> load;
if (forceLoad) {
CACHE.removeInfo(serviceId, url, infoType);
load = actualLoadFromNetwork;
@ -243,7 +243,7 @@ public final class ExtractorHelper {
checkServiceId(serviceId);
return Maybe.defer(() -> {
//noinspection unchecked
I info = (I) CACHE.getFromKey(serviceId, url, infoType);
final I info = (I) CACHE.getFromKey(serviceId, url, infoType);
if (MainActivity.DEBUG) {
Log.d(TAG, "loadFromCache() called, info > " + info);
}
@ -283,7 +283,7 @@ public final class ExtractorHelper {
if (exception instanceof ReCaptchaException) {
Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
// Starting ReCaptcha Challenge Activity
Intent intent = new Intent(context, ReCaptchaActivity.class);
final Intent intent = new Intent(context, ReCaptchaActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else if (ExceptionUtils.isNetworkRelated(exception)) {
@ -293,7 +293,7 @@ public final class ExtractorHelper {
} else if (exception instanceof ContentNotSupportedException) {
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
} else {
int errorId = exception instanceof YoutubeStreamExtractor.DecryptException
final int errorId = exception instanceof YoutubeStreamExtractor.DecryptException
? R.string.youtube_signature_decryption_error
: exception instanceof ParsingException
? R.string.parsing_error : R.string.general_error;

View file

@ -22,7 +22,7 @@ public final class FilenameUtils {
* @return the filename
*/
public static String createFilename(final Context context, final String title) {
SharedPreferences sharedPreferences = PreferenceManager
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
final String charsetLd = context.getString(R.string.charset_letters_and_digits_value);
@ -48,7 +48,7 @@ public final class FilenameUtils {
charset = selectedCharset; // Is the user using a custom charset?
}
Pattern pattern = Pattern.compile(charset);
final Pattern pattern = Pattern.compile(charset);
return createFilename(title, pattern, replacementChar);
}

View file

@ -59,7 +59,7 @@ public final class InfoCache {
}
private static void removeStaleCache() {
for (Map.Entry<String, CacheData> entry : InfoCache.LRU_CACHE.snapshot().entrySet()) {
for (final Map.Entry<String, CacheData> entry : InfoCache.LRU_CACHE.snapshot().entrySet()) {
final CacheData data = entry.getValue();
if (data != null && data.isExpired()) {
InfoCache.LRU_CACHE.remove(entry.getKey());

View file

@ -20,7 +20,7 @@ public class LayoutManagerSmoothScroller extends LinearLayoutManager {
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView,
final RecyclerView.State state, final int position) {
RecyclerView.SmoothScroller smoothScroller
final RecyclerView.SmoothScroller smoothScroller
= new TopSnappedSmoothScroller(recyclerView.getContext());
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);

View file

@ -44,7 +44,7 @@ public final class ListHelper {
*/
public static int getDefaultResolutionIndex(final Context context,
final List<VideoStream> videoStreams) {
String defaultResolution = computeDefaultResolution(context,
final String defaultResolution = computeDefaultResolution(context,
R.string.default_resolution_key, R.string.default_resolution_value);
return getDefaultResolutionWithDefaultFormat(context, defaultResolution, videoStreams);
}
@ -70,7 +70,7 @@ public final class ListHelper {
*/
public static int getPopupDefaultResolutionIndex(final Context context,
final List<VideoStream> videoStreams) {
String defaultResolution = computeDefaultResolution(context,
final String defaultResolution = computeDefaultResolution(context,
R.string.default_popup_resolution_key, R.string.default_popup_resolution_value);
return getDefaultResolutionWithDefaultFormat(context, defaultResolution, videoStreams);
}
@ -90,8 +90,8 @@ public final class ListHelper {
public static int getDefaultAudioFormat(final Context context,
final List<AudioStream> audioStreams) {
MediaFormat defaultFormat = getDefaultFormat(context, R.string.default_audio_format_key,
R.string.default_audio_format_value);
final MediaFormat defaultFormat = getDefaultFormat(context,
R.string.default_audio_format_key, R.string.default_audio_format_value);
// If the user has chosen to limit resolution to conserve mobile data
// usage then we should also limit our audio usage.
@ -117,12 +117,13 @@ public final class ListHelper {
final List<VideoStream>
videoOnlyStreams,
final boolean ascendingOrder) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences
= PreferenceManager.getDefaultSharedPreferences(context);
boolean showHigherResolutions = preferences.getBoolean(
final boolean showHigherResolutions = preferences.getBoolean(
context.getString(R.string.show_higher_resolutions_key), false);
MediaFormat defaultFormat = getDefaultFormat(context, R.string.default_video_format_key,
R.string.default_video_format_value);
final MediaFormat defaultFormat = getDefaultFormat(context,
R.string.default_video_format_key, R.string.default_video_format_value);
return getSortedStreamVideosList(defaultFormat, showHigherResolutions, videoStreams,
videoOnlyStreams, ascendingOrder);
@ -134,14 +135,15 @@ public final class ListHelper {
private static String computeDefaultResolution(final Context context, final int key,
final int value) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences
= PreferenceManager.getDefaultSharedPreferences(context);
// Load the prefered resolution otherwise the best available
String resolution = preferences != null
? preferences.getString(context.getString(key), context.getString(value))
: context.getString(R.string.best_resolution_key);
String maxResolution = getResolutionLimit(context);
final String maxResolution = getResolutionLimit(context);
if (maxResolution != null
&& (resolution.equals(context.getString(R.string.best_resolution_key))
|| compareVideoStreamResolution(maxResolution, resolution) < 1)) {
@ -173,7 +175,7 @@ public final class ListHelper {
return 0;
}
int defaultStreamIndex
final int defaultStreamIndex
= getVideoStreamIndex(defaultResolution, defaultFormat, videoStreams);
// this is actually an error,
@ -200,11 +202,11 @@ public final class ListHelper {
final List<VideoStream> videoStreams,
final List<VideoStream> videoOnlyStreams,
final boolean ascendingOrder) {
ArrayList<VideoStream> retList = new ArrayList<>();
HashMap<String, VideoStream> hashMap = new HashMap<>();
final ArrayList<VideoStream> retList = new ArrayList<>();
final HashMap<String, VideoStream> hashMap = new HashMap<>();
if (videoOnlyStreams != null) {
for (VideoStream stream : videoOnlyStreams) {
for (final VideoStream stream : videoOnlyStreams) {
if (!showHigherResolutions
&& HIGH_RESOLUTION_LIST.contains(stream.getResolution())) {
continue;
@ -213,7 +215,7 @@ public final class ListHelper {
}
}
if (videoStreams != null) {
for (VideoStream stream : videoStreams) {
for (final VideoStream stream : videoStreams) {
if (!showHigherResolutions
&& HIGH_RESOLUTION_LIST.contains(stream.getResolution())) {
continue;
@ -223,12 +225,12 @@ public final class ListHelper {
}
// Add all to the hashmap
for (VideoStream videoStream : retList) {
for (final VideoStream videoStream : retList) {
hashMap.put(videoStream.getResolution(), videoStream);
}
// Override the values when the key == resolution, with the defaultFormat
for (VideoStream videoStream : retList) {
for (final VideoStream videoStream : retList) {
if (videoStream.getFormat() == defaultFormat) {
hashMap.put(videoStream.getResolution(), videoStream);
}
@ -262,7 +264,7 @@ public final class ListHelper {
private static void sortStreamList(final List<VideoStream> videoStreams,
final boolean ascendingOrder) {
Collections.sort(videoStreams, (o1, o2) -> {
int result = compareVideoStreamResolution(o1, o2);
final int result = compareVideoStreamResolution(o1, o2);
return result == 0 ? 0 : (ascendingOrder ? result : -result);
});
}
@ -282,7 +284,7 @@ public final class ListHelper {
while (result == -1) {
AudioStream prevStream = null;
for (int idx = 0; idx < audioStreams.size(); idx++) {
AudioStream stream = audioStreams.get(idx);
final AudioStream stream = audioStreams.get(idx);
if ((format == null || stream.getFormat() == format)
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
AUDIO_FORMAT_QUALITY_RANKING) < 0)) {
@ -314,7 +316,7 @@ public final class ListHelper {
while (result == -1) {
AudioStream prevStream = null;
for (int idx = 0; idx < audioStreams.size(); idx++) {
AudioStream stream = audioStreams.get(idx);
final AudioStream stream = audioStreams.get(idx);
if ((format == null || stream.getFormat() == format)
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) {
@ -357,12 +359,13 @@ public final class ListHelper {
int resMatchOnlyIndex = -1;
int resMatchOnlyNoRefreshIndex = -1;
int lowerResMatchNoRefreshIndex = -1;
String targetResolutionNoRefresh = targetResolution.replaceAll("p\\d+$", "p");
final String targetResolutionNoRefresh = targetResolution.replaceAll("p\\d+$", "p");
for (int idx = 0; idx < videoStreams.size(); idx++) {
MediaFormat format = targetFormat == null ? null : videoStreams.get(idx).getFormat();
String resolution = videoStreams.get(idx).getResolution();
String resolutionNoRefresh = resolution.replaceAll("p\\d+$", "p");
final MediaFormat format
= targetFormat == null ? null : videoStreams.get(idx).getFormat();
final String resolution = videoStreams.get(idx).getResolution();
final String resolutionNoRefresh = resolution.replaceAll("p\\d+$", "p");
if (format == targetFormat && resolution.equals(targetResolution)) {
fullMatchIndex = idx;
@ -414,8 +417,8 @@ public final class ListHelper {
private static int getDefaultResolutionWithDefaultFormat(final Context context,
final String defaultResolution,
final List<VideoStream> videoStreams) {
MediaFormat defaultFormat = getDefaultFormat(context, R.string.default_video_format_key,
R.string.default_video_format_value);
final MediaFormat defaultFormat = getDefaultFormat(context,
R.string.default_video_format_key, R.string.default_video_format_value);
return getDefaultResolutionIndex(defaultResolution,
context.getString(R.string.best_resolution_key), defaultFormat, videoStreams);
}
@ -423,10 +426,11 @@ public final class ListHelper {
private static MediaFormat getDefaultFormat(final Context context,
@StringRes final int defaultFormatKey,
@StringRes final int defaultFormatValueKey) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences
= PreferenceManager.getDefaultSharedPreferences(context);
String defaultFormat = context.getString(defaultFormatValueKey);
String defaultFormatString = preferences.getString(
final String defaultFormat = context.getString(defaultFormatValueKey);
final String defaultFormatString = preferences.getString(
context.getString(defaultFormatKey), defaultFormat);
MediaFormat defaultMediaFormat = getMediaFormatFromKey(context, defaultFormatString);
@ -479,9 +483,9 @@ public final class ListHelper {
}
private static int compareVideoStreamResolution(final String r1, final String r2) {
int res1 = Integer.parseInt(r1.replaceAll("0p\\d+$", "1")
final int res1 = Integer.parseInt(r1.replaceAll("0p\\d+$", "1")
.replaceAll("[^\\d.]", ""));
int res2 = Integer.parseInt(r2.replaceAll("0p\\d+$", "1")
final int res2 = Integer.parseInt(r2.replaceAll("0p\\d+$", "1")
.replaceAll("[^\\d.]", ""));
return res1 - res2;
}
@ -496,7 +500,7 @@ public final class ListHelper {
return 1;
}
int resComp = compareVideoStreamResolution(streamA.getResolution(),
final int resComp = compareVideoStreamResolution(streamA.getResolution(),
streamB.getResolution());
if (resComp != 0) {
return resComp;
@ -521,9 +525,10 @@ public final class ListHelper {
private static String getResolutionLimit(final Context context) {
String resolutionLimit = null;
if (isMeteredNetwork(context)) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String defValue = context.getString(R.string.limit_data_usage_none_key);
String value = preferences.getString(
final SharedPreferences preferences
= PreferenceManager.getDefaultSharedPreferences(context);
final String defValue = context.getString(R.string.limit_data_usage_none_key);
final String value = preferences.getString(
context.getString(R.string.limit_mobile_data_usage_key), defValue);
resolutionLimit = defValue.equals(value) ? null : value;
}
@ -537,7 +542,7 @@ public final class ListHelper {
* @return {@code true} if connected to a metered network
*/
public static boolean isMeteredNetwork(final Context context) {
ConnectivityManager manager
final ConnectivityManager manager
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager == null || manager.getActiveNetworkInfo() == null) {
return false;

View file

@ -110,19 +110,19 @@ public final class Localization {
}
public static Locale getPreferredLocale(final Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String languageCode = sp.getString(context.getString(R.string.content_language_key),
final String languageCode = sp.getString(context.getString(R.string.content_language_key),
context.getString(R.string.default_localization_key));
try {
if (languageCode.length() == 2) {
return new Locale(languageCode);
} else if (languageCode.contains("_")) {
String country = languageCode.substring(languageCode.indexOf("_"));
final String country = languageCode.substring(languageCode.indexOf("_"));
return new Locale(languageCode.substring(0, 2), country);
}
} catch (Exception ignored) {
} catch (final Exception ignored) {
}
return Locale.getDefault();
@ -133,7 +133,7 @@ public final class Localization {
}
public static String localizeNumber(final Context context, final double number) {
NumberFormat nf = NumberFormat.getInstance(getAppLocale(context));
final NumberFormat nf = NumberFormat.getInstance(getAppLocale(context));
return nf.format(number);
}
@ -184,7 +184,7 @@ public final class Localization {
}
public static String shortCount(final Context context, final long count) {
double value = (double) count;
final double value = (double) count;
if (count >= 1000000000) {
return localizeNumber(context, round(value / 1000000000, 1))
+ context.getString(R.string.short_billion);
@ -230,8 +230,8 @@ public final class Localization {
// is not the responsibility of this method handle long numbers
// (it probably will fall in the "other" category,
// or some language have some specific rule... then we have to change it)
int safeCount = count > Integer.MAX_VALUE ? Integer.MAX_VALUE : count < Integer.MIN_VALUE
? Integer.MIN_VALUE : (int) count;
final int safeCount = count > Integer.MAX_VALUE ? Integer.MAX_VALUE
: count < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) count;
return context.getResources().getQuantityString(pluralId, safeCount, formattedCount);
}
@ -305,30 +305,30 @@ public final class Localization {
}
public static String relativeTime(final Calendar calendarTime) {
String time = getPrettyTime().formatUnrounded(calendarTime);
final String time = getPrettyTime().formatUnrounded(calendarTime);
return time.startsWith("-") ? time.substring(1) : time;
//workaround fix for russian showing -1 day ago, -19hrs ago
}
private static void changeAppLanguage(final Locale loc, final Resources res) {
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
final DisplayMetrics dm = res.getDisplayMetrics();
final Configuration conf = res.getConfiguration();
conf.setLocale(loc);
res.updateConfiguration(conf, dm);
}
public static Locale getAppLocale(final Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString(context.getString(R.string.app_language_key), "en");
Locale loc;
final Locale loc;
if (lang.equals(context.getString(R.string.default_localization_key))) {
loc = Locale.getDefault();
} else if (lang.matches(".*-.*")) {
//to differentiate different versions of the language
//for example, pt (portuguese in Portugal) and pt-br (portuguese in Brazil)
String[] localisation = lang.split("-");
final String[] localisation = lang.split("-");
lang = localisation[0];
String country = localisation[1];
final String country = localisation[1];
loc = new Locale(lang, country);
} else {
loc = new Locale(lang);

View file

@ -74,7 +74,7 @@ public final class NavigationHelper {
@NonNull final PlayQueue playQueue,
@Nullable final String quality,
final boolean resumePlayback) {
Intent intent = new Intent(context, targetClazz);
final Intent intent = new Intent(context, targetClazz);
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
if (cacheKey != null) {
@ -243,27 +243,27 @@ public final class NavigationHelper {
return;
}
AudioStream audioStream = info.getAudioStreams().get(index);
final AudioStream audioStream = info.getAudioStreams().get(index);
playOnExternalPlayer(context, info.getName(), info.getUploaderName(), audioStream);
}
public static void playOnExternalVideoPlayer(final Context context, final StreamInfo info) {
ArrayList<VideoStream> videoStreamsList = new ArrayList<>(
final ArrayList<VideoStream> videoStreamsList = new ArrayList<>(
ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), null, false));
int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
final int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
if (index == -1) {
Toast.makeText(context, R.string.video_streams_empty, Toast.LENGTH_SHORT).show();
return;
}
VideoStream videoStream = videoStreamsList.get(index);
final VideoStream videoStream = videoStreamsList.get(index);
playOnExternalPlayer(context, info.getName(), info.getUploaderName(), videoStream);
}
public static void playOnExternalPlayer(final Context context, final String name,
final String artist, final Stream stream) {
Intent intent = new Intent();
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(stream.getUrl()), stream.getFormat().getMimeType());
intent.putExtra(Intent.EXTRA_TITLE, name);
@ -282,7 +282,7 @@ public final class NavigationHelper {
new AlertDialog.Builder(context)
.setMessage(R.string.no_player_found)
.setPositiveButton(R.string.install, (dialog, which) -> {
Intent i = new Intent();
final Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(context.getString(R.string.fdroid_vlc_url)));
context.startActivity(i);
@ -313,7 +313,7 @@ public final class NavigationHelper {
public static void gotoMainFragment(final FragmentManager fragmentManager) {
ImageLoader.getInstance().clearMemoryCache();
boolean popped = fragmentManager.popBackStackImmediate(MAIN_FRAGMENT_TAG, 0);
final boolean popped = fragmentManager.popBackStackImmediate(MAIN_FRAGMENT_TAG, 0);
if (!popped) {
openMainFragment(fragmentManager);
}
@ -483,7 +483,7 @@ public final class NavigationHelper {
public static void openSearch(final Context context, final int serviceId,
final String searchString) {
Intent mIntent = new Intent(context, MainActivity.class);
final Intent mIntent = new Intent(context, MainActivity.class);
mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId);
mIntent.putExtra(Constants.KEY_SEARCH_STRING, searchString);
mIntent.putExtra(Constants.KEY_OPEN_SEARCH, true);
@ -496,7 +496,7 @@ public final class NavigationHelper {
public static void openChannel(final Context context, final int serviceId,
final String url, final String name) {
Intent openIntent = getOpenIntent(context, url, serviceId,
final Intent openIntent = getOpenIntent(context, url, serviceId,
StreamingService.LinkType.CHANNEL);
if (name != null && !name.isEmpty()) {
openIntent.putExtra(Constants.KEY_TITLE, name);
@ -511,7 +511,7 @@ public final class NavigationHelper {
public static void openVideoDetail(final Context context, final int serviceId,
final String url, final String title) {
Intent openIntent = getOpenIntent(context, url, serviceId,
final Intent openIntent = getOpenIntent(context, url, serviceId,
StreamingService.LinkType.STREAM);
if (title != null && !title.isEmpty()) {
openIntent.putExtra(Constants.KEY_TITLE, title);
@ -520,26 +520,26 @@ public final class NavigationHelper {
}
public static void openMainActivity(final Context context) {
Intent mIntent = new Intent(context, MainActivity.class);
final Intent mIntent = new Intent(context, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(mIntent);
}
public static void openRouterActivity(final Context context, final String url) {
Intent mIntent = new Intent(context, RouterActivity.class);
final Intent mIntent = new Intent(context, RouterActivity.class);
mIntent.setData(Uri.parse(url));
mIntent.putExtra(RouterActivity.INTERNAL_ROUTE_KEY, true);
context.startActivity(mIntent);
}
public static void openAbout(final Context context) {
Intent intent = new Intent(context, AboutActivity.class);
final Intent intent = new Intent(context, AboutActivity.class);
context.startActivity(intent);
}
public static void openSettings(final Context context) {
Intent intent = new Intent(context, SettingsActivity.class);
final Intent intent = new Intent(context, SettingsActivity.class);
context.startActivity(intent);
}
@ -548,7 +548,7 @@ public final class NavigationHelper {
activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
return false;
}
Intent intent = new Intent(activity, DownloadActivity.class);
final Intent intent = new Intent(activity, DownloadActivity.class);
activity.startActivity(intent);
return true;
}
@ -559,7 +559,7 @@ public final class NavigationHelper {
private static Intent getServicePlayerActivityIntent(final Context context,
final Class activityClass) {
Intent intent = new Intent(context, activityClass);
final Intent intent = new Intent(context, activityClass);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
@ -571,7 +571,7 @@ public final class NavigationHelper {
private static Intent getOpenIntent(final Context context, final String url,
final int serviceId, final StreamingService.LinkType type) {
Intent mIntent = new Intent(context, MainActivity.class);
final Intent mIntent = new Intent(context, MainActivity.class);
mIntent.putExtra(Constants.KEY_SERVICE_ID, serviceId);
mIntent.putExtra(Constants.KEY_URL, url);
mIntent.putExtra(Constants.KEY_LINK_TYPE, type);
@ -585,14 +585,14 @@ public final class NavigationHelper {
public static Intent getIntentByLink(final Context context, final StreamingService service,
final String url) throws ExtractionException {
StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
final StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
if (linkType == StreamingService.LinkType.NONE) {
throw new ExtractionException("Url not known to service. service=" + service
+ " url=" + url);
}
Intent rIntent = getOpenIntent(context, url, service.getServiceId(), linkType);
final Intent rIntent = getOpenIntent(context, url, service.getServiceId(), linkType);
if (linkType == StreamingService.LinkType.STREAM) {
rIntent.putExtra(VideoDetailFragment.AUTO_PLAY,
@ -621,7 +621,7 @@ public final class NavigationHelper {
try {
// Try market:// scheme
context.startActivity(new Intent(Intent.ACTION_VIEW, openMarketUrl(packageName)));
} catch (ActivityNotFoundException e) {
} catch (final ActivityNotFoundException e) {
// Fall back to google play URL (don't worry F-Droid can handle it :)
context.startActivity(new Intent(Intent.ACTION_VIEW, getGooglePlayUrl(packageName)));
}
@ -648,7 +648,7 @@ public final class NavigationHelper {
* @param videoURL the url to the video
*/
public static void playWithKore(final Context context, final Uri videoURL) {
Intent intent = new Intent(Intent.ACTION_VIEW);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(context.getString(R.string.kore_package));
intent.setData(videoURL);
context.startActivity(intent);

View file

@ -23,27 +23,27 @@ public final class PeertubeHelper {
private PeertubeHelper() { }
public static List<PeertubeInstance> getInstanceList(final Context context) {
SharedPreferences sharedPreferences = PreferenceManager
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
String savedInstanceListKey = context.getString(R.string.peertube_instance_list_key);
final String savedInstanceListKey = context.getString(R.string.peertube_instance_list_key);
final String savedJson = sharedPreferences.getString(savedInstanceListKey, null);
if (null == savedJson) {
return Collections.singletonList(getCurrentInstance());
}
try {
JsonArray array = JsonParser.object().from(savedJson).getArray("instances");
List<PeertubeInstance> result = new ArrayList<>();
for (Object o : array) {
final JsonArray array = JsonParser.object().from(savedJson).getArray("instances");
final List<PeertubeInstance> result = new ArrayList<>();
for (final Object o : array) {
if (o instanceof JsonObject) {
JsonObject instance = (JsonObject) o;
String name = instance.getString("name");
String url = instance.getString("url");
final JsonObject instance = (JsonObject) o;
final String name = instance.getString("name");
final String url = instance.getString("url");
result.add(new PeertubeInstance(url, name));
}
}
return result;
} catch (JsonParserException e) {
} catch (final JsonParserException e) {
return Collections.singletonList(getCurrentInstance());
}
@ -51,13 +51,14 @@ public final class PeertubeHelper {
public static PeertubeInstance selectInstance(final PeertubeInstance instance,
final Context context) {
SharedPreferences sharedPreferences = PreferenceManager
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
String selectedInstanceKey = context.getString(R.string.peertube_selected_instance_key);
JsonStringWriter jsonWriter = JsonWriter.string().object();
final String selectedInstanceKey
= context.getString(R.string.peertube_selected_instance_key);
final JsonStringWriter jsonWriter = JsonWriter.string().object();
jsonWriter.value("name", instance.getName());
jsonWriter.value("url", instance.getUrl());
String jsonToSave = jsonWriter.end().done();
final String jsonToSave = jsonWriter.end().done();
sharedPreferences.edit().putString(selectedInstanceKey, jsonToSave).apply();
ServiceList.PeerTube.setInstance(instance);
return instance;

View file

@ -101,12 +101,12 @@ public final class PermissionHelper {
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean checkSystemAlertWindowPermission(final Context context) {
if (!Settings.canDrawOverlays(context)) {
Intent i = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
final Intent i = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + context.getPackageName()));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(i);
} catch (ActivityNotFoundException ignored) {
} catch (final ActivityNotFoundException ignored) {
}
return false;
} else {
@ -120,8 +120,9 @@ public final class PermissionHelper {
}
public static void showPopupEnablementToast(final Context context) {
Toast toast = Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG);
TextView messageView = toast.getView().findViewById(android.R.id.message);
final Toast toast
= Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG);
final TextView messageView = toast.getView().findViewById(android.R.id.message);
if (messageView != null) {
messageView.setGravity(Gravity.CENTER);
}

View file

@ -16,11 +16,11 @@ public class RelatedStreamInfo extends ListInfo<InfoItem> {
}
public static RelatedStreamInfo getInfo(final StreamInfo info) {
ListLinkHandler handler = new ListLinkHandler(
final ListLinkHandler handler = new ListLinkHandler(
info.getOriginalUrl(), info.getUrl(), info.getId(), Collections.emptyList(), null);
RelatedStreamInfo relatedStreamInfo = new RelatedStreamInfo(
final RelatedStreamInfo relatedStreamInfo = new RelatedStreamInfo(
info.getServiceId(), handler, info.getName());
List<InfoItem> streams = new ArrayList<>();
final List<InfoItem> streams = new ArrayList<>();
streams.addAll(info.getRelatedStreams());
relatedStreamInfo.setRelatedItems(streams);
return relatedStreamInfo;

View file

@ -39,9 +39,9 @@ public class SecondaryStreamHelper<T extends Stream> {
return null;
}
boolean m4v = videoStream.getFormat() == MediaFormat.MPEG_4;
final boolean m4v = videoStream.getFormat() == MediaFormat.MPEG_4;
for (AudioStream audio : audioStreams) {
for (final AudioStream audio : audioStreams) {
if (audio.getFormat() == (m4v ? MediaFormat.M4A : MediaFormat.WEBMA)) {
return audio;
}
@ -53,7 +53,7 @@ public class SecondaryStreamHelper<T extends Stream> {
// retry, but this time in reverse order
for (int i = audioStreams.size() - 1; i >= 0; i--) {
AudioStream audio = audioStreams.get(i);
final AudioStream audio = audioStreams.get(i);
if (audio.getFormat() == MediaFormat.WEBMA_OPUS) {
return audio;
}

View file

@ -117,7 +117,7 @@ public final class ServiceHelper {
int serviceId;
try {
serviceId = NewPipe.getService(serviceName).getServiceId();
} catch (ExtractionException e) {
} catch (final ExtractionException e) {
serviceId = DEFAULT_FALLBACK_SERVICE.getServiceId();
}
@ -128,7 +128,7 @@ public final class ServiceHelper {
String serviceName;
try {
serviceName = NewPipe.getService(serviceId).getServiceInfo().getName();
} catch (ExtractionException e) {
} catch (final ExtractionException e) {
serviceName = DEFAULT_FALLBACK_SERVICE.getServiceInfo().getName();
}
@ -136,7 +136,7 @@ public final class ServiceHelper {
}
public static void setSelectedServiceId(final Context context, final String serviceName) {
int serviceId = NewPipe.getIdOfService(serviceName);
final int serviceId = NewPipe.getIdOfService(serviceName);
if (serviceId == -1) {
setSelectedServicePreferences(context,
DEFAULT_FALLBACK_SERVICE.getServiceInfo().getName());
@ -170,29 +170,29 @@ public final class ServiceHelper {
public static void initService(final Context context, final int serviceId) {
if (serviceId == ServiceList.PeerTube.getServiceId()) {
SharedPreferences sharedPreferences = PreferenceManager
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
String json = sharedPreferences.getString(context.getString(
final String json = sharedPreferences.getString(context.getString(
R.string.peertube_selected_instance_key), null);
if (null == json) {
return;
}
JsonObject jsonObject = null;
final JsonObject jsonObject;
try {
jsonObject = JsonParser.object().from(json);
} catch (JsonParserException e) {
} catch (final JsonParserException e) {
return;
}
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
PeertubeInstance instance = new PeertubeInstance(url, name);
final String name = jsonObject.getString("name");
final String url = jsonObject.getString("url");
final PeertubeInstance instance = new PeertubeInstance(url, name);
ServiceList.PeerTube.setInstance(instance);
}
}
public static void initServices(final Context context) {
for (StreamingService s : ServiceList.all()) {
for (final StreamingService s : ServiceList.all()) {
initService(context, s.getServiceId());
}
}

View file

@ -77,7 +77,7 @@ public final class ShareUtils {
* @param url the url to share
*/
public static void shareUrl(final Context context, final String subject, final String url) {
Intent intent = new Intent(Intent.ACTION_SEND);
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, url);

View file

@ -66,7 +66,7 @@ public final class StateSaver {
* @param context used to get the available cache dir
*/
public static void init(final Context context) {
File externalCacheDir = context.getExternalCacheDir();
final File externalCacheDir = context.getExternalCacheDir();
if (externalCacheDir != null) {
cacheDirPath = externalCacheDir.getAbsolutePath();
}
@ -86,7 +86,7 @@ public final class StateSaver {
return null;
}
SavedState savedState = outState.getParcelable(KEY_SAVED_STATE);
final SavedState savedState = outState.getParcelable(KEY_SAVED_STATE);
if (savedState == null) {
return null;
}
@ -122,7 +122,7 @@ public final class StateSaver {
return savedState;
}
File file = new File(savedState.getPathFileSaved());
final File file = new File(savedState.getPathFileSaved());
if (!file.exists()) {
if (MainActivity.DEBUG) {
Log.d(TAG, "Cache file doesn't exist: " + file.getAbsolutePath());
@ -131,7 +131,7 @@ public final class StateSaver {
}
fileInputStream = new FileInputStream(file);
ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
final ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
//noinspection unchecked
savedObjects = (Queue<Object>) inputStream.readObject();
if (savedObjects != null) {
@ -139,13 +139,13 @@ public final class StateSaver {
}
return savedState;
} catch (Exception e) {
} catch (final Exception e) {
Log.e(TAG, "Failed to restore state", e);
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException ignored) {
} catch (final IOException ignored) {
}
}
}
@ -165,7 +165,7 @@ public final class StateSaver {
@Nullable final SavedState savedState, final Bundle outState,
final WriteRead writeRead) {
@NonNull
String currentSavedPrefix;
final String currentSavedPrefix;
if (savedState == null || TextUtils.isEmpty(savedState.getPrefixFileSaved())) {
// Generate unique prefix
currentSavedPrefix = System.nanoTime() - writeRead.hashCode() + "";
@ -215,7 +215,7 @@ public final class StateSaver {
+ "writeRead = [" + writeRead + "]");
}
LinkedList<Object> savedObjects = new LinkedList<>();
final LinkedList<Object> savedObjects = new LinkedList<>();
writeRead.writeTo(savedObjects);
if (isChangingConfig) {
@ -247,36 +247,36 @@ public final class StateSaver {
}
}
File file = new File(cacheDir, prefixFileName
final File file = new File(cacheDir, prefixFileName
+ (TextUtils.isEmpty(suffixFileName) ? ".cache" : suffixFileName));
if (file.exists() && file.length() > 0) {
// If the file already exists, just return it
return new SavedState(prefixFileName, file.getAbsolutePath());
} else {
// Delete any file that contains the prefix
File[] files = cacheDir.listFiles(new FilenameFilter() {
final File[] files = cacheDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.contains(prefixFileName);
}
});
for (File fileToDelete : files) {
for (final File fileToDelete : files) {
fileToDelete.delete();
}
}
fileOutputStream = new FileOutputStream(file);
ObjectOutputStream outputStream = new ObjectOutputStream(fileOutputStream);
final ObjectOutputStream outputStream = new ObjectOutputStream(fileOutputStream);
outputStream.writeObject(savedObjects);
return new SavedState(prefixFileName, file.getAbsolutePath());
} catch (Exception e) {
} catch (final Exception e) {
Log.e(TAG, "Failed to save state", e);
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException ignored) { }
} catch (final IOException ignored) { }
}
}
return null;
@ -298,7 +298,7 @@ public final class StateSaver {
try {
//noinspection ResultOfMethodCallIgnored
new File(savedState.getPathFileSaved()).delete();
} catch (Exception ignored) {
} catch (final Exception ignored) {
}
}
}
@ -319,7 +319,7 @@ public final class StateSaver {
cacheDir = new File(cacheDir, CACHE_DIR_NAME);
if (cacheDir.exists()) {
for (File file : cacheDir.listFiles()) {
for (final File file : cacheDir.listFiles()) {
file.delete();
}
}

View file

@ -76,7 +76,7 @@ public enum StreamDialogEntry {
*/
public static void setEnabledEntries(final StreamDialogEntry... entries) {
// cleanup from last time StreamDialogEntry was used
for (StreamDialogEntry streamDialogEntry : values()) {
for (final StreamDialogEntry streamDialogEntry : values()) {
streamDialogEntry.customAction = null;
}
@ -84,7 +84,7 @@ public enum StreamDialogEntry {
}
public static String[] getCommands(final Context context) {
String[] commands = new String[enabledEntries.length];
final String[] commands = new String[enabledEntries.length];
for (int i = 0; i != enabledEntries.length; ++i) {
commands[i] = context.getResources().getString(enabledEntries[i].resource);
}

View file

@ -111,7 +111,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
String qualityString;
if (stream instanceof VideoStream) {
VideoStream videoStream = ((VideoStream) stream);
final VideoStream videoStream = ((VideoStream) stream);
qualityString = videoStream.getResolution();
if (secondaryStreams != null) {
@ -123,7 +123,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
}
}
} else if (stream instanceof AudioStream) {
AudioStream audioStream = ((AudioStream) stream);
final AudioStream audioStream = ((AudioStream) stream);
qualityString = audioStream.getAverageBitrate() > 0
? audioStream.getAverageBitrate() + "kbps"
: audioStream.getFormat().getName();
@ -137,10 +137,11 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
}
if (streamsWrapper.getSizeInBytes(position) > 0) {
SecondaryStreamHelper secondary = secondaryStreams == null ? null
final SecondaryStreamHelper secondary = secondaryStreams == null ? null
: secondaryStreams.get(position);
if (secondary != null) {
long size = secondary.getSizeInBytes() + streamsWrapper.getSizeInBytes(position);
final long size
= secondary.getSizeInBytes() + streamsWrapper.getSizeInBytes(position);
sizeView.setText(Utility.formatBytes(size));
} else {
sizeView.setText(streamsWrapper.getFormattedSize(position));
@ -204,7 +205,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
final StreamSizeWrapper<X> streamsWrapper) {
final Callable<Boolean> fetchAndSet = () -> {
boolean hasChanged = false;
for (X stream : streamsWrapper.getStreamsList()) {
for (final X stream : streamsWrapper.getStreamsList()) {
if (streamsWrapper.getSizeInBytes(stream) > -2) {
continue;
}

View file

@ -27,7 +27,7 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory {
private SSLSocketFactory internalSSLSocketFactory;
public TLSSocketFactoryCompat() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
final SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
internalSSLSocketFactory = context.getSocketFactory();
}
@ -35,7 +35,7 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory {
public TLSSocketFactoryCompat(final TrustManager[] tm)
throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
final SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tm, new java.security.SecureRandom());
internalSSLSocketFactory = context.getSocketFactory();
}

View file

@ -126,11 +126,11 @@ public final class ThemeHelper {
*/
@StyleRes
public static int getThemeForService(final Context context, final int serviceId) {
String lightTheme = context.getResources().getString(R.string.light_theme_key);
String darkTheme = context.getResources().getString(R.string.dark_theme_key);
String blackTheme = context.getResources().getString(R.string.black_theme_key);
final String lightTheme = context.getResources().getString(R.string.light_theme_key);
final String darkTheme = context.getResources().getString(R.string.dark_theme_key);
final String blackTheme = context.getResources().getString(R.string.black_theme_key);
String selectedTheme = getSelectedThemeString(context);
final String selectedTheme = getSelectedThemeString(context);
int defaultTheme = R.style.DarkTheme;
if (selectedTheme.equals(lightTheme)) {
@ -148,7 +148,7 @@ public final class ThemeHelper {
final StreamingService service;
try {
service = NewPipe.getService(serviceId);
} catch (ExtractionException ignored) {
} catch (final ExtractionException ignored) {
return defaultTheme;
}
@ -162,7 +162,7 @@ public final class ThemeHelper {
}
themeName += "." + service.getServiceInfo().getName();
int resourceId = context
final int resourceId = context
.getResources()
.getIdentifier(themeName, "style", context.getPackageName());
@ -175,11 +175,11 @@ public final class ThemeHelper {
@StyleRes
public static int getSettingsThemeStyle(final Context context) {
String lightTheme = context.getResources().getString(R.string.light_theme_key);
String darkTheme = context.getResources().getString(R.string.dark_theme_key);
String blackTheme = context.getResources().getString(R.string.black_theme_key);
final String lightTheme = context.getResources().getString(R.string.light_theme_key);
final String darkTheme = context.getResources().getString(R.string.dark_theme_key);
final String blackTheme = context.getResources().getString(R.string.black_theme_key);
String selectedTheme = getSelectedThemeString(context);
final String selectedTheme = getSelectedThemeString(context);
if (selectedTheme.equals(lightTheme)) {
return R.style.LightSettingsTheme;
@ -201,8 +201,8 @@ public final class ThemeHelper {
* @return resource ID
*/
public static int resolveResourceIdFromAttr(final Context context, @AttrRes final int attr) {
TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
int attributeResourceId = a.getResourceId(0, 0);
final TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
final int attributeResourceId = a.getResourceId(0, 0);
a.recycle();
return attributeResourceId;
}
@ -226,8 +226,8 @@ public final class ThemeHelper {
}
private static String getSelectedThemeString(final Context context) {
String themeKey = context.getString(R.string.theme_key);
String defaultTheme = context.getResources().getString(R.string.default_theme_value);
final String themeKey = context.getString(R.string.theme_key);
final String defaultTheme = context.getResources().getString(R.string.default_theme_value);
return PreferenceManager.getDefaultSharedPreferences(context)
.getString(themeKey, defaultTheme);
}

View file

@ -44,10 +44,10 @@ public final class ZipHelper {
*/
public static void addFileToZip(final ZipOutputStream outZip, final String file,
final String name) throws Exception {
byte[] data = new byte[BUFFER_SIZE];
FileInputStream fi = new FileInputStream(file);
BufferedInputStream inputStream = new BufferedInputStream(fi, BUFFER_SIZE);
ZipEntry entry = new ZipEntry(name);
final byte[] data = new byte[BUFFER_SIZE];
final FileInputStream fi = new FileInputStream(file);
final BufferedInputStream inputStream = new BufferedInputStream(fi, BUFFER_SIZE);
final ZipEntry entry = new ZipEntry(name);
outZip.putNextEntry(entry);
int count;
while ((count = inputStream.read(data, 0, BUFFER_SIZE)) != -1) {
@ -69,11 +69,11 @@ public final class ZipHelper {
public static boolean extractFileFromZip(final String filePath, final String file,
final String name) throws Exception {
ZipInputStream inZip = new ZipInputStream(
final ZipInputStream inZip = new ZipInputStream(
new BufferedInputStream(
new FileInputStream(filePath)));
byte[] data = new byte[BUFFER_SIZE];
final byte[] data = new byte[BUFFER_SIZE];
boolean found = false;
@ -82,14 +82,14 @@ public final class ZipHelper {
if (ze.getName().equals(name)) {
found = true;
// delete old file first
File oldFile = new File(file);
final File oldFile = new File(file);
if (oldFile.exists()) {
if (!oldFile.delete()) {
throw new Exception("Could not delete " + file);
}
}
FileOutputStream outFile = new FileOutputStream(file);
final FileOutputStream outFile = new FileOutputStream(file);
int count = 0;
while ((count = inZip.read(data)) != -1) {
outFile.write(data, 0, count);