From 57504acd0017b2825ecbb68a4ff7bec9c7f64fdc Mon Sep 17 00:00:00 2001 From: Xiang Rong Lin <41164160+XiangRongLin@users.noreply.github.com> Date: Sat, 29 Feb 2020 11:23:21 +0100 Subject: [PATCH] If inexact seekt is used, hide 5,15,25 seconds seek duration options when opening settings --- .../settings/VideoAudioSettingsFragment.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) 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 d5f46fb22..5476158c4 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -11,6 +11,8 @@ import androidx.preference.ListPreference; import com.google.android.material.snackbar.Snackbar; +import java.util.LinkedList; +import java.util.List; import org.schabi.newpipe.R; import org.schabi.newpipe.util.PermissionHelper; @@ -26,19 +28,28 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { Resources res = getResources(); String[] durationsValues = res.getStringArray(R.array.seek_duration_value); String[] durationsDescriptions = res.getStringArray(R.array.seek_duration_description); + List durationsValResult = new LinkedList<>(); + List durationsDesResult = new LinkedList<>(); int currentDurationValue; + final boolean inexactSeek = getPreferenceManager().getSharedPreferences() + .getBoolean(res.getString(R.string.use_inexact_seek_key), false); + for (int i = 0; i < durationsDescriptions.length; i++) { currentDurationValue = Integer.parseInt(durationsValues[i]) / 1000; - try { - durationsDescriptions[i] = String.format( + if (inexactSeek && currentDurationValue % 10 != 5) { + try { + durationsValResult.add(durationsValues[i]); + durationsDesResult.add(String.format( res.getQuantityString(R.plurals.dynamic_seek_duration_description, currentDurationValue), - currentDurationValue); - } catch (Resources.NotFoundException ignored) { - //if this happens, the translation is missing, and the english string will be displayed instead + currentDurationValue)); + } catch (Resources.NotFoundException ignored) { + //if this happens, the translation is missing, and the english string will be displayed instead + } } } ListPreference durations = (ListPreference) findPreference(getString(R.string.seek_duration_key)); - durations.setEntries(durationsDescriptions); + durations.setEntryValues(durationsValResult.toArray(new CharSequence[0])); + durations.setEntries(durationsDesResult.toArray(new CharSequence[0])); listener = (sharedPreferences, s) -> { @@ -62,7 +73,6 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { }; } - @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.video_audio_settings);