1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-10 01:10:33 +00:00

Added some doc and abstracted more methods

This commit is contained in:
litetex 2022-03-04 22:02:39 +01:00
parent 4b06536582
commit 20602889be

View File

@ -172,7 +172,7 @@ public class PlaybackParameterDialog extends DialogFragment {
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Control Views // UI Initialization and Control
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
private void initUI() { private void initUI() {
@ -265,8 +265,7 @@ public class PlaybackParameterDialog extends DialogFragment {
isChecked -> { isChecked -> {
if (!isChecked) { if (!isChecked) {
// when unchecked, slide back to the minimum of current tempo or pitch // when unchecked, slide back to the minimum of current tempo or pitch
setSliders(Math.min(pitchPercent, tempo)); ensureHookIsValidAndUpdateCallBack();
updateCallback();
} }
}); });
@ -277,6 +276,8 @@ public class PlaybackParameterDialog extends DialogFragment {
}); });
} }
// -- General formatting --
private void setText( private void setText(
final TextView textView, final TextView textView,
final DoubleFunction<String> formatter, final DoubleFunction<String> formatter,
@ -285,6 +286,8 @@ public class PlaybackParameterDialog extends DialogFragment {
Objects.requireNonNull(textView).setText(formatter.apply(value)); Objects.requireNonNull(textView).setText(formatter.apply(value));
} }
// -- Steps --
private void registerOnStepClickListener( private void registerOnStepClickListener(
final TextView stepTextView, final TextView stepTextView,
final DoubleSupplier currentValueSupplier, final DoubleSupplier currentValueSupplier,
@ -310,6 +313,8 @@ public class PlaybackParameterDialog extends DialogFragment {
}); });
} }
// -- Pitch --
private void setupPitchControlModeTextView( private void setupPitchControlModeTextView(
final boolean semitones, final boolean semitones,
final TextView textView final TextView textView
@ -367,6 +372,9 @@ public class PlaybackParameterDialog extends DialogFragment {
this.onPitchPercentSliderUpdated(newPitchPercent); this.onPitchPercentSliderUpdated(newPitchPercent);
updateCallback(); updateCallback();
} }
} else if (!binding.unhookCheckbox.isChecked()) {
// When changing to percent it's possible that tempo is != pitch
ensureHookIsValidAndUpdateCallBack();
} }
} }
@ -377,6 +385,8 @@ public class PlaybackParameterDialog extends DialogFragment {
PITCH_CTRL_MODE_PERCENT); PITCH_CTRL_MODE_PERCENT);
} }
// -- Steps (Set) --
private void setupStepTextView( private void setupStepTextView(
final double stepSizeValue, final double stepSizeValue,
final TextView textView final TextView textView
@ -430,6 +440,8 @@ public class PlaybackParameterDialog extends DialogFragment {
.getFloat(getString(R.string.adjustment_step_key), (float) DEFAULT_STEP); .getFloat(getString(R.string.adjustment_step_key), (float) DEFAULT_STEP);
} }
// -- Additional options --
private void setAndUpdateSkipSilence(final boolean newSkipSilence) { private void setAndUpdateSkipSilence(final boolean newSkipSilence) {
this.skipSilence = newSkipSilence; this.skipSilence = newSkipSilence;
binding.skipSilenceCheckbox.setChecked(newSkipSilence); binding.skipSilenceCheckbox.setChecked(newSkipSilence);
@ -461,6 +473,18 @@ public class PlaybackParameterDialog extends DialogFragment {
}); });
} }
/**
* Ensures that the slider hook is valid and if not sets and updates the sliders accordingly.
* <br/>
* You have to ensure by yourself that the hooking is active.
*/
private void ensureHookIsValidAndUpdateCallBack() {
if (tempo != pitchPercent) {
setSliders(Math.min(tempo, pitchPercent));
updateCallback();
}
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Sliders // Sliders
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/