1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

-Fixed playback parameter dialog settings not persisting through rotation.

-Moved playback parameter dialog step size selector to below pitch slider.
This commit is contained in:
John Zhen Mo 2018-06-26 10:18:01 -07:00
parent aa1878c15a
commit 7f7145e8de
2 changed files with 75 additions and 57 deletions

View File

@ -33,15 +33,19 @@ public class PlaybackParameterDialog extends DialogFragment {
public static final double STEP_TEN_PERCENT_VALUE = 0.10f; public static final double STEP_TEN_PERCENT_VALUE = 0.10f;
public static final double STEP_TWENTY_FIVE_PERCENT_VALUE = 0.25f; public static final double STEP_TWENTY_FIVE_PERCENT_VALUE = 0.25f;
public static final double STEP_ONE_HUNDRED_PERCENT_VALUE = 1.00f; public static final double STEP_ONE_HUNDRED_PERCENT_VALUE = 1.00f;
public static final double DEFAULT_PLAYBACK_STEP_VALUE = STEP_TWENTY_FIVE_PERCENT_VALUE;
public static final double DEFAULT_TEMPO = 1.00f; public static final double DEFAULT_TEMPO = 1.00f;
public static final double DEFAULT_PITCH = 1.00f; public static final double DEFAULT_PITCH = 1.00f;
public static final double DEFAULT_STEP = STEP_TWENTY_FIVE_PERCENT_VALUE;
public static final boolean DEFAULT_SKIP_SILENCE = false; public static final boolean DEFAULT_SKIP_SILENCE = false;
@NonNull private static final String INITIAL_TEMPO_KEY = "initial_tempo_key"; @NonNull private static final String INITIAL_TEMPO_KEY = "initial_tempo_key";
@NonNull private static final String INITIAL_PITCH_KEY = "initial_pitch_key"; @NonNull private static final String INITIAL_PITCH_KEY = "initial_pitch_key";
@NonNull private static final String TEMPO_KEY = "tempo_key";
@NonNull private static final String PITCH_KEY = "pitch_key";
@NonNull private static final String STEP_SIZE_KEY = "step_size_key";
public interface Callback { public interface Callback {
void onPlaybackParameterChanged(final float playbackTempo, final float playbackPitch, void onPlaybackParameterChanged(final float playbackTempo, final float playbackPitch,
final boolean playbackSkipSilence); final boolean playbackSkipSilence);
@ -57,6 +61,10 @@ public class PlaybackParameterDialog extends DialogFragment {
private double initialPitch = DEFAULT_PITCH; private double initialPitch = DEFAULT_PITCH;
private boolean initialSkipSilence = DEFAULT_SKIP_SILENCE; private boolean initialSkipSilence = DEFAULT_SKIP_SILENCE;
private double tempo = DEFAULT_TEMPO;
private double pitch = DEFAULT_PITCH;
private double stepSize = DEFAULT_STEP;
@Nullable private SeekBar tempoSlider; @Nullable private SeekBar tempoSlider;
@Nullable private TextView tempoMinimumText; @Nullable private TextView tempoMinimumText;
@Nullable private TextView tempoMaximumText; @Nullable private TextView tempoMaximumText;
@ -86,6 +94,10 @@ public class PlaybackParameterDialog extends DialogFragment {
PlaybackParameterDialog dialog = new PlaybackParameterDialog(); PlaybackParameterDialog dialog = new PlaybackParameterDialog();
dialog.initialTempo = playbackTempo; dialog.initialTempo = playbackTempo;
dialog.initialPitch = playbackPitch; dialog.initialPitch = playbackPitch;
dialog.tempo = playbackTempo;
dialog.pitch = playbackPitch;
dialog.initialSkipSilence = playbackSkipSilence; dialog.initialSkipSilence = playbackSkipSilence;
return dialog; return dialog;
} }
@ -110,6 +122,10 @@ public class PlaybackParameterDialog extends DialogFragment {
if (savedInstanceState != null) { if (savedInstanceState != null) {
initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO); initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO);
initialPitch = savedInstanceState.getDouble(INITIAL_PITCH_KEY, DEFAULT_PITCH); initialPitch = savedInstanceState.getDouble(INITIAL_PITCH_KEY, DEFAULT_PITCH);
tempo = savedInstanceState.getDouble(TEMPO_KEY, DEFAULT_TEMPO);
pitch = savedInstanceState.getDouble(PITCH_KEY, DEFAULT_PITCH);
stepSize = savedInstanceState.getDouble(STEP_SIZE_KEY, DEFAULT_STEP);
} }
} }
@ -118,6 +134,10 @@ public class PlaybackParameterDialog extends DialogFragment {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putDouble(INITIAL_TEMPO_KEY, initialTempo); outState.putDouble(INITIAL_TEMPO_KEY, initialTempo);
outState.putDouble(INITIAL_PITCH_KEY, initialPitch); outState.putDouble(INITIAL_PITCH_KEY, initialPitch);
outState.putDouble(TEMPO_KEY, getCurrentTempo());
outState.putDouble(PITCH_KEY, getCurrentPitch());
outState.putDouble(STEP_SIZE_KEY, getCurrentStepSize());
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -154,8 +174,8 @@ public class PlaybackParameterDialog extends DialogFragment {
setupTempoControl(rootView); setupTempoControl(rootView);
setupPitchControl(rootView); setupPitchControl(rootView);
setupStepSize(DEFAULT_PLAYBACK_STEP_VALUE);
changeStepSize(stepSize);
setupStepSizeSelector(rootView); setupStepSizeSelector(rootView);
} }
@ -168,31 +188,15 @@ public class PlaybackParameterDialog extends DialogFragment {
tempoStepDownText = rootView.findViewById(R.id.tempoStepDown); tempoStepDownText = rootView.findViewById(R.id.tempoStepDown);
if (tempoCurrentText != null) if (tempoCurrentText != null)
tempoCurrentText.setText(PlayerHelper.formatSpeed(initialTempo)); tempoCurrentText.setText(PlayerHelper.formatSpeed(tempo));
if (tempoMaximumText != null) if (tempoMaximumText != null)
tempoMaximumText.setText(PlayerHelper.formatSpeed(MAXIMUM_PLAYBACK_VALUE)); tempoMaximumText.setText(PlayerHelper.formatSpeed(MAXIMUM_PLAYBACK_VALUE));
if (tempoMinimumText != null) if (tempoMinimumText != null)
tempoMinimumText.setText(PlayerHelper.formatSpeed(MINIMUM_PLAYBACK_VALUE)); tempoMinimumText.setText(PlayerHelper.formatSpeed(MINIMUM_PLAYBACK_VALUE));
if (tempoStepUpText != null) {
tempoStepUpText.setText(getStepUpPercentString(DEFAULT_PLAYBACK_STEP_VALUE));
tempoStepUpText.setOnClickListener(view -> {
onTempoSliderUpdated(getCurrentTempo() + DEFAULT_PLAYBACK_STEP_VALUE);
setCurrentPlaybackParameters();
});
}
if (tempoStepDownText != null) {
tempoStepDownText.setText(getStepDownPercentString(DEFAULT_PLAYBACK_STEP_VALUE));
tempoStepDownText.setOnClickListener(view -> {
onTempoSliderUpdated(getCurrentTempo() - DEFAULT_PLAYBACK_STEP_VALUE);
setCurrentPlaybackParameters();
});
}
if (tempoSlider != null) { if (tempoSlider != null) {
tempoSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE)); tempoSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
tempoSlider.setProgress(strategy.progressOf(initialTempo)); tempoSlider.setProgress(strategy.progressOf(tempo));
tempoSlider.setOnSeekBarChangeListener(getOnTempoChangedListener()); tempoSlider.setOnSeekBarChangeListener(getOnTempoChangedListener());
} }
} }
@ -206,7 +210,7 @@ public class PlaybackParameterDialog extends DialogFragment {
pitchStepUpText = rootView.findViewById(R.id.pitchStepUp); pitchStepUpText = rootView.findViewById(R.id.pitchStepUp);
if (pitchCurrentText != null) if (pitchCurrentText != null)
pitchCurrentText.setText(PlayerHelper.formatPitch(initialPitch)); pitchCurrentText.setText(PlayerHelper.formatPitch(pitch));
if (pitchMaximumText != null) if (pitchMaximumText != null)
pitchMaximumText.setText(PlayerHelper.formatPitch(MAXIMUM_PLAYBACK_VALUE)); pitchMaximumText.setText(PlayerHelper.formatPitch(MAXIMUM_PLAYBACK_VALUE));
if (pitchMinimumText != null) if (pitchMinimumText != null)
@ -214,7 +218,7 @@ public class PlaybackParameterDialog extends DialogFragment {
if (pitchSlider != null) { if (pitchSlider != null) {
pitchSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE)); pitchSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
pitchSlider.setProgress(strategy.progressOf(initialPitch)); pitchSlider.setProgress(strategy.progressOf(pitch));
pitchSlider.setOnSeekBarChangeListener(getOnPitchChangedListener()); pitchSlider.setOnSeekBarChangeListener(getOnPitchChangedListener());
} }
} }
@ -222,7 +226,7 @@ public class PlaybackParameterDialog extends DialogFragment {
private void setupHookingControl(@NonNull View rootView) { private void setupHookingControl(@NonNull View rootView) {
unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox); unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox);
if (unhookingCheckbox != null) { if (unhookingCheckbox != null) {
unhookingCheckbox.setChecked(initialPitch != initialTempo); unhookingCheckbox.setChecked(pitch != tempo);
unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> { unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
if (isChecked) return; if (isChecked) return;
// When unchecked, slide back to the minimum of current tempo or pitch // When unchecked, slide back to the minimum of current tempo or pitch
@ -252,35 +256,37 @@ public class PlaybackParameterDialog extends DialogFragment {
if (stepSizeOnePercentText != null) { if (stepSizeOnePercentText != null) {
stepSizeOnePercentText.setText(getPercentString(STEP_ONE_PERCENT_VALUE)); stepSizeOnePercentText.setText(getPercentString(STEP_ONE_PERCENT_VALUE));
stepSizeOnePercentText.setOnClickListener(view -> stepSizeOnePercentText.setOnClickListener(view ->
setupStepSize(STEP_ONE_PERCENT_VALUE)); changeStepSize(STEP_ONE_PERCENT_VALUE));
} }
if (stepSizeFivePercentText != null) { if (stepSizeFivePercentText != null) {
stepSizeFivePercentText.setText(getPercentString(STEP_FIVE_PERCENT_VALUE)); stepSizeFivePercentText.setText(getPercentString(STEP_FIVE_PERCENT_VALUE));
stepSizeFivePercentText.setOnClickListener(view -> stepSizeFivePercentText.setOnClickListener(view ->
setupStepSize(STEP_FIVE_PERCENT_VALUE)); changeStepSize(STEP_FIVE_PERCENT_VALUE));
} }
if (stepSizeTenPercentText != null) { if (stepSizeTenPercentText != null) {
stepSizeTenPercentText.setText(getPercentString(STEP_TEN_PERCENT_VALUE)); stepSizeTenPercentText.setText(getPercentString(STEP_TEN_PERCENT_VALUE));
stepSizeTenPercentText.setOnClickListener(view -> stepSizeTenPercentText.setOnClickListener(view ->
setupStepSize(STEP_TEN_PERCENT_VALUE)); changeStepSize(STEP_TEN_PERCENT_VALUE));
} }
if (stepSizeTwentyFivePercentText != null) { if (stepSizeTwentyFivePercentText != null) {
stepSizeTwentyFivePercentText.setText(getPercentString(STEP_TWENTY_FIVE_PERCENT_VALUE)); stepSizeTwentyFivePercentText.setText(getPercentString(STEP_TWENTY_FIVE_PERCENT_VALUE));
stepSizeTwentyFivePercentText.setOnClickListener(view -> stepSizeTwentyFivePercentText.setOnClickListener(view ->
setupStepSize(STEP_TWENTY_FIVE_PERCENT_VALUE)); changeStepSize(STEP_TWENTY_FIVE_PERCENT_VALUE));
} }
if (stepSizeOneHundredPercentText != null) { if (stepSizeOneHundredPercentText != null) {
stepSizeOneHundredPercentText.setText(getPercentString(STEP_ONE_HUNDRED_PERCENT_VALUE)); stepSizeOneHundredPercentText.setText(getPercentString(STEP_ONE_HUNDRED_PERCENT_VALUE));
stepSizeOneHundredPercentText.setOnClickListener(view -> stepSizeOneHundredPercentText.setOnClickListener(view ->
setupStepSize(STEP_ONE_HUNDRED_PERCENT_VALUE)); changeStepSize(STEP_ONE_HUNDRED_PERCENT_VALUE));
} }
} }
private void setupStepSize(final double stepSize) { private void changeStepSize(final double stepSize) {
this.stepSize = stepSize;
if (tempoStepUpText != null) { if (tempoStepUpText != null) {
tempoStepUpText.setText(getStepUpPercentString(stepSize)); tempoStepUpText.setText(getStepUpPercentString(stepSize));
tempoStepUpText.setOnClickListener(view -> { tempoStepUpText.setOnClickListener(view -> {
@ -419,15 +425,19 @@ public class PlaybackParameterDialog extends DialogFragment {
} }
private double getCurrentTempo() { private double getCurrentTempo() {
return tempoSlider == null ? initialTempo : strategy.valueOf( return tempoSlider == null ? tempo : strategy.valueOf(
tempoSlider.getProgress()); tempoSlider.getProgress());
} }
private double getCurrentPitch() { private double getCurrentPitch() {
return pitchSlider == null ? initialPitch : strategy.valueOf( return pitchSlider == null ? pitch : strategy.valueOf(
pitchSlider.getProgress()); pitchSlider.getProgress());
} }
private double getCurrentStepSize() {
return stepSize;
}
private boolean getCurrentSkipSilence() { private boolean getCurrentSkipSilence() {
return skipSilenceCheckbox != null && skipSilenceCheckbox.isChecked(); return skipSilenceCheckbox != null && skipSilenceCheckbox.isChecked();
} }

View File

@ -260,43 +260,19 @@
</RelativeLayout> </RelativeLayout>
<View <View
android:id="@+id/separatorCheckbox" android:id="@+id/separatorStepSizeSelector"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_below="@+id/pitchControl" android:layout_below="@+id/pitchControl"
android:layout_margin="@dimen/video_item_search_padding" android:layout_margin="@dimen/video_item_search_padding"
android:background="?attr/separator_color"/> android:background="?attr/separator_color"/>
<CheckBox
android:id="@+id/unhookCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:text="@string/unhook_checkbox"
android:maxLines="1"
android:layout_centerHorizontal="true"
android:layout_below="@id/separatorCheckbox"/>
<CheckBox
android:id="@+id/skipSilenceCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:text="@string/skip_silence_checkbox"
android:maxLines="1"
android:layout_centerHorizontal="true"
android:layout_below="@id/unhookCheckbox"/>
<LinearLayout <LinearLayout
android:id="@+id/stepSizeSelector" android:id="@+id/stepSizeSelector"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_below="@id/skipSilenceCheckbox"> android:layout_below="@id/separatorStepSizeSelector">
<TextView <TextView
android:id="@+id/stepSizeText" android:id="@+id/stepSizeText"
@ -365,6 +341,38 @@
android:textColor="?attr/colorAccent"/> android:textColor="?attr/colorAccent"/>
</LinearLayout> </LinearLayout>
<View
android:id="@+id/separatorCheckbox"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/stepSizeSelector"
android:layout_margin="@dimen/video_item_search_padding"
android:background="?attr/separator_color"/>
<CheckBox
android:id="@+id/unhookCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:text="@string/unhook_checkbox"
android:maxLines="1"
android:layout_centerHorizontal="true"
android:layout_below="@id/separatorCheckbox"/>
<CheckBox
android:id="@+id/skipSilenceCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:text="@string/skip_silence_checkbox"
android:maxLines="1"
android:layout_centerHorizontal="true"
android:layout_below="@id/unhookCheckbox"/>
<!-- END HERE --> <!-- END HERE -->
</RelativeLayout> </RelativeLayout>