diff options
author | Martin Fietz <martin.fietz@gmail.com> | 2018-09-27 17:21:27 +0200 |
---|---|---|
committer | Martin Fietz <martin.fietz@gmail.com> | 2018-09-27 17:24:41 +0200 |
commit | 3e6fc34550059044531fc07947d2b6a37bc7671b (patch) | |
tree | 225db57aa9faacf3f5254071eb16d08938c2715c /core | |
parent | 5a4219bf09aac249477958f2ba725999215e6265 (diff) | |
download | AntennaPod-3e6fc34550059044531fc07947d2b6a37bc7671b.zip |
When auto refreshing feeds, give network some time to get available
Diffstat (limited to 'core')
-rw-r--r-- | core/build.gradle | 1 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java | 21 |
2 files changed, 17 insertions, 5 deletions
diff --git a/core/build.gradle b/core/build.gradle index 4998b3853..f5a781c1c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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:3.1.2' implementation "com.google.android.exoplayer:exoplayer:$exoPlayerVersion" implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion" diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java index 24e0da9ed..43f805f9f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java @@ -2,20 +2,31 @@ 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.await; +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"); } } + } |