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
|
|
|
|
2020-01-25 17:00:49 +00:00
|
|
|
import androidx.annotation.Nullable;
|
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;
|
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
|
2020-03-31 17:20:15 +00:00
|
|
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
2020-01-25 17:00:49 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2020-02-29 10:53:04 +00:00
|
|
|
updateSeekOptions();
|
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
|
|
|
|
2020-02-01 12:41:03 +00:00
|
|
|
listener = (sharedPreferences, s) -> {
|
|
|
|
|
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
|
|
|
|
&& s.equals(getString(R.string.minimize_on_exit_key))) {
|
2020-02-01 12:41:03 +00:00
|
|
|
String newSetting = sharedPreferences.getString(s, null);
|
|
|
|
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
|
|
|
}
|
2020-02-29 10:53:04 +00:00
|
|
|
} else if (s.equals(getString(R.string.use_inexact_seek_key))) {
|
|
|
|
updateSeekOptions();
|
2020-01-25 17:00:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
for (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-02-29 10:53:04 +00:00
|
|
|
} catch (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-03-31 17:20:15 +00:00
|
|
|
final ListPreference durations = (ListPreference) findPreference(
|
|
|
|
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-03-03 18:50:50 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-03 06:04:18 +00:00
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
2017-09-03 06:04:18 +00:00
|
|
|
addPreferencesFromResource(R.xml.video_audio_settings);
|
|
|
|
}
|
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
|
|
|
}
|