Merge pull request #2839 from AntennaPod/bugfix/2691-auto-update-network-not-ready

When auto refreshing feeds, give network some time to get available
This commit is contained in:
Martin Fietz 2018-09-30 21:11:04 +02:00 committed by GitHub
commit a79c7c0cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -43,6 +43,7 @@ project.ext {
targetSdkVersion = 26
supportVersion = "26.1.0"
awaitilityVersion = "3.1.2"
commonsioVersion = "2.5"
commonslangVersion = "3.6"
commonstextVersion = "1.3"

View File

@ -66,6 +66,7 @@ dependencies {
implementation "com.squareup.okio:okio:$okioVersion"
implementation "de.greenrobot:eventbus:$eventbusVersion"
implementation "io.reactivex:rxandroid:$rxAndroidVersion"
implementation "org.awaitility:awaitility:$awaitilityVersion"
implementation "com.google.android.exoplayer:exoplayer:$exoPlayerVersion"
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"

View File

@ -2,20 +2,30 @@ package de.danoeh.antennapod.core.util;
import android.content.Context;
import android.util.Log;
import org.awaitility.core.ConditionTimeoutException;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.storage.DBTasks;
import static org.awaitility.Awaitility.with;
public class FeedUpdateUtils {
private static final String TAG = "FeedUpdateUtils";
private FeedUpdateUtils() {
}
private FeedUpdateUtils() {}
public static void startAutoUpdate(Context context, Runnable callback) {
if (NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()) {
try {
with().pollInterval(1, TimeUnit.SECONDS)
.await()
.atMost(10, TimeUnit.SECONDS)
.until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed());
DBTasks.refreshAllFeeds(context, null, callback);
} else {
} catch (ConditionTimeoutException ignore) {
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
}
}
}