Skip to content

Commit be6055a

Browse files
committed
player: add sleep timer into HQ dialogue
1 parent f2cc336 commit be6055a

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/playback/controllers/HQDialogController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private void onHighQualityClicked() {
5454
addVideoBufferCategory();
5555
addAudioDelayCategory();
5656
addPitchEffectCategory();
57+
addSleepTimerCategory();
5758
//addBackgroundPlaybackCategory();
5859

5960
appendOptions(mCategoriesInt);
@@ -141,6 +142,10 @@ private void addPitchEffectCategory() {
141142
addCategoryInt(AppDialogUtil.createPitchEffectCategory(getContext()));
142143
}
143144

145+
private void addSleepTimerCategory() {
146+
addCategoryInt(AppDialogUtil.createSleepTimerCategory(getContext()));
147+
}
148+
144149
private void addAudioLanguage() {
145150
if (getPlayer() == null) {
146151
return;

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/settings/PlayerSettingsPresenter.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,8 @@ private void appendPlayerExitCategory(AppDialogPresenter settingsPresenter) {
342342
}
343343

344344
private void appendSleepTimerCategory(AppDialogPresenter settingsPresenter) {
345-
List<OptionItem> options = new ArrayList<>();
346-
347-
for (float sleepHours : Helpers.range(0, 10, 0.5f)) {
348-
options.add(UiOptionItem.from(
349-
sleepHours == 0 ? getContext().getString(R.string.option_disabled)
350-
: getContext().getResources().getQuantityString(R.plurals.hours, (int) sleepHours, Helpers.toString(sleepHours)),
351-
option -> mPlayerData.setSleepTimerHours(sleepHours),
352-
Helpers.floatEquals(mPlayerData.getSleepTimerHours(), sleepHours)));
353-
}
354-
355-
settingsPresenter.appendRadioCategory(getContext().getString(R.string.player_sleep_timer), options);
345+
OptionCategory category = AppDialogUtil.createSleepTimerCategory(getContext());
346+
settingsPresenter.appendCategory(category);
356347
}
357348

358349
private void appendMiscCategory(AppDialogPresenter settingsPresenter) {

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public class AppDialogUtil {
7777
private static final int AUDIO_VOLUME_ID = 145;
7878
private static final int PLAYER_REPEAT_ID = 146;
7979
private static final int PLAYER_ENGINE_ID = 147;
80-
private static final int QUIET_DURATION_ID = 148;
80+
private static final int IGNORE_DURATION_ID = 148;
81+
private static final int SLEEP_TIMER_ID = 149;
8182
private static final int SUBTITLE_STYLES_ID = 45;
8283
private static final int SUBTITLE_SIZE_ID = 46;
8384
private static final int SUBTITLE_POSITION_ID = 47;
@@ -901,7 +902,24 @@ public static OptionCategory createIgnoreShortSegmentsCategory(Context context,
901902
durationMs == sponsorBlockData.getIgnoredDurationMs()));
902903
}
903904

904-
return OptionCategory.from(QUIET_DURATION_ID, OptionCategory.TYPE_RADIO_LIST, title, options);
905+
return OptionCategory.from(IGNORE_DURATION_ID, OptionCategory.TYPE_RADIO_LIST, title, options);
906+
}
907+
908+
public static OptionCategory createSleepTimerCategory(Context context) {
909+
PlayerData playerData = PlayerData.instance(context);
910+
String title = context.getString(R.string.player_sleep_timer);
911+
912+
List<OptionItem> options = new ArrayList<>();
913+
914+
for (float sleepHours : Helpers.range(0, 10, 0.5f)) {
915+
options.add(UiOptionItem.from(
916+
sleepHours == 0 ? context.getString(R.string.option_disabled)
917+
: context.getResources().getQuantityString(R.plurals.hours, (int) sleepHours, Helpers.toString(sleepHours)),
918+
option -> playerData.setSleepTimerHours(sleepHours),
919+
Helpers.floatEquals(playerData.getSleepTimerHours(), sleepHours)));
920+
}
921+
922+
return OptionCategory.from(SLEEP_TIMER_ID, OptionCategory.TYPE_RADIO_LIST, title, options);
905923
}
906924

907925
public static OptionItem createSubscriptionsBackupButton(Context context) {

0 commit comments

Comments
 (0)