2017-09-03 06:04:18 +00:00
|
|
|
package org.schabi.newpipe.settings;
|
|
|
|
|
2020-01-25 17:00:49 +00:00
|
|
|
import android.content.SharedPreferences;
|
2020-02-17 09:10:15 +00:00
|
|
|
import android.content.res.Resources;
|
2020-01-25 17:00:49 +00:00
|
|
|
import android.os.Build;
|
2017-09-03 06:04:18 +00:00
|
|
|
import android.os.Bundle;
|
2020-01-25 17:00:49 +00:00
|
|
|
import android.provider.Settings;
|
2020-03-02 18:54:08 +00:00
|
|
|
import android.text.format.DateUtils;
|
2020-03-02 19:15:54 +00:00
|
|
|
import android.widget.Toast;
|
2020-03-31 17:20:15 +00:00
|
|
|
|
Multiple localization fixes
With the extractor PR, fixes title & description shown in the wrong language.
Fixed views / spectators counts possibly in the wrong language
Fixed live spectators not showing full count on detail page
Fixed LIVE shown on players, it shows translated instead
Fixed Videos string in search / three dots not available in Weblate
(because it was videos, but there already was a plural string named videos, in Weblate)
Subscriber count is always giving the short count.
We can't get exact number since this YouTube update: https://support.google.com/youtube/thread/6543166
But only short count (B, M, k), so showing full number, eg for 1.9M: 1,900,000, is wrong because the number could be 1,923,490 or 1,897,789…
Added a « sytem default » option to content language and country language selector.
It's the one selected by default (not en-GB anymore then), and correspond to the
language of the system / country of the system
By system I mean phone, tablet, TV…
Fixed russian showing - before time ago (eg 19hrs ago)
This is a workaround fix, I opened an issue on prettytime library repo.
Fixed russian plurals:
other was used instead of many for videos and subscribers
Fixed seek_duration english only
2020-02-14 17:19:35 +00:00
|
|
|
import androidx.preference.ListPreference;
|
2020-01-25 17:00:49 +00:00
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2017-09-03 06:04:18 +00:00
|
|
|
|
|
|
|
import org.schabi.newpipe.R;
|
2023-03-28 17:04:26 +00:00
|
|
|
import org.schabi.newpipe.util.ListHelper;
|
2020-01-25 17:00:49 +00:00
|
|
|
import org.schabi.newpipe.util.PermissionHelper;
|
2017-09-03 06:04:18 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2020-01-25 17:00:49 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
public class VideoAudioSettingsFragment extends BasePreferenceFragment {
|
2020-01-25 17:00:49 +00:00
|
|
|
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
|
|
|
|
|
|
|
@Override
|
2021-03-22 20:38:36 +00:00
|
|
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
2021-12-24 20:35:15 +00:00
|
|
|
addPreferencesFromResourceRegistry();
|
2020-01-25 17:00:49 +00:00
|
|
|
|
2020-02-29 10:53:04 +00:00
|
|
|
updateSeekOptions();
|
2023-03-28 17:04:26 +00:00
|
|
|
updateResolutionOptions();
|
2023-01-16 22:05:29 +00:00
|
|
|
listener = (sharedPreferences, key) -> {
|
2020-02-01 12:41:03 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
// on M and above, if user chooses to minimise to popup player on exit
|
|
|
|
// and the app doesn't have display over other apps permission,
|
|
|
|
// show a snackbar to let the user give permission
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
2023-01-16 22:05:29 +00:00
|
|
|
&& getString(R.string.minimize_on_exit_key).equals(key)) {
|
|
|
|
final String newSetting = sharedPreferences.getString(key, null);
|
2020-02-01 12:41:03 +00:00
|
|
|
if (newSetting != null
|
|
|
|
&& newSetting.equals(getString(R.string.minimize_on_exit_popup_key))
|
|
|
|
&& !Settings.canDrawOverlays(getContext())) {
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
Snackbar.make(getListView(), R.string.permission_display_over_apps,
|
|
|
|
Snackbar.LENGTH_INDEFINITE)
|
|
|
|
.setAction(R.string.settings, view ->
|
|
|
|
PermissionHelper.checkSystemAlertWindowPermission(getContext()))
|
2020-02-01 12:41:03 +00:00
|
|
|
.show();
|
|
|
|
|
2020-01-25 17:00:49 +00:00
|
|
|
}
|
2023-01-16 22:05:29 +00:00
|
|
|
} else if (getString(R.string.use_inexact_seek_key).equals(key)) {
|
2020-02-29 10:53:04 +00:00
|
|
|
updateSeekOptions();
|
2023-03-28 17:04:26 +00:00
|
|
|
} else if (getString(R.string.show_higher_resolutions_key).equals(key)) {
|
|
|
|
updateResolutionOptions();
|
2020-01-25 17:00:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-28 17:04:26 +00:00
|
|
|
/**
|
|
|
|
* Update default resolution, default popup resolution & mobile data resolution options.
|
2023-09-17 23:43:14 +00:00
|
|
|
* <br />
|
|
|
|
* Show high resolutions when "Show higher resolution" option is enabled.
|
|
|
|
* Set default resolution to "best resolution" when "Show higher resolution" option
|
|
|
|
* is disabled.
|
2023-03-28 17:04:26 +00:00
|
|
|
*/
|
|
|
|
private void updateResolutionOptions() {
|
|
|
|
final Resources resources = getResources();
|
|
|
|
final boolean showHigherResolutions = getPreferenceManager().getSharedPreferences()
|
|
|
|
.getBoolean(resources.getString(R.string.show_higher_resolutions_key), false);
|
2023-09-17 23:43:14 +00:00
|
|
|
|
|
|
|
// get sorted resolution lists
|
2023-03-28 17:04:26 +00:00
|
|
|
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);
|
2023-09-17 23:43:14 +00:00
|
|
|
|
|
|
|
// 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
|
2023-03-28 17:04:26 +00:00
|
|
|
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]));
|
2023-09-17 23:43:14 +00:00
|
|
|
|
|
|
|
// if "Show higher resolution" option is disabled,
|
|
|
|
// set default resolution to "best resolution"
|
2023-03-28 17:04:26 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 10:53:04 +00:00
|
|
|
/**
|
2020-03-31 17:20:15 +00:00
|
|
|
* Update fast-forward/-rewind seek duration options
|
|
|
|
* according to language and inexact seek setting.
|
2020-02-29 10:53:04 +00:00
|
|
|
* Exoplayer can't seek 5 seconds in audio when using inexact seek.
|
|
|
|
*/
|
|
|
|
private void updateSeekOptions() {
|
2020-03-31 17:20:15 +00:00
|
|
|
// initializing R.array.seek_duration_description to display the translation of seconds
|
2020-02-29 10:53:04 +00:00
|
|
|
final Resources res = getResources();
|
|
|
|
final String[] durationsValues = res.getStringArray(R.array.seek_duration_value);
|
|
|
|
final List<String> displayedDurationValues = new LinkedList<>();
|
|
|
|
final List<String> displayedDescriptionValues = new LinkedList<>();
|
|
|
|
int currentDurationValue;
|
|
|
|
final boolean inexactSeek = getPreferenceManager().getSharedPreferences()
|
2020-03-31 17:20:15 +00:00
|
|
|
.getBoolean(res.getString(R.string.use_inexact_seek_key), false);
|
2020-02-29 10:53:04 +00:00
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
for (final String durationsValue : durationsValues) {
|
2020-03-02 18:54:08 +00:00
|
|
|
currentDurationValue =
|
2020-03-31 17:20:15 +00:00
|
|
|
Integer.parseInt(durationsValue) / (int) DateUtils.SECOND_IN_MILLIS;
|
2020-02-29 10:53:04 +00:00
|
|
|
if (inexactSeek && currentDurationValue % 10 == 5) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-03 20:41:15 +00:00
|
|
|
|
|
|
|
displayedDurationValues.add(durationsValue);
|
2020-02-29 10:53:04 +00:00
|
|
|
try {
|
|
|
|
displayedDescriptionValues.add(String.format(
|
2020-03-31 17:20:15 +00:00
|
|
|
res.getQuantityString(R.plurals.seconds,
|
|
|
|
currentDurationValue),
|
|
|
|
currentDurationValue));
|
2020-08-16 08:24:58 +00:00
|
|
|
} catch (final Resources.NotFoundException ignored) {
|
2020-03-31 17:20:15 +00:00
|
|
|
// if this happens, the translation is missing,
|
|
|
|
// and the english string will be displayed instead
|
2020-02-29 10:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-03 18:50:50 +00:00
|
|
|
|
2020-08-27 20:56:58 +00:00
|
|
|
final ListPreference durations = findPreference(
|
2020-03-31 17:20:15 +00:00
|
|
|
getString(R.string.seek_duration_key));
|
2020-02-29 10:53:04 +00:00
|
|
|
durations.setEntryValues(displayedDurationValues.toArray(new CharSequence[0]));
|
|
|
|
durations.setEntries(displayedDescriptionValues.toArray(new CharSequence[0]));
|
2020-03-02 18:52:42 +00:00
|
|
|
final int selectedDuration = Integer.parseInt(durations.getValue());
|
2020-03-25 21:34:02 +00:00
|
|
|
if (inexactSeek && selectedDuration / (int) DateUtils.SECOND_IN_MILLIS % 10 == 5) {
|
2020-03-02 19:15:54 +00:00
|
|
|
final int newDuration = selectedDuration / (int) DateUtils.SECOND_IN_MILLIS + 5;
|
|
|
|
durations.setValue(Integer.toString(newDuration * (int) DateUtils.SECOND_IN_MILLIS));
|
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
final Toast toast = Toast
|
2020-03-31 17:20:15 +00:00
|
|
|
.makeText(getContext(),
|
|
|
|
getString(R.string.new_seek_duration_toast, newDuration),
|
|
|
|
Toast.LENGTH_LONG);
|
2020-03-02 19:15:54 +00:00
|
|
|
toast.show();
|
2020-02-29 10:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 17:00:49 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2020-03-31 17:20:15 +00:00
|
|
|
getPreferenceManager().getSharedPreferences()
|
|
|
|
.registerOnSharedPreferenceChangeListener(listener);
|
2020-01-25 17:00:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
2020-03-31 17:20:15 +00:00
|
|
|
getPreferenceManager().getSharedPreferences()
|
|
|
|
.unregisterOnSharedPreferenceChangeListener(listener);
|
2020-01-25 17:00:49 +00:00
|
|
|
}
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|