Skip to content

Commit bf1a64f

Browse files
committed
Settings: rework Audio shift to edit dialogue
1 parent 8f61312 commit bf1a64f

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/AppDialogUtil.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,35 @@ public static OptionCategory createAudioShiftCategory(Context context) {
406406

407407
public static OptionCategory createAudioShiftCategory(Context context, Runnable onSetCallback) {
408408
PlayerData playerData = PlayerData.instance(context);
409-
String title = context.getString(R.string.audio_shift);
409+
String title = context.getResources().getQuantityString(R.plurals.seconds, 10, context.getString(R.string.audio_shift));
410+
411+
OptionItem optionItem = UiOptionItem.from(title, item -> {
412+
AppDialogPresenter.instance(context).closeDialog();
413+
float delaySec = playerData.getAudioDelayMs() / 1_000f;
414+
SimpleEditDialog.show(
415+
context,
416+
title,
417+
Helpers.toString(delaySec),
418+
newValue -> {
419+
if (!Helpers.isNumeric(newValue)) {
420+
return false;
421+
}
410422

411-
List<OptionItem> options = new ArrayList<>();
423+
float newDelaySec = Helpers.parseFloat(newValue);
424+
int newDelayMs = (int) (newDelaySec * 1_000);
412425

413-
for (int delayMs : Helpers.range(-8_000, 8_000, 50)) {
414-
options.add(UiOptionItem.from(context.getString(R.string.audio_shift_sec, Helpers.toString(delayMs / 1_000f)),
415-
optionItem -> {
416-
playerData.setAudioDelayMs(delayMs);
426+
if (newDelayMs == 0 && newDelaySec != 0) { // lower than 1ms
427+
return false;
428+
}
429+
430+
playerData.setAudioDelayMs(newDelayMs);
417431
onSetCallback.run();
418-
},
419-
delayMs == playerData.getAudioDelayMs()));
420-
}
432+
return true;
433+
}
434+
);
435+
});
421436

422-
return OptionCategory.from(AUDIO_DELAY_ID, OptionCategory.TYPE_RADIO_LIST, title, options);
437+
return OptionCategory.from(AUDIO_DELAY_ID, OptionCategory.TYPE_SINGLE_BUTTON, title, optionItem);
423438
}
424439

425440
public static OptionCategory createAudioVolumeCategory(Context context) {

0 commit comments

Comments
 (0)