From 3e6fc34550059044531fc07947d2b6a37bc7671b Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Thu, 27 Sep 2018 17:21:27 +0200 Subject: [PATCH] When auto refreshing feeds, give network some time to get available --- core/build.gradle | 1 + .../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"); } } + }