diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 22 | ||||
-rw-r--r-- | core/src/main/res/values/arrays.xml | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 02102db14..fd11dc4c5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -129,6 +129,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { private static final String CUSTOM_ACTION_REWIND = "action.de.danoeh.antennapod.core.service.rewind"; private static final String CUSTOM_ACTION_CHANGE_PLAYBACK_SPEED = "action.de.danoeh.antennapod.core.service.changePlaybackSpeed"; + private static final String CUSTOM_ACTION_TOGGLE_SLEEP_TIMER = + "action.de.danoeh.antennapod.core.service.toggleSleepTimer"; public static final String CUSTOM_ACTION_NEXT_CHAPTER = "action.de.danoeh.antennapod.core.service.next_chapter"; /** @@ -977,6 +979,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { @SuppressWarnings("unused") public void sleepTimerUpdate(SleepTimerUpdatedEvent event) { if (event.isOver()) { + updateMediaSession(mediaPlayer.getPlayerStatus()); mediaPlayer.pause(true, true); mediaPlayer.setVolume(1.0f, 1.0f); int newPosition = mediaPlayer.getPosition() - (int) SleepTimer.NOTIFICATION_THRESHOLD / 2; @@ -988,7 +991,10 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "onSleepTimerAlmostExpired: " + multiplicator); mediaPlayer.setVolume(multiplicator, multiplicator); } else if (event.isCancelled()) { + updateMediaSession(mediaPlayer.getPlayerStatus()); mediaPlayer.setVolume(1.0f, 1.0f); + } else if (event.wasJustEnabled()) { + updateMediaSession(mediaPlayer.getPlayerStatus()); } } @@ -1271,6 +1277,16 @@ public class PlaybackService extends MediaBrowserServiceCompat { ); } + if (UserPreferences.showSleepTimerOnFullNotification()) { + @DrawableRes int icon = R.drawable.ic_notification_sleep; + if (sleepTimerActive()) { + icon = R.drawable.ic_notification_sleep_off; + } + sessionState.addCustomAction( + new PlaybackStateCompat.CustomAction.Builder(CUSTOM_ACTION_TOGGLE_SLEEP_TIMER, + getString(R.string.sleep_timer_label), icon).build()); + } + if (UserPreferences.showNextChapterOnFullNotification()) { if (getPlayable() != null && getPlayable().getChapters() != null) { sessionState.addCustomAction( @@ -1950,6 +1966,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { } onSetPlaybackSpeed(newSpeed); } + } else if (CUSTOM_ACTION_TOGGLE_SLEEP_TIMER.equals(action)) { + if (sleepTimerActive()) { + disableSleepTimer(); + } else { + setSleepTimer(SleepTimerPreferences.timerMillis()); + } } } }; diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 7eeab886a..2961339cd 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -250,6 +250,7 @@ <item>@string/skip_episode_label</item> <item>@string/next_chapter</item> <item>@string/playback_speed</item> + <item>@string/sleep_timer_label</item> </string-array> <string-array name="default_page_values"> |