diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2016-01-25 15:02:44 -0500 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2016-01-25 15:02:44 -0500 |
commit | f290048362f9b4da51b5f238d4a57751052b1cad (patch) | |
tree | ffad0b6fe945a1067dc051b7687a5040a2057376 /core/src | |
parent | f9afe0d488bdb14798136fa183cb5831329b7cde (diff) | |
download | AntennaPod-f290048362f9b4da51b5f238d4a57751052b1cad.zip |
allow feeds to be excluded from global refreshing
Diffstat (limited to 'core/src')
4 files changed, 49 insertions, 14 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java index 9e95d5276..30e14dd5e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java @@ -18,6 +18,7 @@ public class FeedPreferences { private FeedFilter filter; private long feedID; private boolean autoDownload; + private boolean globalRefresh; public enum AutoDeleteAction { GLOBAL, @@ -29,12 +30,13 @@ public class FeedPreferences { private String password; public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password) { - this(feedID, autoDownload, auto_delete_action, username, password, new FeedFilter()); + this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter()); } - public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) { + public FeedPreferences(long feedID, boolean autoDownload, boolean globalRefresh, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) { this.feedID = feedID; this.autoDownload = autoDownload; + this.globalRefresh = globalRefresh; this.auto_delete_action = auto_delete_action; this.username = username; this.password = password; @@ -44,6 +46,7 @@ public class FeedPreferences { public static FeedPreferences fromCursor(Cursor cursor) { int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID); int indexAutoDownload = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DOWNLOAD); + int indexAutoRefresh = cursor.getColumnIndex(PodDBAdapter.KEY_GLOBAL_REFRESH); int indexAutoDeleteAction = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DELETE_ACTION); int indexUsername = cursor.getColumnIndex(PodDBAdapter.KEY_USERNAME); int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD); @@ -52,13 +55,14 @@ public class FeedPreferences { long feedId = cursor.getLong(indexId); boolean autoDownload = cursor.getInt(indexAutoDownload) > 0; + boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0; int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction); AutoDeleteAction autoDeleteAction = AutoDeleteAction.values()[autoDeleteActionIndex]; String username = cursor.getString(indexUsername); String password = cursor.getString(indexPassword); String includeFilter = cursor.getString(indexIncludeFilter); String excludeFilter = cursor.getString(indexExcludeFilter); - return new FeedPreferences(feedId, autoDownload, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter)); + return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter)); } /** @@ -73,6 +77,18 @@ public class FeedPreferences { } /** + * @return true if this feed should be refreshed when everything else is being refreshed + * if false the feed should only be refreshed if requested directly. + */ + public boolean getGlobalRefresh() { + return globalRefresh; + } + + public void setGlobalRefresh(boolean globalRefresh) { + this.globalRefresh = globalRefresh; + } + + /** * Compare another FeedPreferences with this one. The feedID, autoDownload and AutoDeleteAction attribute are excluded from the * comparison. * 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 157e6d28c..b69fa1eef 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 @@ -26,6 +26,7 @@ import de.danoeh.antennapod.core.feed.EventDistributor; 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.service.GpodnetSyncService; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.service.playback.PlaybackService; @@ -186,21 +187,30 @@ public final class DBTasks { } } + /** + * @param context + * @param feedList the list of feeds to refresh + */ private static void refreshFeeds(final Context context, final List<Feed> feedList) { for (Feed feed : feedList) { - try { - refreshFeed(context, feed); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DBWriter.addDownloadStatus( - new DownloadStatus(feed, feed - .getHumanReadableIdentifier(), - DownloadError.ERROR_REQUEST_ERROR, false, e - .getMessage() - ) - ); + FeedPreferences prefs = feed.getPreferences(); + // feeds with !getGlobalRefresh can only be refreshed + // directly from the FeedActivity + if (prefs.getGlobalRefresh()) { + try { + refreshFeed(context, feed); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DBWriter.addDownloadStatus( + new DownloadStatus(feed, feed + .getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, false, e + .getMessage() + ) + ); + } } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 6ade990cd..382fad03d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -92,6 +92,7 @@ public class PodDBAdapter { public static final String KEY_CHAPTER_TYPE = "type"; public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date"; public static final String KEY_AUTO_DOWNLOAD = "auto_download"; + public static final String KEY_GLOBAL_REFRESH = "global_refresh"; public static final String KEY_AUTO_DELETE_ACTION = "auto_delete_action"; public static final String KEY_PLAYED_DURATION = "played_duration"; public static final String KEY_USERNAME = "username"; @@ -132,6 +133,7 @@ public class PodDBAdapter { + KEY_PASSWORD + " TEXT," + KEY_INCLUDE_FILTER + " TEXT DEFAULT ''," + KEY_EXCLUDE_FILTER + " TEXT DEFAULT ''," + + KEY_GLOBAL_REFRESH + " INTEGER DEFAULT 1," + KEY_IS_PAGED + " INTEGER DEFAULT 0," + KEY_NEXT_PAGE_LINK + " TEXT," + KEY_HIDE + " TEXT," @@ -234,6 +236,7 @@ public class PodDBAdapter { TABLE_NAME_FEEDS + "." + KEY_TYPE, TABLE_NAME_FEEDS + "." + KEY_FEED_IDENTIFIER, TABLE_NAME_FEEDS + "." + KEY_AUTO_DOWNLOAD, + TABLE_NAME_FEEDS + "." + KEY_GLOBAL_REFRESH, TABLE_NAME_FEEDS + "." + KEY_FLATTR_STATUS, TABLE_NAME_FEEDS + "." + KEY_IS_PAGED, TABLE_NAME_FEEDS + "." + KEY_NEXT_PAGE_LINK, @@ -398,6 +401,7 @@ public class PodDBAdapter { } ContentValues values = new ContentValues(); values.put(KEY_AUTO_DOWNLOAD, prefs.getAutoDownload()); + values.put(KEY_GLOBAL_REFRESH, prefs.getGlobalRefresh()); values.put(KEY_AUTO_DELETE_ACTION,prefs.getAutoDeleteAction().ordinal()); values.put(KEY_USERNAME, prefs.getUsername()); values.put(KEY_PASSWORD, prefs.getPassword()); @@ -1796,6 +1800,10 @@ public class PodDBAdapter { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + PodDBAdapter.KEY_EXCLUDE_FILTER + " TEXT DEFAULT ''"); + + // and now auto refresh + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_GLOBAL_REFRESH + " INTEGER DEFAULT 1"); } EventBus.getDefault().post(ProgressEvent.end()); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index b8f6f7065..3adcb6e00 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -536,6 +536,7 @@ <string name="episode_filters_include">Include</string> <string name="episode_filters_exclude">Exclude</string> <string name="episode_filters_hint">Single words \n\"Multiple Words\"</string> + <string name="global_refresh">Global Refresh</string> <!-- Progress information --> <string name="progress_upgrading_database">Upgrading the database</string> |