diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/DownloadService.java | 38 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/Util.java | 3 |
2 files changed, 37 insertions, 4 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 0db091ad..5673c427 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -841,7 +841,8 @@ public class DownloadService extends Service { private int getNextPlayingIndex() { int index = getCurrentPlayingIndex(); if (index != -1) { - switch (getRepeatMode()) { + RepeatMode repeatMode = getRepeatMode(); + switch (repeatMode) { case OFF: index = index + 1; break; @@ -853,7 +854,32 @@ public class DownloadService extends Service { default: break; } + + index = checkNextIndexValid(index, repeatMode); + } + return index; + } + private int checkNextIndexValid(int index, RepeatMode repeatMode) { + int size = size(); + if(index < size && index != -1) { + if(!Util.isAllowedToDownload(this)){ + DownloadFile next = downloadList.get(index); + while(!next.isCompleteFileAvailable()) { + index++; + + if (index >= size) { + if(repeatMode == RepeatMode.ALL) { + index = 0; + } else { + return -1; + } + } + + next = downloadList.get(index); + } + } } + return index; } @@ -1588,10 +1614,14 @@ public class DownloadService extends Service { } private synchronized void bufferAndPlay(int position, boolean start) { if(!currentPlaying.isCompleteFileAvailable()) { - reset(); + if(Util.isAllowedToDownload(this)) { + reset(); - bufferTask = new BufferTask(currentPlaying, position, start); - bufferTask.execute(); + bufferTask = new BufferTask(currentPlaying, position, start); + bufferTask.execute(); + } else { + next(false, start); + } } else { doPlay(currentPlaying, position, start); } diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index 24895226..99926716 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -1104,6 +1104,9 @@ public final class Util { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } + public static boolean isAllowedToDownload(Context context) { + return !isWifiRequiredForDownload(context) || isWifiConnected(context); + } public static boolean isWifiRequiredForDownload(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD, false); |