Merge pull request #9987 from Edwardsoen/add_high_resolution_to_default_option
Include a high-resolution option in the default resolution settings.
This commit is contained in:
commit
1630e309fb
4 changed files with 131 additions and 1 deletions
|
@ -13,6 +13,7 @@ import androidx.preference.ListPreference;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
import org.schabi.newpipe.util.PermissionHelper;
|
import org.schabi.newpipe.util.PermissionHelper;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -26,7 +27,7 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
|
||||||
addPreferencesFromResourceRegistry();
|
addPreferencesFromResourceRegistry();
|
||||||
|
|
||||||
updateSeekOptions();
|
updateSeekOptions();
|
||||||
|
updateResolutionOptions();
|
||||||
listener = (sharedPreferences, key) -> {
|
listener = (sharedPreferences, key) -> {
|
||||||
|
|
||||||
// on M and above, if user chooses to minimise to popup player on exit
|
// on M and above, if user chooses to minimise to popup player on exit
|
||||||
|
@ -48,10 +49,84 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
|
||||||
}
|
}
|
||||||
} else if (getString(R.string.use_inexact_seek_key).equals(key)) {
|
} else if (getString(R.string.use_inexact_seek_key).equals(key)) {
|
||||||
updateSeekOptions();
|
updateSeekOptions();
|
||||||
|
} else if (getString(R.string.show_higher_resolutions_key).equals(key)) {
|
||||||
|
updateResolutionOptions();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update default resolution, default popup resolution & mobile data resolution options.
|
||||||
|
* <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 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,
|
||||||
|
R.array.high_resolution_list_descriptions,
|
||||||
|
showHigherResolutions);
|
||||||
|
final List<String> resolutionListValues = ListHelper.getSortedResolutionList(
|
||||||
|
resources,
|
||||||
|
R.array.resolution_list_values,
|
||||||
|
R.array.high_resolution_list_values,
|
||||||
|
showHigherResolutions);
|
||||||
|
final List<String> limitDataUsageResolutionValues = ListHelper.getSortedResolutionList(
|
||||||
|
resources,
|
||||||
|
R.array.limit_data_usage_values_list,
|
||||||
|
R.array.high_resolution_limit_data_usage_values_list,
|
||||||
|
showHigherResolutions);
|
||||||
|
final List<String> limitDataUsageResolutionDescriptions = ListHelper
|
||||||
|
.getSortedResolutionList(resources,
|
||||||
|
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]));
|
||||||
|
defaultPopupResolution.setEntryValues(resolutionListValues.toArray(new String[0]));
|
||||||
|
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,
|
||||||
|
resources)) {
|
||||||
|
defaultResolution.setValueIndex(0);
|
||||||
|
}
|
||||||
|
if (ListHelper.isHighResolutionSelected(defaultPopupResolution.getValue(),
|
||||||
|
R.array.high_resolution_list_values,
|
||||||
|
resources)) {
|
||||||
|
defaultPopupResolution.setValueIndex(0);
|
||||||
|
}
|
||||||
|
if (ListHelper.isHighResolutionSelected(mobileDataResolution.getValue(),
|
||||||
|
R.array.high_resolution_limit_data_usage_values_list,
|
||||||
|
resources)) {
|
||||||
|
mobileDataResolution.setValueIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update fast-forward/-rewind seek duration options
|
* Update fast-forward/-rewind seek duration options
|
||||||
* according to language and inexact seek setting.
|
* according to language and inexact seek setting.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -239,6 +240,41 @@ 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(
|
||||||
|
final Resources resources,
|
||||||
|
final int defaultResolutionKey,
|
||||||
|
final int additionalResolutionKey,
|
||||||
|
final boolean showHigherResolutions) {
|
||||||
|
final List<String> resolutions = new ArrayList<>(Arrays.asList(
|
||||||
|
resources.getStringArray(defaultResolutionKey)));
|
||||||
|
if (!showHigherResolutions) {
|
||||||
|
return resolutions;
|
||||||
|
}
|
||||||
|
final List<String> additionalResolutions = Arrays.asList(
|
||||||
|
resources.getStringArray(additionalResolutionKey));
|
||||||
|
// keep "best resolution" at the top
|
||||||
|
resolutions.addAll(1, additionalResolutions);
|
||||||
|
return resolutions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isHighResolutionSelected(final String selectedResolution,
|
||||||
|
final int additionalResolutionKey,
|
||||||
|
final Resources resources) {
|
||||||
|
return Arrays.asList(resources.getStringArray(
|
||||||
|
additionalResolutionKey))
|
||||||
|
.contains(selectedResolution);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the list of audio streams and return a list with the preferred stream for
|
* Filter the list of audio streams and return a list with the preferred stream for
|
||||||
* each audio track. Streams are sorted with the preferred language in the first position.
|
* each audio track. Streams are sorted with the preferred language in the first position.
|
||||||
|
|
|
@ -124,6 +124,16 @@
|
||||||
<string name="default_popup_resolution_value">480p</string>
|
<string name="default_popup_resolution_value">480p</string>
|
||||||
<string name="best_resolution_key">best_resolution</string>
|
<string name="best_resolution_key">best_resolution</string>
|
||||||
|
|
||||||
|
<string-array name="high_resolution_list_values">
|
||||||
|
<item>2160p</item>
|
||||||
|
<item>1440p</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="high_resolution_list_descriptions">
|
||||||
|
<item>2160p</item>
|
||||||
|
<item>1440p</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="resolution_list_values">
|
<string-array name="resolution_list_values">
|
||||||
<item>@string/best_resolution_key</item>
|
<item>@string/best_resolution_key</item>
|
||||||
<item>1080p60</item>
|
<item>1080p60</item>
|
||||||
|
@ -1346,6 +1356,11 @@
|
||||||
<item>144p</item>
|
<item>144p</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="high_resolution_limit_data_usage_values_list">
|
||||||
|
<item>2160p</item>
|
||||||
|
<item>1440p</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="list_view_mode_key">list_view_mode</string>
|
<string name="list_view_mode_key">list_view_mode</string>
|
||||||
<string name="list_view_mode_value">@string/list_view_mode_auto_key</string>
|
<string name="list_view_mode_value">@string/list_view_mode_auto_key</string>
|
||||||
|
|
||||||
|
|
|
@ -541,6 +541,10 @@
|
||||||
<item>240p</item>
|
<item>240p</item>
|
||||||
<item>144p</item>
|
<item>144p</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="high_resolution_limit_data_usage_description_list">
|
||||||
|
<item>2160p</item>
|
||||||
|
<item>1440p</item>
|
||||||
|
</string-array>
|
||||||
<!-- Notifications settings -->
|
<!-- Notifications settings -->
|
||||||
<string name="enable_streams_notifications_title">New streams notifications</string>
|
<string name="enable_streams_notifications_title">New streams notifications</string>
|
||||||
<string name="enable_streams_notifications_summary">Notify about new streams from subscriptions</string>
|
<string name="enable_streams_notifications_summary">Notify about new streams from subscriptions</string>
|
||||||
|
|
Loading…
Reference in a new issue