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 d5f46fb220b..bd51c309587 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -14,10 +14,16 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.util.PermissionHelper; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class VideoAudioSettingsFragment extends BasePreferenceFragment { private SharedPreferences.OnSharedPreferenceChangeListener listener; + private ListPreference defaultRes,defaultPopupRes,limitMobDataUsage; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -40,6 +46,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) { ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key)); durations.setEntries(durationsDescriptions); + defaultRes = (ListPreference) findPreference(getString(R.string.default_resolution_key)); + defaultPopupRes = (ListPreference) findPreference(getString(R.string.default_popup_resolution_key)); + limitMobDataUsage = (ListPreference) findPreference(getString(R.string.limit_mobile_data_usage_key)); + listener = (sharedPreferences, s) -> { // on M and above, if user chooses to minimise to popup player on exit and the app doesn't have @@ -59,7 +69,72 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } } + + //check if "show higher resolutions" was changed + if(s.equals(getString(R.string.show_higher_resolutions_key))){ + + if(checkIfShowHighRes()){ + showHigherResolutions(true); + } + else { + + //if the setting was turned off and any of the defaults is set to 1440p or 2160p, change them to 1080p60 + //(the next highest value) + if(defaultRes.getValue().equals("1440p") || defaultRes.getValue().equals("2160p")){ + defaultRes.setValueIndex(3); + } + if(defaultPopupRes.getValue().equals("1440p") || defaultPopupRes.getValue().equals("2160p")){ + defaultPopupRes.setValueIndex(3); + } + if(limitMobDataUsage.getValue().equals("1440p") || limitMobDataUsage.getValue().equals("2160p")){ + limitMobDataUsage.setValueIndex(3); + } + + showHigherResolutions(false); + + } + } + }; + + //if "show higher resolutions" is off, remove the higher resolutions from the default resolutions lists + if(!checkIfShowHighRes()){ + showHigherResolutions(false); + } + } + + private boolean checkIfShowHighRes(){ + return getPreferenceManager().getSharedPreferences().getBoolean(getString(R.string.show_higher_resolutions_key),false); + } + + private void showHigherResolutions(boolean show){ + + Resources res = getResources(); + ArrayList resolutions = new ArrayList(Arrays.asList(res.getStringArray(R.array.resolution_list_description))); + ArrayList resolutionValues = new ArrayList(Arrays.asList(res.getStringArray(R.array.resolution_list_values))); + + ArrayList mobileDataResolutions = new ArrayList(Arrays.asList(res.getStringArray(R.array.limit_data_usage_description_list))); + ArrayList mobileDataResolutionValues = new ArrayList(Arrays.asList(res.getStringArray(R.array.limit_data_usage_values_list))); + + if(!show) { + List higherResolutions = Arrays.asList("1440p", "2160p"); + + resolutions.removeAll(higherResolutions); + resolutionValues.removeAll(higherResolutions); + + mobileDataResolutions.removeAll(higherResolutions); + mobileDataResolutionValues.removeAll(higherResolutions); + } + + defaultRes.setEntries(resolutions.toArray(new String[resolutions.size()])); + defaultRes.setEntryValues(resolutionValues.toArray(new String[resolutionValues.size()])); + + defaultPopupRes.setEntries(resolutions.toArray(new String[resolutions.size()])); + defaultPopupRes.setEntryValues(resolutionValues.toArray(new String[resolutionValues.size()])); + + limitMobDataUsage.setEntries(mobileDataResolutions.toArray(new String[mobileDataResolutions.size()])); + limitMobDataUsage.setEntryValues(mobileDataResolutionValues.toArray(new String[mobileDataResolutionValues.size()])); + } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index fe096c9fddd..bfa7a5865e5 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -74,6 +74,8 @@ @string/best_resolution_key + 2160p + 1440p 1080p60 1080p 720p60 @@ -85,6 +87,8 @@ @string/best_resolution + 2160p + 1440p 1080p60 1080p 720p60 @@ -1071,6 +1075,8 @@ @string/limit_data_usage_none_key + 2160p + 1440p 1080p60 1080p 720p60 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42b4b77c594..4c62f350bd4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -506,6 +506,8 @@ @string/limit_data_usage_none_key @string/limit_data_usage_none_description + 2160p + 1440p 1080p60 1080p 720p60