From 62c0e6605ca7c28c5b66cf1d9775f268b7a4e66b Mon Sep 17 00:00:00 2001 From: kt programs Date: Tue, 1 Mar 2022 16:27:20 +0800 Subject: [PATCH] Remember adjustment step size for playback controls (speed and pitch) - Add adjustment_step_key to settings_keys.xml to be used when saving/loading the step size. - Remove the global stepSize variable and the code that saves it to outState/loads it from savedInstanceState because it's now saved to Shared Preferences. - Move initially setting step size to setupStepSizeSelector to be consistent with the other view setup methods, using the value loaded from Shared Preferences. - Save the step size to Shared Preferences inside setStepSize. Fixes: #7031 --- .../player/helper/PlaybackParameterDialog.java | 18 +++++++++--------- app/src/main/res/values/settings_keys.xml | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 0fe500965..2834b93ae 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -71,7 +71,6 @@ public class PlaybackParameterDialog extends DialogFragment { private double tempo = DEFAULT_TEMPO; private double pitch = DEFAULT_PITCH; private int semitones = DEFAULT_SEMITONES; - private double stepSize = DEFAULT_STEP; @Nullable private SeekBar tempoSlider; @@ -147,7 +146,6 @@ public class PlaybackParameterDialog extends DialogFragment { tempo = savedInstanceState.getDouble(TEMPO_KEY, DEFAULT_TEMPO); pitch = savedInstanceState.getDouble(PITCH_KEY, DEFAULT_PITCH); semitones = percentToSemitones(pitch); - stepSize = savedInstanceState.getDouble(STEP_SIZE_KEY, DEFAULT_STEP); } } @@ -159,7 +157,6 @@ public class PlaybackParameterDialog extends DialogFragment { outState.putDouble(TEMPO_KEY, getCurrentTempo()); outState.putDouble(PITCH_KEY, getCurrentPitch()); - outState.putDouble(STEP_SIZE_KEY, getCurrentStepSize()); } /*////////////////////////////////////////////////////////////////////////// @@ -203,7 +200,7 @@ public class PlaybackParameterDialog extends DialogFragment { togglePitchSliderType(rootView); - setStepSize(stepSize); + setupStepSizeSelector(rootView); } private void togglePitchSliderType(@NonNull final View rootView) { @@ -380,6 +377,10 @@ public class PlaybackParameterDialog extends DialogFragment { } private void setupStepSizeSelector(@NonNull final View rootView) { + setStepSize(PreferenceManager + .getDefaultSharedPreferences(requireContext()) + .getFloat(getString(R.string.adjustment_step_key), (float) DEFAULT_STEP)); + final TextView stepSizeOnePercentText = rootView.findViewById(R.id.stepSizeOnePercent); final TextView stepSizeFivePercentText = rootView.findViewById(R.id.stepSizeFivePercent); final TextView stepSizeTenPercentText = rootView.findViewById(R.id.stepSizeTenPercent); @@ -438,7 +439,10 @@ public class PlaybackParameterDialog extends DialogFragment { } private void setStepSize(final double stepSize) { - this.stepSize = stepSize; + PreferenceManager.getDefaultSharedPreferences(requireContext()) + .edit() + .putFloat(getString(R.string.adjustment_step_key), (float) stepSize) + .apply(); if (tempoStepUpText != null) { tempoStepUpText.setText(getStepUpPercentString(stepSize)); @@ -665,10 +669,6 @@ public class PlaybackParameterDialog extends DialogFragment { return semitoneSlider == null ? semitones : semitoneSlider.getProgress() - 12; } - private double getCurrentStepSize() { - return stepSize; - } - private boolean getCurrentSkipSilence() { return skipSilenceCheckbox != null && skipSilenceCheckbox.isChecked(); } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index ddceec2f1..5e9fc2220 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -258,6 +258,7 @@ main_page_content enable_playback_resume enable_playback_state_lists + adjustment_step_key playback_unhook_key playback_speed_key playback_pitch_key