1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-29 21:42:33 +01:00

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. * 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() { 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 Resources resources = getResources();
final boolean showHigherResolutions = getPreferenceManager().getSharedPreferences() final boolean showHigherResolutions = getPreferenceManager().getSharedPreferences()
.getBoolean(resources.getString(R.string.show_higher_resolutions_key), false); .getBoolean(resources.getString(R.string.show_higher_resolutions_key), false);
// get sorted resolution lists
final List<String> resolutionListDescriptions = ListHelper.getSortedResolutionList( final List<String> resolutionListDescriptions = ListHelper.getSortedResolutionList(
resources, resources,
R.array.resolution_list_description, R.array.resolution_list_description,
@ -89,6 +88,16 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
R.array.limit_data_usage_description_list, R.array.limit_data_usage_description_list,
R.array.high_resolution_list_descriptions, R.array.high_resolution_list_descriptions,
showHigherResolutions); 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.setEntries(resolutionListDescriptions.toArray(new String[0]));
defaultResolution.setEntryValues(resolutionListValues.toArray(new String[0])); defaultResolution.setEntryValues(resolutionListValues.toArray(new String[0]));
defaultPopupResolution.setEntries(resolutionListDescriptions.toArray(new String[0])); defaultPopupResolution.setEntries(resolutionListDescriptions.toArray(new String[0]));
@ -96,6 +105,9 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
mobileDataResolution.setEntries( mobileDataResolution.setEntries(
limitDataUsageResolutionDescriptions.toArray(new String[0])); limitDataUsageResolutionDescriptions.toArray(new String[0]));
mobileDataResolution.setEntryValues(limitDataUsageResolutionValues.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 (!showHigherResolutions) {
if (ListHelper.isHighResolutionSelected(defaultResolution.getValue(), if (ListHelper.isHighResolutionSelected(defaultResolution.getValue(),
R.array.high_resolution_list_values, R.array.high_resolution_list_values,

View File

@ -240,20 +240,31 @@ public final class ListHelper {
videoOnlyStreams, ascendingOrder, preferVideoOnlyStreams); 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( public static List<String> getSortedResolutionList(
final Resources resources, final Resources resources,
final int defaultResolutionKey, final int defaultResolutionKey,
final int additionalResolutionKey, final int additionalResolutionKey,
final boolean showHigherResolutions) { final boolean showHigherResolutions) {
final List<String> defaultResolution = new ArrayList<String>(Arrays.asList( final List<String> resolutions = new ArrayList<>(Arrays.asList(
resources.getStringArray(defaultResolutionKey))); resources.getStringArray(defaultResolutionKey)));
if (!showHigherResolutions) { if (!showHigherResolutions) {
return defaultResolution; return resolutions;
} }
final List<String> additionalResolutions = Arrays.asList( final List<String> additionalResolutions = Arrays.asList(
resources.getStringArray(additionalResolutionKey)); resources.getStringArray(additionalResolutionKey));
defaultResolution.addAll(1, additionalResolutions); // keep "best resolution" at the top
return defaultResolution; resolutions.addAll(1, additionalResolutions);
return resolutions;
} }
public static boolean isHighResolutionSelected(final String selectedResolution, public static boolean isHighResolutionSelected(final String selectedResolution,