From 575e8090043dde229bf9c8b2057c869042a0e6a7 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 6 Jan 2024 17:24:53 +0100 Subject: [PATCH] Don't write defaultFormat setting, use default value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../java/org/schabi/newpipe/util/ListHelper.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java index 71071d997..7cb8f1f37 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java @@ -643,6 +643,7 @@ public final class ListHelper { context.getString(R.string.best_resolution_key), defaultFormat, videoStreams); } + @Nullable private static MediaFormat getDefaultFormat(@NonNull final Context context, @StringRes final int defaultFormatKey, @StringRes final int defaultFormatValueKey) { @@ -651,18 +652,14 @@ public final class ListHelper { final String defaultFormat = context.getString(defaultFormatValueKey); final String defaultFormatString = preferences.getString( - context.getString(defaultFormatKey), defaultFormat); + context.getString(defaultFormatKey), + defaultFormat + ); - MediaFormat defaultMediaFormat = getMediaFormatFromKey(context, defaultFormatString); - if (defaultMediaFormat == null) { - preferences.edit().putString(context.getString(defaultFormatKey), defaultFormat) - .apply(); - defaultMediaFormat = getMediaFormatFromKey(context, defaultFormat); - } - - return defaultMediaFormat; + return getMediaFormatFromKey(context, defaultFormatString); } + @Nullable private static MediaFormat getMediaFormatFromKey(@NonNull final Context context, @NonNull final String formatKey) { MediaFormat format = null;