From 11b22606da0a28619e4a47d854a012938c3f6a5c Mon Sep 17 00:00:00 2001 From: ashrafzadeh Date: Wed, 5 Sep 2018 12:23:17 +0430 Subject: [PATCH] change repeat type to enum for three values --- .../audiostreamer/AudioStreamingManager.java | 24 ++++++++++++------- .../java/dm/audiostreamer/RepeatType.java | 5 ++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 dmaudiostreamer/src/main/java/dm/audiostreamer/RepeatType.java diff --git a/dmaudiostreamer/src/main/java/dm/audiostreamer/AudioStreamingManager.java b/dmaudiostreamer/src/main/java/dm/audiostreamer/AudioStreamingManager.java index a5df7f7..d8e42bf 100644 --- a/dmaudiostreamer/src/main/java/dm/audiostreamer/AudioStreamingManager.java +++ b/dmaudiostreamer/src/main/java/dm/audiostreamer/AudioStreamingManager.java @@ -20,6 +20,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import static dm.audiostreamer.RepeatType.*; + public class AudioStreamingManager extends StreamingManager { private static final String TAG = Logger.makeLogTag(AudioStreamingManager.class); @@ -34,7 +36,7 @@ public class AudioStreamingManager extends StreamingManager { private MediaMetaData currentAudio; private List mediaList = new ArrayList<>(); public static volatile Handler applicationHandler = null; - private boolean repeatEnable = false; + private RepeatType repeatType = NONE; private boolean shuffleEnable = false; @@ -71,12 +73,12 @@ public String getCurrentAudioId() { return currentAudio != null ? currentAudio.getMediaId() : ""; } - public void setRepeatEnable(boolean repeatEnable) { - this.repeatEnable = repeatEnable; + public void setRepeatType(RepeatType repeatType) { + this.repeatType = repeatType; } - public boolean isRepeatEnable() { - return repeatEnable; + public RepeatType getRepeatType() { + return repeatType; } public void setShuffleEnable(boolean shuffleEnable) { @@ -167,10 +169,12 @@ public int lastSeekPosition() { @Override public void onSkipToNext() { int nextIndex = index + 1; - if (shuffleEnable) + if (repeatType == SINGLE) + nextIndex = index; + else if (shuffleEnable) nextIndex = getRandomIndex(); if (!isValidIndex(true, nextIndex)) - if (repeatEnable) + if (repeatType == ALL) nextIndex = 0; else return; @@ -187,10 +191,12 @@ public void onSkipToNext() { @Override public void onSkipToPrevious() { int prvIndex = index - 1; - if (shuffleEnable) + if (repeatType == SINGLE) + prvIndex = index; + else if (shuffleEnable) prvIndex = getRandomIndex(); if (!isValidIndex(true, prvIndex)) - if (repeatEnable) + if (repeatType == ALL) prvIndex = mediaList.size() - 1; else return; diff --git a/dmaudiostreamer/src/main/java/dm/audiostreamer/RepeatType.java b/dmaudiostreamer/src/main/java/dm/audiostreamer/RepeatType.java new file mode 100644 index 0000000..8caae71 --- /dev/null +++ b/dmaudiostreamer/src/main/java/dm/audiostreamer/RepeatType.java @@ -0,0 +1,5 @@ +package dm.audiostreamer; + +public enum RepeatType { + NONE, SINGLE, ALL +}