diff options
author | tommy watson <toggles@gmail.com> | 2013-03-24 17:13:09 +0100 |
---|---|---|
committer | tommy watson <toggles@gmail.com> | 2013-03-24 17:13:09 +0100 |
commit | 931a47c7a4b75105a69a5ead261e78708ff5b486 (patch) | |
tree | 48de18c9672df7db9c190a91de6431b7bb21beea /src/de/danoeh/antennapod | |
parent | f966df8bcc3f8438570080eb616f469deac5e583 (diff) | |
download | AntennaPod-931a47c7a4b75105a69a5ead261e78708ff5b486.zip |
Only schedule expired feeds when update triggered.
Diffstat (limited to 'src/de/danoeh/antennapod')
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedManager.java | 53 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/preferences/UserPreferences.java | 2 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java | 2 |
3 files changed, 51 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index e5de32f59..45eed2203 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -2,12 +2,14 @@ package de.danoeh.antennapod.feed; import java.io.File; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import android.annotation.SuppressLint; import android.content.Context; @@ -449,11 +451,54 @@ public class FeedManager { } /** Updates all feeds in the feed list. */ - @SuppressLint("NewApi") public void refreshAllFeeds(final Context context) { if (AppConfig.DEBUG) Log.d(TAG, "Refreshing all feeds."); + refreshFeeds(context,feeds); + } + + /** Updates all feeds in the feed list. */ + public void refreshExpiredFeeds(final Context context) { + long millis=UserPreferences.getUpdateInterval(); + + if (AppConfig.DEBUG) + Log.d(TAG, "Refreshing expired feeds, "+millis+" ms"); + + if(millis>0) { + List<Feed> feedList=new ArrayList<Feed>(); + long now=Calendar.getInstance().getTime().getTime(); + + // Allow a 10 minute window.. + millis-=10*60*1000; + for(Feed feed:feeds) { + Date date=feed.getLastUpdate(); + if(date!=null) { + if(date.getTime()+millis<=now) { + if(AppConfig.DEBUG) { + Log.d(TAG, + "Adding expired feed "+feed.getTitle()); + } + feedList.add(feed); + } + else { + if(AppConfig.DEBUG) { + Log.d(TAG, + "Skipping feed "+feed.getTitle()); + } + } + } + } + if(feedList.size()>0) { + refreshFeeds(context,feedList); + } + } + } + + @SuppressLint("NewApi") + private void refreshFeeds(Context context,List<Feed> feeds) { if (!isStartingFeedRefresh) { + final Context ctx=context; + final List<Feed> feedList=feeds; isStartingFeedRefresh = true; AsyncTask<Void, Void, Void> updateWorker = new AsyncTask<Void, Void, Void>() { @@ -467,13 +512,13 @@ public class FeedManager { @Override protected Void doInBackground(Void... params) { - for (Feed feed : feeds) { + for (Feed feed : feedList) { try { - refreshFeed(context, feed); + refreshFeed(ctx, feed); } catch (DownloadRequestException e) { e.printStackTrace(); addDownloadStatus( - context, + ctx, new DownloadStatus(feed, feed .getHumanReadableIdentifier(), DownloadError.ERROR_REQUEST_ERROR, diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 489f9f02d..060c85d71 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -362,7 +362,7 @@ public class UserPreferences implements alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, millis, millis, updateIntent); if (AppConfig.DEBUG) - Log.d(TAG, "Changed alarm to new intervall"); + Log.d(TAG, "Changed alarm to new interval"); } else { if (AppConfig.DEBUG) Log.d(TAG, "Automatic update was deactivated"); diff --git a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java index 651a62aed..b2cdda9b2 100644 --- a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java +++ b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java @@ -21,7 +21,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver { if (AppConfig.DEBUG) Log.d(TAG, "Received intent"); boolean mobileUpdate = UserPreferences.isAllowMobileUpdate(); if (mobileUpdate || connectedToWifi(context)) { - FeedManager.getInstance().refreshAllFeeds(context); + FeedManager.getInstance().refreshExpiredFeeds(context); } else { if (AppConfig.DEBUG) Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); |