Skip to content

Commit

Permalink
change repeat type to enum for three values
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrafzadeh committed Sep 5, 2018
1 parent 9513088 commit 11b2260
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -34,7 +36,7 @@ public class AudioStreamingManager extends StreamingManager {
private MediaMetaData currentAudio;
private List<MediaMetaData> mediaList = new ArrayList<>();
public static volatile Handler applicationHandler = null;
private boolean repeatEnable = false;
private RepeatType repeatType = NONE;
private boolean shuffleEnable = false;


Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dm.audiostreamer;

public enum RepeatType {
NONE, SINGLE, ALL
}

0 comments on commit 11b2260

Please sign in to comment.