Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember adjustment step size for playback controls (speed and pitch) #7728

Merged

Conversation

ktprograms
Copy link
Contributor

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

  • Save adjustmentStepSize to shared preferences, pass it back and forth
    between PlaybackParameterDialog and Player/PlayQueueActivity.
  • Made DEFAULT_STEP in PlaybackParameterDialog public so it can be used as
    the default adjustmentStepSize value in the Player.

Before/After Screenshots/Screen Record

Before After
before.mp4
after.mp4

Fixes the following issue(s)

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@triallax triallax added feature request Issue is related to a feature in the app player Issues related to any player (main, popup and background) labels Jan 31, 2022
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should pass around the adjustmentStepSize as a playback parameter. It's not something influencing the playback, it's just a value to save to / read from preferences. You should just read it when the PlaybackParameterDialog is setup, and save it when the user changes it inside the same dialog.

@ktprograms
Copy link
Contributor Author

@Stypox Sorry, I was busy so I didn't have time to look at the code.

I'm guessing this should be done similarly to how setupHookingControl handles accessing the preferences?

private void setupHookingControl(@NonNull final View rootView) {
unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox);
if (unhookingCheckbox != null) {
// restore whether pitch and tempo are unhooked or not
unhookingCheckbox.setChecked(PreferenceManager
.getDefaultSharedPreferences(requireContext())
.getBoolean(getString(R.string.playback_unhook_key), true));
unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
// save whether pitch and tempo are unhooked or not
PreferenceManager.getDefaultSharedPreferences(requireContext())
.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();
}
});
}
}

@Stypox
Copy link
Member

Stypox commented Feb 23, 2022

@ktprograms yes, I think that's the way to go

@ktprograms
Copy link
Contributor Author

@Stypox Since the step size will now be saved to shared preferences, should I remove the code that saves it to/reads it from outState?

@Stypox
Copy link
Member

Stypox commented Mar 1, 2022

@ktprograms yes, there is no need to save/restore it there

- 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: TeamNewPipe#7031
@ktprograms ktprograms force-pushed the remember-playback-adjustment-step-size branch from 6d40a63 to 62c0e66 Compare March 1, 2022 08:34
@ktprograms
Copy link
Contributor Author

@Stypox Done, basically rewrote the entire commit, so here's the overview of everything changed:

  • 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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Code looks good to me, I'm going to test it later :-)

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and everything seems to work well :-)

@Stypox Stypox merged commit cbdcf59 into TeamNewPipe:dev Mar 1, 2022
@ktprograms
Copy link
Contributor Author

Thanks!

@Stypox Stypox mentioned this pull request Apr 16, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issue is related to a feature in the app player Issues related to any player (main, popup and background)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remember step for playback speed controls
3 participants