From 0f22833ad58f165c312dbf0dcb6c6b1ba72ae43b Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 2 Feb 2020 15:52:35 +0100 Subject: [PATCH 1/2] Save and restore whether pitch and tempo are unhooked or not Fixes #1536 --- .../helper/PlaybackParameterDialog.java | 24 ++++++++++++++----- app/src/main/res/values/settings_keys.xml | 1 + 2 files changed, 19 insertions(+), 6 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 3ada3a6be..94fb412f7 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 @@ -7,6 +7,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; + +import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.CheckBox; @@ -219,13 +221,23 @@ public class PlaybackParameterDialog extends DialogFragment { private void setupHookingControl(@NonNull View rootView) { unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox); if (unhookingCheckbox != null) { - unhookingCheckbox.setChecked(pitch != tempo); + // restore whether pitch and tempo are unhooked or not + unhookingCheckbox.setChecked(PreferenceManager.getDefaultSharedPreferences(getContext()) + .getBoolean(getString(R.string.playback_unhook_key), true)); + unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> { - if (isChecked) return; - // When unchecked, slide back to the minimum of current tempo or pitch - final double minimum = Math.min(getCurrentPitch(), getCurrentTempo()); - setSliders(minimum); - setCurrentPlaybackParameters(); + // save whether pitch and tempo are unhooked or not + PreferenceManager.getDefaultSharedPreferences(getContext()) + .edit() + .putBoolean(getString(R.string.playback_unhook_key), isChecked) + .apply(); + + if (!isChecked) { + // when unchecked, slide back to the minimum of current tempo or pitch + final double minimum = Math.min(getCurrentPitch(), getCurrentTempo()); + setSliders(minimum); + setCurrentPlaybackParameters(); + } }); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 1a7d61dae..e46904b6d 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -175,6 +175,7 @@ main_page_content enable_playback_resume enable_playback_state_lists + playback_unhook_key app_language_key enable_lock_screen_video_thumbnail From 244009a1cd06492518c2159a505dd8e5cc9a0bb6 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 2 Feb 2020 15:54:31 +0100 Subject: [PATCH 2/2] Change "Unlink" to "Unhook" in unhook_checkbox string "Unlink" is not an english word, and "Unhook" is used everywhere in the code --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 763eb7426..a35cbe804 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -492,7 +492,7 @@ Playback Speed Controls Tempo Pitch - Unlink (may cause distortion) + Unhook (may cause distortion) Fast-forward during silence Step Reset