diff options
author | orionlee <orionlee@yahoo.com> | 2018-11-21 12:11:39 -0800 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2018-11-21 12:11:39 -0800 |
commit | feef92f80263a8304b7204cd719b54e1891d0ef0 (patch) | |
tree | dbd0b84e3a08283d5026074f026e6333bbcd8baa /core/src | |
parent | 1dc366544eca621537efddb7d7cc7b6eea4ca8d8 (diff) | |
download | AntennaPod-feef92f80263a8304b7204cd719b54e1891d0ef0.zip |
#2906: refactor: move auto feed update by interval helper,
checkShouldRefreshFeeds(), to proper level of abstraction.
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java | 34 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java | 29 |
2 files changed, 34 insertions, 29 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 bf13d1563..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,13 +27,10 @@ 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.FeedUpdateUtils; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; @@ -208,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 @@ -318,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) { - FeedUpdateUtils.startAutoUpdate(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); + } + } } |