@@ -84,8 +84,6 @@ public double valueOf(final int progress) {
8484 @ State
8585 double pitchPercent = DEFAULT_PITCH_PERCENT ;
8686 @ State
87- double stepSize = DEFAULT_STEP ;
88- @ State
8987 boolean skipSilence = DEFAULT_SKIP_SILENCE ;
9088
9189 private DialogPlaybackParameterBinding binding ;
@@ -228,13 +226,10 @@ private void initUI() {
228226 this ::onPitchPercentSliderUpdated );
229227
230228 // Steps
231- setupStepTextView (binding .stepSizeOnePercent , STEP_1_PERCENT_VALUE );
232- setupStepTextView (binding .stepSizeFivePercent , STEP_5_PERCENT_VALUE );
233- setupStepTextView (binding .stepSizeTenPercent , STEP_10_PERCENT_VALUE );
234- setupStepTextView (binding .stepSizeTwentyFivePercent , STEP_25_PERCENT_VALUE );
235- setupStepTextView (binding .stepSizeOneHundredPercent , STEP_100_PERCENT_VALUE );
236-
237- setAndUpdateStepSize (stepSize );
229+ getStepSizeComponentMappings ()
230+ .forEach (this ::setupStepTextView );
231+ // Initialize UI
232+ setStepSizeToUI (getCurrentStepSize ());
238233
239234 // Bottom controls
240235 bindCheckboxWithBoolPref (
@@ -263,13 +258,12 @@ private void initUI() {
263258 );
264259 }
265260
266- private TextView setText (
261+ private void setText (
267262 final TextView textView ,
268263 final DoubleFunction <String > formatter ,
269264 final double value
270265 ) {
271266 Objects .requireNonNull (textView ).setText (formatter .apply (value ));
272- return textView ;
273267 }
274268
275269 private void registerOnStepClickListener (
@@ -280,7 +274,7 @@ private void registerOnStepClickListener(
280274 ) {
281275 stepTextView .setOnClickListener (view -> {
282276 newValueConsumer .accept (
283- currentValueSupplier .getAsDouble () + 1 * stepSize * direction );
277+ currentValueSupplier .getAsDouble () + 1 * getCurrentStepSize () * direction );
284278 updateCallback ();
285279 });
286280 }
@@ -315,26 +309,30 @@ private void setAndUpdateStepSize(final double newStepSize) {
315309 binding .pitchPercentStepDown .setText (getStepDownPercentString (newStepSize ));
316310 }
317311
312+ private double getCurrentStepSize () {
313+ return PreferenceManager .getDefaultSharedPreferences (requireContext ())
314+ .getFloat (getString (R .string .adjustment_step_key ), (float ) DEFAULT_STEP );
315+ }
316+
318317 private void setAndUpdateSkipSilence (final boolean newSkipSilence ) {
319318 this .skipSilence = newSkipSilence ;
320319 binding .skipSilenceCheckbox .setChecked (newSkipSilence );
321320 }
322321
322+ @ SuppressWarnings ("SameParameterValue" ) // this method was written to be reusable
323323 private void bindCheckboxWithBoolPref (
324324 @ NonNull final CheckBox checkBox ,
325325 @ StringRes final int resId ,
326326 final boolean defaultValue ,
327- @ Nullable final Consumer <Boolean > onInitialValueOrValueChange
327+ @ NonNull final Consumer <Boolean > onInitialValueOrValueChange
328328 ) {
329329 final boolean prefValue = PreferenceManager
330330 .getDefaultSharedPreferences (requireContext ())
331331 .getBoolean (getString (resId ), defaultValue );
332332
333333 checkBox .setChecked (prefValue );
334334
335- if (onInitialValueOrValueChange != null ) {
336- onInitialValueOrValueChange .accept (prefValue );
337- }
335+ onInitialValueOrValueChange .accept (prefValue );
338336
339337 checkBox .setOnCheckedChangeListener ((compoundButton , isChecked ) -> {
340338 // save whether pitch and tempo are unhooked or not
@@ -343,9 +341,7 @@ private void bindCheckboxWithBoolPref(
343341 .putBoolean (getString (resId ), isChecked )
344342 .apply ();
345343
346- if (onInitialValueOrValueChange != null ) {
347- onInitialValueOrValueChange .accept (isChecked );
348- }
344+ onInitialValueOrValueChange .accept (isChecked );
349345 });
350346 }
351347
0 commit comments