Skip to content

Commit 575e809

Browse files
committed
Don't write defaultFormat setting, use default value
Nowhere else does this (write a setting if it’s not set). It took me a while to see that this code does not do what it intends, because `defaultFormat` is already the default value in the first `context.getString`, so calling `getMediaFormatFromKey` again is the exact same call (“do you know the definition of insanity…”) and will return `null` again … So let’s drop the setting write and just rely on the default values.
1 parent 1d8850d commit 575e809

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

app/src/main/java/org/schabi/newpipe/util/ListHelper.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ private static int getDefaultResolutionWithDefaultFormat(@NonNull final Context
643643
context.getString(R.string.best_resolution_key), defaultFormat, videoStreams);
644644
}
645645

646+
@Nullable
646647
private static MediaFormat getDefaultFormat(@NonNull final Context context,
647648
@StringRes final int defaultFormatKey,
648649
@StringRes final int defaultFormatValueKey) {
@@ -651,18 +652,14 @@ private static MediaFormat getDefaultFormat(@NonNull final Context context,
651652

652653
final String defaultFormat = context.getString(defaultFormatValueKey);
653654
final String defaultFormatString = preferences.getString(
654-
context.getString(defaultFormatKey), defaultFormat);
655+
context.getString(defaultFormatKey),
656+
defaultFormat
657+
);
655658

656-
MediaFormat defaultMediaFormat = getMediaFormatFromKey(context, defaultFormatString);
657-
if (defaultMediaFormat == null) {
658-
preferences.edit().putString(context.getString(defaultFormatKey), defaultFormat)
659-
.apply();
660-
defaultMediaFormat = getMediaFormatFromKey(context, defaultFormat);
661-
}
662-
663-
return defaultMediaFormat;
659+
return getMediaFormatFromKey(context, defaultFormatString);
664660
}
665661

662+
@Nullable
666663
private static MediaFormat getMediaFormatFromKey(@NonNull final Context context,
667664
@NonNull final String formatKey) {
668665
MediaFormat format = null;

0 commit comments

Comments
 (0)