diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-09-16 18:25:59 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-09-16 18:25:59 -0700 |
commit | e3c84517487d4b8875620dc1414e861c405ecc34 (patch) | |
tree | ddf67f60bc8329554ba789237ae49ea4335a478c /app/src | |
parent | a501dc49b08f3dc7a256f650d7937febb46c7e39 (diff) | |
parent | 6a93260d3886df769898e036cbe57487c3a25453 (diff) | |
download | dsub-e3c84517487d4b8875620dc1414e861c405ecc34.tar.gz dsub-e3c84517487d4b8875620dc1414e861c405ecc34.tar.bz2 dsub-e3c84517487d4b8875620dc1414e861c405ecc34.zip |
Merge branch 'no-wifi-skip'
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/DownloadService.java | 47 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/Util.java | 3 |
2 files changed, 46 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 3f3f036a..a828ae4a 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -840,7 +840,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; @@ -852,9 +853,43 @@ public class DownloadService extends Service { default: break; } + + index = checkNextIndexValid(index, repeatMode); } return index; } + private int checkNextIndexValid(int index, RepeatMode repeatMode) { + int startIndex = index; + 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; + } + } else if(index == startIndex) { + handler.post(new Runnable() { + @Override + public void run() { + Util.toast(DownloadService.this, R.string.download_playerstate_mobile_disabled); + } + }); + return -1; + } + + next = downloadList.get(index); + } + } + } + + return index; + } public DownloadFile getCurrentPlaying() { return currentPlaying; @@ -1622,10 +1657,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 e90bfa06..c2ecdcee 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -1105,6 +1105,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); |