diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-10-04 17:23:38 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-10-04 17:23:38 +0200 |
commit | 15446f18479a57a8d485d1c95e810b609b67f69f (patch) | |
tree | b233e465b1d42edaa308b6a4fe803a90a5c9c11a /src/de/danoeh/antennapod | |
parent | 44e4924db9afd40c2bfb9515ec84f2d569b150e3 (diff) | |
download | AntennaPod-15446f18479a57a8d485d1c95e810b609b67f69f.zip |
Fixed problem with automatic feed updates
Diffstat (limited to 'src/de/danoeh/antennapod')
4 files changed, 52 insertions, 35 deletions
diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 8b57979af..f00d6245c 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -347,6 +347,20 @@ public class UserPreferences implements editor.commit(); } + /** + * Sets the update interval value. Should only be used for testing purposes! + * */ + public static void setUpdateInterval(Context context, long newValue) { + instanceAvailable(); + SharedPreferences.Editor editor = PreferenceManager + .getDefaultSharedPreferences(context.getApplicationContext()) + .edit(); + editor.putString(PREF_UPDATE_INTERVAL, + String.valueOf(newValue)); + editor.commit(); + instance.updateInterval = newValue; + } + /** * Return the folder where the app stores all of its data. This method will * return the standard data folder if none has been set by the user. diff --git a/src/de/danoeh/antennapod/storage/DBReader.java b/src/de/danoeh/antennapod/storage/DBReader.java index a5a4c8cd4..d256d82ea 100644 --- a/src/de/danoeh/antennapod/storage/DBReader.java +++ b/src/de/danoeh/antennapod/storage/DBReader.java @@ -106,7 +106,7 @@ public final class DBReader { * of the returned list does NOT have its list of FeedItems yet. The FeedItem-list * can be loaded separately with {@link #getFeedItemList(android.content.Context, de.danoeh.antennapod.feed.Feed)}. */ - static List<Feed> getExpiredFeedsList(final Context context, final long expirationTime) { + public static List<Feed> getExpiredFeedsList(final Context context, final long expirationTime) { if (AppConfig.DEBUG) Log.d(TAG, String.format("getExpiredFeedsList(%d)", expirationTime)); diff --git a/src/de/danoeh/antennapod/storage/DBTasks.java b/src/de/danoeh/antennapod/storage/DBTasks.java index b9a1fd002..cd0e65e8f 100644 --- a/src/de/danoeh/antennapod/storage/DBTasks.java +++ b/src/de/danoeh/antennapod/storage/DBTasks.java @@ -1,27 +1,11 @@ package de.danoeh.antennapod.storage; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.FutureTask; -import java.util.concurrent.atomic.AtomicBoolean; - import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.util.Log; import de.danoeh.antennapod.AppConfig; -import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.feed.FeedImage; -import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.feed.*; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.service.GpodnetSyncService; import de.danoeh.antennapod.service.PlaybackService; @@ -32,6 +16,12 @@ import de.danoeh.antennapod.util.QueueAccess; import de.danoeh.antennapod.util.comparator.FeedItemPubdateComparator; import de.danoeh.antennapod.util.exception.MediaFileNotFoundException; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; +import java.util.concurrent.atomic.AtomicBoolean; + /** * Provides methods for doing common tasks that use DBReader and DBWriter. */ @@ -43,9 +33,10 @@ public final class DBTasks { /** * Removes the feed with the given download url. This method should NOT be executed on the GUI thread. - * @param context Used for accessing the db + * + * @param context Used for accessing the db * @param downloadUrl URL of the feed. - * */ + */ public static void removeFeedWithDownloadUrl(Context context, String downloadUrl) { PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); @@ -157,6 +148,30 @@ public final class DBTasks { } /** + * Used by refreshExpiredFeeds to determine which feeds should be refreshed. + * This method will use the value specified in the UserPreferences as the + * expiration time. + * @param context Used for DB access. + * @return A list of expired feeds. An empty list will be returned if there + * are no expired feeds. + */ + public static List<Feed> getExpiredFeeds(final Context context) { + long millis = UserPreferences.getUpdateInterval(); + + if (millis > 0) { + + List<Feed> feedList = DBReader.getExpiredFeedsList(context, + millis); + if (feedList.size() > 0) { + refreshFeeds(context, feedList); + } + return feedList; + } else { + return new ArrayList<Feed>(); + } + } + + /** * Refreshes expired Feeds in the list returned by the getExpiredFeedsList(Context, long) method in DBReader. * The expiration date parameter is determined by the update interval specified in {@link UserPreferences}. * @@ -168,19 +183,7 @@ public final class DBTasks { new Thread() { public void run() { - long millis = UserPreferences.getUpdateInterval(); - - if (millis > 0) { - long now = Calendar.getInstance().getTime().getTime(); - - // Allow a 10 minute window - millis -= 10 * 60 * 1000; - List<Feed> feedList = DBReader.getExpiredFeedsList(context, - now - millis); - if (feedList.size() > 0) { - refreshFeeds(context, feedList); - } - } + refreshFeeds(context, getExpiredFeeds(context)); } }.start(); } diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java index 2e2fa070c..53eb9858c 100644 --- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java +++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java @@ -675,8 +675,8 @@ public class PodDBAdapter { } public final Cursor getExpiredFeedsCursor(long expirationTime) { - Cursor c = db.query(TABLE_NAME_FEEDS, null, "?<?", new String[]{ - KEY_LASTUPDATE, String.valueOf(System.currentTimeMillis() - expirationTime)}, null, null, + Cursor c = db.query(TABLE_NAME_FEEDS, null, KEY_LASTUPDATE + " < " + String.valueOf(System.currentTimeMillis() - expirationTime), + null, null, null, null); return c; } |