aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java47
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java3
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);