diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-09-12 15:24:33 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-09-12 15:24:33 -0700 |
commit | b6e9bef76a72b8033a4f4658d1d47c55293dd5ab (patch) | |
tree | aa3e169d3d7ccd7bd8a5302237585c6dc07fd981 /app | |
parent | 634b118ebad3cd9f1e7987de7c58e52a7dfefc57 (diff) | |
download | dsub-b6e9bef76a72b8033a4f4658d1d47c55293dd5ab.tar.gz dsub-b6e9bef76a72b8033a4f4658d1d47c55293dd5ab.tar.bz2 dsub-b6e9bef76a72b8033a4f4658d1d47c55293dd5ab.zip |
#536 Auto skip non-downloaded songs when Wifi mobile
Diffstat (limited to 'app')
-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); |