diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-06-24 10:15:01 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-06-24 10:18:14 +0200 |
commit | 92752e79969266d9c924e3683f187756b70d1729 (patch) | |
tree | 9652d8b95a4205ce76455efa890c0a81ea458786 /core/src | |
parent | 63bb80560b666c16c4f9d45f13673db317e6fe4e (diff) | |
download | AntennaPod-92752e79969266d9c924e3683f187756b70d1729.zip |
Fix mark as seen and improve mark all X [of feed Z] as Y
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java | 52 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java | 24 |
2 files changed, 43 insertions, 33 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 50bcd64cb..8e007019f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -4,7 +4,6 @@ import android.app.backup.BackupManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.database.Cursor; import android.preference.PreferenceManager; import android.util.Log; @@ -649,7 +648,7 @@ public class DBWriter { } /** - * Sets the 'read'-attribute of all FeedItems of a specific Feed to true. + * Sets the 'read'-attribute of all NEW FeedItems of a specific Feed to UNPLAYED. * * @param feedId ID of the Feed. */ @@ -657,15 +656,7 @@ public class DBWriter { return dbExec.submit(() -> { final PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - Cursor itemCursor = adapter.getNewItemsIdsCursor(feedId); - long[] ids = new long[itemCursor.getCount()]; - itemCursor.moveToFirst(); - for (int i = 0; i < ids.length; i++) { - ids[i] = itemCursor.getLong(0); - itemCursor.moveToNext(); - } - itemCursor.close(); - adapter.setFeedItemRead(FeedItem.UNPLAYED, ids); + adapter.setFeedItems(FeedItem.NEW, FeedItem.UNPLAYED, feedId); adapter.close(); EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); @@ -673,7 +664,7 @@ public class DBWriter { } /** - * Sets the 'read'-attribute of all FeedItems of a specific Feed to true. + * Sets the 'read'-attribute of all FeedItems of a specific Feed to PLAYED. * * @param feedId ID of the Feed. */ @@ -681,16 +672,7 @@ public class DBWriter { return dbExec.submit(() -> { final PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - Cursor itemCursor = adapter.getAllItemsOfFeedCursor(feedId); - long[] itemIds = new long[itemCursor.getCount()]; - itemCursor.moveToFirst(); - for (int i = 0; i < itemIds.length; i++) { - int indexId = itemCursor.getColumnIndex(PodDBAdapter.KEY_ID); - itemIds[i] = itemCursor.getLong(indexId); - itemCursor.moveToNext(); - } - itemCursor.close(); - adapter.setFeedItemRead(FeedItem.PLAYED, itemIds); + adapter.setFeedItems(FeedItem.PLAYED, feedId); adapter.close(); EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); @@ -698,27 +680,31 @@ public class DBWriter { } /** - * Sets the 'read'-attribute of all FeedItems to true. + * Sets the 'read'-attribute of all FeedItems to PLAYED. */ public static Future<?> markAllItemsRead() { return dbExec.submit(() -> { final PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - Cursor itemCursor = adapter.getUnreadItemsCursor(); - long[] itemIds = new long[itemCursor.getCount()]; - itemCursor.moveToFirst(); - for (int i = 0; i < itemIds.length; i++) { - int indexId = itemCursor.getColumnIndex(PodDBAdapter.KEY_ID); - itemIds[i] = itemCursor.getLong(indexId); - itemCursor.moveToNext(); - } - itemCursor.close(); - adapter.setFeedItemRead(FeedItem.PLAYED, itemIds); + adapter.setFeedItems(FeedItem.PLAYED); adapter.close(); EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); }); + } + /** + * Sets the 'read'-attribute of all NEW FeedItems to UNPLAYED. + */ + public static Future<?> markNewItemsSeen() { + return dbExec.submit(() -> { + final PodDBAdapter adapter = PodDBAdapter.getInstance(); + adapter.open(); + adapter.setFeedItems(FeedItem.NEW, FeedItem.UNPLAYED); + adapter.close(); + + EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); + }); } static Future<?> addNewFeed(final Context context, final Feed... feeds) { 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 92d1e790c..ecba0f9af 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 @@ -1215,6 +1215,30 @@ public class PodDBAdapter { + "<" + FeedItem.PLAYED, null, null, null, KEY_PUBDATE + " DESC"); } + public void setFeedItems(int state) { + setFeedItems(Integer.MIN_VALUE, state, 0); + } + + public void setFeedItems(int oldState, int newState) { + setFeedItems(oldState, newState, 0); + } + + public void setFeedItems(int state, long feedId) { + setFeedItems(Integer.MIN_VALUE, state, feedId); + } + + public void setFeedItems(int oldState, int newState, long feedId) { + String sql = "UPDATE " + TABLE_NAME_FEED_ITEMS + " SET " + KEY_READ + "=" + newState; + if(feedId > 0) { + sql += " WHERE " + KEY_FEED + "=" + feedId; + } + if(FeedItem.NEW <= oldState && oldState <= FeedItem.PLAYED) { + sql += feedId > 0 ? " AND " : " WHERE "; + sql += KEY_READ + "=" + oldState; + } + db.execSQL(sql); + } + /** * Returns a cursor which contains all items of a feed that are considered new. * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. |