From f290048362f9b4da51b5f238d4a57751052b1cad Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Mon, 25 Jan 2016 15:02:44 -0500 Subject: allow feeds to be excluded from global refreshing --- .../antennapod/core/feed/FeedPreferences.java | 22 +++++++++++++-- .../de/danoeh/antennapod/core/storage/DBTasks.java | 32 ++++++++++++++-------- .../antennapod/core/storage/PodDBAdapter.java | 8 ++++++ 3 files changed, 48 insertions(+), 14 deletions(-) (limited to 'core/src/main/java') 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)); } /** @@ -72,6 +76,18 @@ public class FeedPreferences { this.filter = filter; } + /** + * @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 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()); -- cgit v1.2.3 From c5d05d338aefda7a7832538bd18b4702c8dce587 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Mon, 25 Jan 2016 16:28:55 -0500 Subject: If the feed doesn't have 'Global Refresh' then don't include it in the New Episodes list. resolves AntennaPod/AntennaPod#286 --- .../danoeh/antennapod/core/storage/PodDBAdapter.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'core/src/main/java') 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 382fad03d..9ba8f1ffd 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 @@ -1131,13 +1131,6 @@ public class PodDBAdapter { return c; } - public final Cursor getNewItemIdsCursor() { - final String query = "SELECT " + KEY_ID - + " FROM " + TABLE_NAME_FEED_ITEMS - + " WHERE " + KEY_READ + "=" + FeedItem.NEW; - return db.rawQuery(query, null); - } - /** * Returns a cursor which contains all items of a feed that are considered new. * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. @@ -1157,10 +1150,15 @@ public class PodDBAdapter { * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. */ public final Cursor getNewItemsCursor() { - final String query = "SELECT " + SEL_FI_SMALL_STR - + " FROM " + TABLE_NAME_FEED_ITEMS - + " WHERE " + KEY_READ + "=" + FeedItem.NEW - + " ORDER BY " + KEY_PUBDATE + " DESC"; + String[] args = new String[] { + SEL_FI_SMALL_STR, + TABLE_NAME_FEED_ITEMS, + TABLE_NAME_FEEDS, + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID, + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW + " AND " + TABLE_NAME_FEEDS + "." + KEY_GLOBAL_REFRESH + " > 0", + KEY_PUBDATE + " DESC" + }; + final String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s WHERE %s ORDER BY %s", args); Cursor c = db.rawQuery(query, null); return c; } -- cgit v1.2.3 From 747aa2f0e01c4a3b2ecdf8fbc6cad57ac390bcb4 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Mon, 25 Jan 2016 16:40:46 -0500 Subject: updated comments --- core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java | 2 +- core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'core/src/main/java') diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index bc4c671a2..d29eec02c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -371,7 +371,7 @@ public final class DBReader { /** * Loads a list of FeedItems that are considered new. - * + * Excludes items from feeds that do not have global refresh enabled. * @return A list of FeedItems that are considered new. */ public static List getNewItemsList() { 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 9ba8f1ffd..4dcb7e096 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 @@ -1147,6 +1147,7 @@ public class PodDBAdapter { /** * Returns a cursor which contains all feed items that are considered new. + * Excludes those feeds that do not have 'global_refresh' enabled. * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. */ public final Cursor getNewItemsCursor() { -- cgit v1.2.3 From 7dfe4d5ed34ebc308b123138e582436a22bc95cf Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Mon, 25 Jan 2016 17:21:13 -0500 Subject: Global Refresh -> Keep Updated --- .../de/danoeh/antennapod/core/feed/FeedPreferences.java | 16 ++++++++-------- .../java/de/danoeh/antennapod/core/storage/DBReader.java | 2 +- .../java/de/danoeh/antennapod/core/storage/DBTasks.java | 4 ++-- .../de/danoeh/antennapod/core/storage/PodDBAdapter.java | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'core/src/main/java') 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 30e14dd5e..faf23a37a 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,7 +18,7 @@ public class FeedPreferences { private FeedFilter filter; private long feedID; private boolean autoDownload; - private boolean globalRefresh; + private boolean keepUpdated; public enum AutoDeleteAction { GLOBAL, @@ -33,10 +33,10 @@ public class FeedPreferences { this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter()); } - public FeedPreferences(long feedID, boolean autoDownload, boolean globalRefresh, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) { + public FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) { this.feedID = feedID; this.autoDownload = autoDownload; - this.globalRefresh = globalRefresh; + this.keepUpdated = keepUpdated; this.auto_delete_action = auto_delete_action; this.username = username; this.password = password; @@ -46,7 +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 indexAutoRefresh = cursor.getColumnIndex(PodDBAdapter.KEY_KEEP_UPDATED); int indexAutoDeleteAction = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DELETE_ACTION); int indexUsername = cursor.getColumnIndex(PodDBAdapter.KEY_USERNAME); int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD); @@ -80,12 +80,12 @@ 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 boolean getKeepUpdated() { + return keepUpdated; } - public void setGlobalRefresh(boolean globalRefresh) { - this.globalRefresh = globalRefresh; + public void setKeepUpdated(boolean keepUpdated) { + this.keepUpdated = keepUpdated; } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index d29eec02c..0563f878f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -371,7 +371,7 @@ public final class DBReader { /** * Loads a list of FeedItems that are considered new. - * Excludes items from feeds that do not have global refresh enabled. + * Excludes items from feeds that do not have keep updated enabled. * @return A list of FeedItems that are considered new. */ public static List getNewItemsList() { 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 b69fa1eef..efc60bfc2 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 @@ -196,9 +196,9 @@ public final class DBTasks { for (Feed feed : feedList) { FeedPreferences prefs = feed.getPreferences(); - // feeds with !getGlobalRefresh can only be refreshed + // feeds with !getKeepUpdated can only be refreshed // directly from the FeedActivity - if (prefs.getGlobalRefresh()) { + if (prefs.getKeepUpdated()) { try { refreshFeed(context, feed); } catch (DownloadRequestException e) { 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 4dcb7e096..85ff8fc8c 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,7 +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_KEEP_UPDATED = "keep_updated"; 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"; @@ -133,7 +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_KEEP_UPDATED + " INTEGER DEFAULT 1," + KEY_IS_PAGED + " INTEGER DEFAULT 0," + KEY_NEXT_PAGE_LINK + " TEXT," + KEY_HIDE + " TEXT," @@ -236,7 +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_KEEP_UPDATED, TABLE_NAME_FEEDS + "." + KEY_FLATTR_STATUS, TABLE_NAME_FEEDS + "." + KEY_IS_PAGED, TABLE_NAME_FEEDS + "." + KEY_NEXT_PAGE_LINK, @@ -401,7 +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_KEEP_UPDATED, prefs.getKeepUpdated()); values.put(KEY_AUTO_DELETE_ACTION,prefs.getAutoDeleteAction().ordinal()); values.put(KEY_USERNAME, prefs.getUsername()); values.put(KEY_PASSWORD, prefs.getPassword()); @@ -1147,7 +1147,7 @@ public class PodDBAdapter { /** * Returns a cursor which contains all feed items that are considered new. - * Excludes those feeds that do not have 'global_refresh' enabled. + * Excludes those feeds that do not have 'Keep Updated' enabled. * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. */ public final Cursor getNewItemsCursor() { @@ -1156,7 +1156,7 @@ public class PodDBAdapter { TABLE_NAME_FEED_ITEMS, TABLE_NAME_FEEDS, TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID, - TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW + " AND " + TABLE_NAME_FEEDS + "." + KEY_GLOBAL_REFRESH + " > 0", + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0", KEY_PUBDATE + " DESC" }; final String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s WHERE %s ORDER BY %s", args); @@ -1802,7 +1802,7 @@ public class PodDBAdapter { // and now auto refresh db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS - + " ADD COLUMN " + PodDBAdapter.KEY_GLOBAL_REFRESH + " INTEGER DEFAULT 1"); + + " ADD COLUMN " + PodDBAdapter.KEY_KEEP_UPDATED + " INTEGER DEFAULT 1"); } EventBus.getDefault().post(ProgressEvent.end()); -- cgit v1.2.3