Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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<String> resolutions = new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.resolution_list_description)));
ArrayList<String> resolutionValues = new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.resolution_list_values)));

ArrayList<String> mobileDataResolutions = new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.limit_data_usage_description_list)));
ArrayList<String> mobileDataResolutionValues = new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.limit_data_usage_values_list)));

if(!show) {
List<String> 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()]));

}


Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

<string-array name="resolution_list_values" translatable="false">
<item>@string/best_resolution_key</item>
<item>2160p</item>
<item>1440p</item>
<item>1080p60</item>
<item>1080p</item>
<item>720p60</item>
Expand All @@ -85,6 +87,8 @@
</string-array>
<string-array name="resolution_list_description" translatable="false">
<item>@string/best_resolution</item>
<item>2160p</item>
<item>1440p</item>
<item>1080p60</item>
<item>1080p</item>
<item>720p60</item>
Expand Down Expand Up @@ -1071,6 +1075,8 @@

<string-array name="limit_data_usage_values_list">
<item>@string/limit_data_usage_none_key</item>
<item>2160p</item>
<item>1440p</item>
<item>1080p60</item>
<item>1080p</item>
<item>720p60</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@
<string name="limit_mobile_data_usage_value" translatable="false">@string/limit_data_usage_none_key</string>
<string-array name="limit_data_usage_description_list">
<item>@string/limit_data_usage_none_description</item>
<item>2160p</item>
<item>1440p</item>
<item>1080p60</item>
<item>1080p</item>
<item>720p60</item>
Expand Down