summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2015-05-11 17:14:42 +0200
committerMartin Fietz <Martin.Fietz@gmail.com>2015-05-19 11:58:38 +0200
commit4561f16f11ed2f27d711d3ea42f5e84bcccc002c (patch)
treeed439456b9d56a2c2981876d27e14b30a89c1315 /core/src
parentc829a4e9b2cf7ccee117269769d71c40432f92fa (diff)
downloadAntennaPod-4561f16f11ed2f27d711d3ea42f5e84bcccc002c.zip
Redone new indicator
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java6
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java14
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java8
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java12
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java50
6 files changed, 57 insertions, 35 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
index 330a7ee83..44be0e3c5 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
@@ -179,7 +179,7 @@ public class Feed extends FeedFile implements FlattrThing, PicassoImageResource
*/
public boolean hasNewItems(boolean enableEpisodeFilter) {
for (FeedItem item : items) {
- if (item.getState() == FeedItem.State.NEW) {
+ if (item.getState() == FeedItem.State.UNREAD) {
if (item.getMedia() != null) {
return true;
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
index 45a62ca12..11348953e 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
@@ -239,7 +239,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
}
public boolean isRead() {
- return read || isInProgress();
+ return read;
}
public void setRead(boolean read) {
@@ -330,7 +330,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
}
public enum State {
- NEW, IN_PROGRESS, READ, PLAYING
+ UNREAD, IN_PROGRESS, READ, PLAYING
}
public State getState() {
@@ -342,7 +342,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
return State.IN_PROGRESS;
}
}
- return (isRead() ? State.READ : State.NEW);
+ return (isRead() ? State.READ : State.UNREAD);
}
public long getFeedId() {
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 0958aa7b9..99ae9a113 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
@@ -178,8 +178,7 @@ public final class DBReader {
*/
public static List<FeedItem> getFeedItemList(Context context,
final Feed feed) {
- if (BuildConfig.DEBUG)
- Log.d(TAG, "Extracting Feeditems of feed " + feed.getTitle());
+ Log.d(TAG, "Extracting Feeditems of feed " + feed.getTitle());
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
@@ -319,7 +318,7 @@ public final class DBReader {
new FlattrStatus(cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_FLATTR_STATUS)),
cursor.getInt(PodDBAdapter.IDX_FEED_SEL_STD_IS_PAGED) > 0,
cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_NEXT_PAGE_LINK),
- cursor.getString(cursor.getColumnIndex(PodDBAdapter.KEY_HIDE))
+ cursor.getString(cursor.getColumnIndex(PodDBAdapter.KEY_HIDE)),
cursor.getInt(PodDBAdapter.IDX_FEED_SEL_STD_LAST_UPDATE_FAILED) > 0
);
@@ -521,15 +520,16 @@ public final class DBReader {
* @return A list of IDs of the FeedItems whose 'read'-attribute is set to false. This method should be preferred
* over {@link #getUnreadItemsList(android.content.Context)} if the FeedItems in the UnreadItems list are not used.
*/
- public static long[] getUnreadItemIds(Context context) {
+ public static LongList getNewItemIds(Context context) {
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
- Cursor cursor = adapter.getUnreadItemIdsCursor();
- long[] itemIds = new long[cursor.getCount()];
+ Cursor cursor = adapter.getNewItemIdsCursor();
+ LongList itemIds = new LongList(cursor.getCount());
int i = 0;
if (cursor.moveToFirst()) {
do {
- itemIds[i] = cursor.getLong(PodDBAdapter.KEY_ID_INDEX);
+ long id = cursor.getLong(PodDBAdapter.KEY_ID_INDEX);
+ itemIds.add(id);
i++;
} while (cursor.moveToNext());
}
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 0817221c1..c5b701ab3 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
@@ -456,14 +456,6 @@ public final class DBTasks {
}
/**
- * Adds all FeedItem objects whose 'read'-attribute is false to the queue in a separate thread.
- */
- public static void enqueueAllNewItems(final Context context) {
- long[] unreadItems = DBReader.getUnreadItemIds(context);
- DBWriter.addQueueItem(context, unreadItems);
- }
-
- /**
* Returns the successor of a FeedItem in the queue.
*
* @param context Used for accessing the DB.
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 4355c7dd4..fe5d0dfd3 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
@@ -408,16 +408,11 @@ public class DBWriter {
if(addToFront){
queue.add(0, item);
- }else{
+ } else {
queue.add(item);
}
queueModified = true;
- if (!item.isRead()) {
- item.setRead(true);
- itemsToSave.add(item);
- unreadItemsModified = true;
- }
}
}
}
@@ -425,11 +420,6 @@ public class DBWriter {
adapter.setQueue(queue);
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue));
}
- if (unreadItemsModified) {
- adapter.setFeedItemlist(itemsToSave);
- EventDistributor.getInstance()
- .sendUnreadItemsUpdateBroadcast();
- }
}
adapter.close();
DBTasks.autodownloadUndownloadedItems(context);
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 23b5391c7..c087cb4b5 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
@@ -227,6 +227,28 @@ public class PodDBAdapter {
+ " TEXT," + KEY_START + " INTEGER," + KEY_FEEDITEM + " INTEGER,"
+ KEY_LINK + " TEXT," + KEY_CHAPTER_TYPE + " INTEGER)";
+ // SQL Statements for creating indexes
+ public static final String CREATE_INDEX_FEEDITEMS_FEED = "CREATE INDEX "
+ + TABLE_NAME_FEED_ITEMS + "_" + KEY_FEED + " ON " + TABLE_NAME_FEED_ITEMS + " ("
+ + KEY_FEED + ")";
+
+ public static final String CREATE_INDEX_FEEDITEMS_IMAGE = "CREATE INDEX "
+ + TABLE_NAME_FEED_ITEMS + "_" + KEY_IMAGE + " ON " + TABLE_NAME_FEED_ITEMS + " ("
+ + KEY_IMAGE + ")";
+
+ public static final String CREATE_INDEX_QUEUE_FEEDITEM = "CREATE INDEX "
+ + TABLE_NAME_QUEUE + "_" + KEY_FEEDITEM + " ON " + TABLE_NAME_QUEUE + " ("
+ + KEY_FEEDITEM + ")";
+
+ public static final String CREATE_INDEX_FEEDMEDIA_FEEDITEM = "CREATE INDEX "
+ + TABLE_NAME_FEED_MEDIA + "_" + KEY_FEEDITEM + " ON " + TABLE_NAME_FEED_MEDIA + " ("
+ + KEY_FEEDITEM + ")";
+
+ public static final String CREATE_INDEX_SIMPLECHAPTERS_FEEDITEM = "CREATE INDEX "
+ + TABLE_NAME_SIMPLECHAPTERS + "_" + KEY_FEEDITEM + " ON " + TABLE_NAME_SIMPLECHAPTERS + " ("
+ + KEY_FEEDITEM + ")";
+
+
private SQLiteDatabase db;
private final Context context;
private PodDBHelper helper;
@@ -1063,10 +1085,21 @@ public class PodDBAdapter {
return c;
}
- public final Cursor getUnreadItemIdsCursor() {
- Cursor c = db.query(TABLE_NAME_FEED_ITEMS, new String[]{KEY_ID},
- KEY_READ + "=0", null, null, null, KEY_PUBDATE + " DESC");
- return c;
+ public final Cursor getNewItemIdsCursor() {
+ final String query = "SELECT " + TABLE_NAME_FEED_ITEMS + "." + KEY_ID
+ + " FROM " + TABLE_NAME_FEED_ITEMS
+ + " INNER JOIN " + TABLE_NAME_FEED_MEDIA + " ON "
+ + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "="
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM
+ + " LEFT OUTER JOIN " + TABLE_NAME_QUEUE + " ON "
+ + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "="
+ + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM
+ + " WHERE "
+ + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + " = 0 AND " // unplayed
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " = 0 AND " // undownloaded
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + " = 0 AND " // not partially played
+ + TABLE_NAME_QUEUE + "." + KEY_ID + " IS NULL"; // not in queue
+ return db.rawQuery(query, null);
}
/**
@@ -1085,7 +1118,8 @@ public class PodDBAdapter {
+ TABLE_NAME_FEED_ITEMS + "." + KEY_READ + " = 0 AND " // unplayed
+ TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " = 0 AND " // undownloaded
+ TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + " = 0 AND " // not partially played
- + TABLE_NAME_QUEUE + "." + KEY_ID + " IS NULL"; // not in queue
+ + TABLE_NAME_QUEUE + "." + KEY_ID + " IS NULL" // not in queue
+ + " ORDER BY " + KEY_PUBDATE + " DESC";
Cursor c = db.rawQuery(query, null);
return c;
}
@@ -1425,6 +1459,12 @@ public class PodDBAdapter {
db.execSQL(CREATE_TABLE_DOWNLOAD_LOG);
db.execSQL(CREATE_TABLE_QUEUE);
db.execSQL(CREATE_TABLE_SIMPLECHAPTERS);
+
+ db.execSQL(CREATE_INDEX_FEEDITEMS_FEED);
+ db.execSQL(CREATE_INDEX_FEEDITEMS_IMAGE);
+ db.execSQL(CREATE_INDEX_FEEDMEDIA_FEEDITEM);
+ db.execSQL(CREATE_INDEX_QUEUE_FEEDITEM);
+ db.execSQL(CREATE_INDEX_SIMPLECHAPTERS_FEEDITEM);
}
@Override