Add documentation to increase maintainablilty

Rename a variable
This commit is contained in:
TobiGr 2023-09-18 01:43:14 +02:00
parent d1a82a85cd
commit 19640d5e7c
2 changed files with 34 additions and 11 deletions

View File

@ -57,18 +57,17 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
/**
* Update default resolution, default popup resolution & mobile data resolution options.
* show high resolution when "Show higher resolution" option enabled.
* <br />
* 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<String> resolutionListDescriptions = ListHelper.getSortedResolutionList(
resources,
R.array.resolution_list_description,
@ -89,6 +88,16 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
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 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
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,

View File

@ -240,20 +240,31 @@ public final class ListHelper {
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<String> getSortedResolutionList(
final Resources resources,
final int defaultResolutionKey,
final int additionalResolutionKey,
final boolean showHigherResolutions) {
final List<String> defaultResolution = new ArrayList<String>(Arrays.asList(
final List<String> resolutions = new ArrayList<>(Arrays.asList(
resources.getStringArray(defaultResolutionKey)));
if (!showHigherResolutions) {
return defaultResolution;
return resolutions;
}
final List<String> 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,