diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-01-03 19:25:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-03 19:25:51 +0100 |
commit | 8252f6a41d76e5ed9899d5a1d6ac926d77a4bc9b (patch) | |
tree | a4c4d6e9d54581e451c0acb9d90de6877a3ad546 /core | |
parent | d7e7684cc0a582d0b41d7616a6f69956625f6221 (diff) | |
parent | feef92f80263a8304b7204cd719b54e1891d0ef0 (diff) | |
download | AntennaPod-8252f6a41d76e5ed9899d5a1d6ac926d77a4bc9b.zip |
Merge pull request #2913 from orionlee/auto_feed_update_fix_in_airplane_2906
Auto feed update fix in airplane mode
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java | 33 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java | 29 |
2 files changed, 34 insertions, 28 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index ba7d4b47b..dab8e19b5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -17,7 +17,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.core.ClientConfig; @@ -28,11 +27,9 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedPreferences; -import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.GpodnetSyncService; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; @@ -207,6 +204,11 @@ public final class DBTasks { }).start(); } + public static long getLastRefreshAllFeedsTimeMillis(final Context context) { + SharedPreferences prefs = context.getSharedPreferences(DBTasks.PREF_NAME, MODE_PRIVATE); + return prefs.getLong(DBTasks.PREF_LAST_REFRESH, 0); + } + /** * @param context * @param feedList the list of feeds to refresh @@ -317,31 +319,6 @@ public final class DBTasks { DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force); } - /* - * Checks if the app should refresh all feeds, i.e. if the last auto refresh failed. - * - * The feeds are only refreshed if an update interval or time of day is set and the last - * (successful) refresh was before the last interval or more than a day ago, respectively. - */ - public static void checkShouldRefreshFeeds(Context context) { - long interval = 0; - if(UserPreferences.getUpdateInterval() > 0) { - interval = UserPreferences.getUpdateInterval(); - } else if(UserPreferences.getUpdateTimeOfDay().length > 0){ - interval = TimeUnit.DAYS.toMillis(1); - } - if(interval == 0) { // auto refresh is disabled - return; - } - SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, MODE_PRIVATE); - long lastRefresh = prefs.getLong(PREF_LAST_REFRESH, 0); - Log.d(TAG, "last refresh: " + Converter.getDurationStringLocalized(context, - System.currentTimeMillis() - lastRefresh) + " ago"); - if(lastRefresh <= System.currentTimeMillis() - interval) { - DBTasks.refreshAllFeeds(context, null); - } - } - /** * Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's values in the * DB and send a FeedUpdateBroadcast. diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java index 3a2a4ac80..1629f4aaf 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java @@ -15,8 +15,12 @@ import android.util.Log; import java.util.Calendar; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver; import de.danoeh.antennapod.core.service.FeedUpdateJobService; +import de.danoeh.antennapod.core.storage.DBTasks; +import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.FeedUpdateUtils; public class AutoUpdateManager { private static final int JOB_ID_FEED_UPDATE = 42; @@ -153,4 +157,29 @@ public class AutoUpdateManager { updateIntent); Log.d(TAG, "Changed alarm to new time of day " + alarm.get(Calendar.HOUR_OF_DAY) + ":" + alarm.get(Calendar.MINUTE)); } + + /* + * Checks if the app should refresh all feeds, i.e. if the last auto refresh failed. + * + * The feeds are only refreshed if an update interval or time of day is set and the last + * (successful) refresh was before the last interval or more than a day ago, respectively. + * + */ + public static void checkShouldRefreshFeeds(Context context) { + long interval = 0; + if(UserPreferences.getUpdateInterval() > 0) { + interval = UserPreferences.getUpdateInterval(); + } else if(UserPreferences.getUpdateTimeOfDay().length > 0){ + interval = TimeUnit.DAYS.toMillis(1); + } + if(interval == 0) { // auto refresh is disabled + return; + } + long lastRefresh = DBTasks.getLastRefreshAllFeedsTimeMillis(context); + Log.d(TAG, "last refresh: " + Converter.getDurationStringLocalized(context, + System.currentTimeMillis() - lastRefresh) + " ago"); + if(lastRefresh <= System.currentTimeMillis() - interval) { + FeedUpdateUtils.startAutoUpdate(context, null); + } + } } |