diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-10-15 12:12:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-15 12:12:06 +0200 |
commit | 54eeeb4355b1ac8146549651c73300ca37169e0e (patch) | |
tree | 0e139b412e64a76c5f7d67edb1b64aa21b97202a /core | |
parent | 7fa400178a65a6849ad324d256181b3b0a42f54b (diff) | |
parent | a59fd671787a5a4d9e0320c2b7f65853791a9e04 (diff) | |
download | AntennaPod-54eeeb4355b1ac8146549651c73300ca37169e0e.zip |
Merge pull request #3516 from egsavage/reset-sleep-timer-on-play
Issue #2381 - restart sleep timer on play
Diffstat (limited to 'core')
3 files changed, 19 insertions, 4 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 a9967ae07..5002fb913 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 @@ -827,6 +827,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { @Override public void onPlaybackStart(@NonNull Playable playable, int position) { + if (taskManager.isSleepTimerActive()) { + taskManager.restartSleepTimer(); + } taskManager.startWidgetUpdater(); if (position != PlaybackServiceMediaPlayer.INVALID_TIME) { playable.setPosition(position); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java index 1cf271a29..5647590b1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java @@ -249,6 +249,16 @@ public class PlaybackServiceTaskManager { } /** + * Restarts the sleep timer. If the sleep timer is not active, nothing will happen. + */ + public synchronized void restartSleepTimer() { + if (isSleepTimerActive()) { + Log.d(TAG, "Restarting sleep timer"); + sleepTimer.restart(); + } + } + + /** * Returns the current sleep timer time or 0 if the sleep timer is not active. */ public synchronized long getSleepTimerTimeLeft() { @@ -428,13 +438,15 @@ public class PlaybackServiceTaskManager { return timeLeft; } - public void onShake() { + public void restart() { postCallback(() -> { setSleepTimer(waitingTime, shakeToReset, vibrate); callback.onSleepTimerReset(); }); - shakeListener.pause(); - shakeListener = null; + if (shakeListener != null) { + shakeListener.pause(); + shakeListener = null; + } } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ShakeListener.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ShakeListener.java index c0b1b3bc0..b0b6e164d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ShakeListener.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ShakeListener.java @@ -52,7 +52,7 @@ class ShakeListener implements SensorEventListener double gForce = Math.sqrt(gX*gX + gY*gY + gZ*gZ); if (gForce > 2.25) { Log.d(TAG, "Detected shake " + gForce); - mSleepTimer.onShake(); + mSleepTimer.restart(); } } |