diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java
index b498bcf308f..a1f563724ee 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java
@@ -57,18 +57,17 @@ && getString(R.string.minimize_on_exit_key).equals(key)) {
/**
* Update default resolution, default popup resolution & mobile data resolution options.
- * show high resolution when "Show higher resolution" option enabled.
+ *
+ * Show high resolutions when "Show higher resolution" option is enabled.
+ * Set default resolution to "best resolution" when "Show higher resolution" option
+ * is disabled.
*/
private void updateResolutionOptions() {
- final ListPreference defaultResolution = findPreference(
- getString(R.string.default_resolution_key));
- final ListPreference defaultPopupResolution = findPreference(
- getString(R.string.default_popup_resolution_key));
- final ListPreference mobileDataResolution = findPreference(
- getString(R.string.limit_mobile_data_usage_key));
final Resources resources = getResources();
final boolean showHigherResolutions = getPreferenceManager().getSharedPreferences()
.getBoolean(resources.getString(R.string.show_higher_resolutions_key), false);
+
+ // get sorted resolution lists
final List resolutionListDescriptions = ListHelper.getSortedResolutionList(
resources,
R.array.resolution_list_description,
@@ -89,6 +88,16 @@ private void updateResolutionOptions() {
R.array.limit_data_usage_description_list,
R.array.high_resolution_list_descriptions,
showHigherResolutions);
+
+ // get resolution preferences
+ final ListPreference defaultResolution = findPreference(
+ getString(R.string.default_resolution_key));
+ final ListPreference defaultPopupResolution = findPreference(
+ getString(R.string.default_popup_resolution_key));
+ final ListPreference mobileDataResolution = findPreference(
+ getString(R.string.limit_mobile_data_usage_key));
+
+ // update resolution preferences with new resolutions, entries & values for each
defaultResolution.setEntries(resolutionListDescriptions.toArray(new String[0]));
defaultResolution.setEntryValues(resolutionListValues.toArray(new String[0]));
defaultPopupResolution.setEntries(resolutionListDescriptions.toArray(new String[0]));
@@ -96,6 +105,9 @@ private void updateResolutionOptions() {
mobileDataResolution.setEntries(
limitDataUsageResolutionDescriptions.toArray(new String[0]));
mobileDataResolution.setEntryValues(limitDataUsageResolutionValues.toArray(new String[0]));
+
+ // if "Show higher resolution" option is disabled,
+ // set default resolution to "best resolution"
if (!showHigherResolutions) {
if (ListHelper.isHighResolutionSelected(defaultResolution.getValue(),
R.array.high_resolution_list_values,
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 ead98211e88..5918ece2544 100644
--- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java
+++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java
@@ -240,20 +240,31 @@ public static List getSortedStreamVideosList(
videoOnlyStreams, ascendingOrder, preferVideoOnlyStreams);
}
+ /**
+ * Get a sorted list containing a set of default resolution info
+ * and additional resolution info if showHigherResolutions is true.
+ *
+ * @param resources the resources to get the resolutions from
+ * @param defaultResolutionKey the settings key of the default resolution
+ * @param additionalResolutionKey the settings key of the additional resolutions
+ * @param showHigherResolutions if higher resolutions should be included in the sorted list
+ * @return a sorted list containing the default and maybe additional resolutions
+ */
public static List getSortedResolutionList(
final Resources resources,
final int defaultResolutionKey,
final int additionalResolutionKey,
final boolean showHigherResolutions) {
- final List defaultResolution = new ArrayList(Arrays.asList(
+ final List resolutions = new ArrayList<>(Arrays.asList(
resources.getStringArray(defaultResolutionKey)));
if (!showHigherResolutions) {
- return defaultResolution;
+ return resolutions;
}
final List additionalResolutions = Arrays.asList(
resources.getStringArray(additionalResolutionKey));
- defaultResolution.addAll(1, additionalResolutions);
- return defaultResolution;
+ // keep "best resolution" at the top
+ resolutions.addAll(1, additionalResolutions);
+ return resolutions;
}
public static boolean isHighResolutionSelected(final String selectedResolution,