summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage/PodDBAdapter.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-08-03 13:58:31 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2013-08-03 13:58:31 +0200
commit9ba3dc0d823b786700010a60d38f47c802101d27 (patch)
tree89b74eff993fdcb3b373c64695c72d534f1a80cd /src/de/danoeh/antennapod/storage/PodDBAdapter.java
parent2071793e6aa1a106744078fcbcf7c0529ed315c4 (diff)
downloadAntennaPod-9ba3dc0d823b786700010a60d38f47c802101d27.zip
Improved DownloadService, several bugfixes
- DownloadService should now terminate properly as soon as all downloads have been completed. - Notification bug ("0 downloads left" notification) should be fixed
Diffstat (limited to 'src/de/danoeh/antennapod/storage/PodDBAdapter.java')
-rw-r--r--src/de/danoeh/antennapod/storage/PodDBAdapter.java41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
index 1aa8c93d4..14ef07c34 100644
--- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java
+++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
@@ -201,6 +201,13 @@ public class PodDBAdapter {
TABLE_NAME_FEED_ITEMS + "." + KEY_HAS_CHAPTERS,
TABLE_NAME_FEED_ITEMS + "." + KEY_ITEM_IDENTIFIER };
+ /** Contains SEL_FI_SMALL as comma-separated list. Useful for raw queries. */
+ private static final String SEL_FI_SMALL_STR;
+ static {
+ String selFiSmall = Arrays.toString(SEL_FI_SMALL);
+ SEL_FI_SMALL_STR = selFiSmall.substring(1, selFiSmall.length() - 1);
+ }
+
// column indices for SEL_FI_SMALL
public static final int IDX_FI_SMALL_ID = 0;
@@ -601,7 +608,7 @@ public class PodDBAdapter {
public final Cursor getAllFeedsCursor() {
open();
Cursor c = db.query(TABLE_NAME_FEEDS, null, null, null, null, null,
- null);
+ KEY_TITLE + " ASC");
return c;
}
@@ -692,9 +699,8 @@ public class PodDBAdapter {
*/
public final Cursor getQueueCursor() {
open();
- String selFiSmall = Arrays.toString(SEL_FI_SMALL);
Object[] args = (Object[]) new String[] {
- selFiSmall.substring(1, selFiSmall.length() - 1) + "," + TABLE_NAME_QUEUE + "." + KEY_ID,
+ SEL_FI_SMALL_STR + "," + TABLE_NAME_QUEUE + "." + KEY_ID,
TABLE_NAME_FEED_ITEMS, TABLE_NAME_QUEUE,
TABLE_NAME_FEED_ITEMS + "." + KEY_ID,
TABLE_NAME_QUEUE + "." + KEY_FEEDITEM,
@@ -738,12 +744,12 @@ public class PodDBAdapter {
public Cursor getDownloadedItemsCursor() {
open();
- Cursor c = db.rawQuery("SELECT ? FROM " + TABLE_NAME_FEED_ITEMS
- + "FULL JOIN " + TABLE_NAME_FEED_MEDIA + " ON "
- + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "="
- + TABLE_NAME_FEED_MEDIA + "." + KEY_ID + " WHERE "
- + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + ">0",
- SEL_FI_SMALL);
+ final String query = "SELECT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS
+ + " INNER JOIN " + TABLE_NAME_FEED_MEDIA + " ON "
+ + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "="
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_ID + " WHERE "
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + ">0";
+ Cursor c = db.rawQuery(query, null);
return c;
}
@@ -768,7 +774,11 @@ public class PodDBAdapter {
return c;
}
- public final Cursor getFeedMediaCursor(String... mediaIds) {
+ public final Cursor getSingleFeedMediaCursor(long id) {
+ return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?", new String[] {Long.toString(id)}, null, null, null);
+ }
+
+ public final Cursor getFeedMediaCursorByItemID(String... mediaIds) {
int length = mediaIds.length;
if (length > IN_OPERATOR_MAXIMUM) {
Log.w(TAG, "Length of id array is larger than "
@@ -837,11 +847,14 @@ public class PodDBAdapter {
}
public final int getNumberOfDownloadedEpisodes() {
+ final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_MEDIA +
+ " WHERE " + KEY_DOWNLOADED + " > 0";
- Cursor c = db.rawQuery(
- "SELECT COUNT(DISTINCT ?) AS count FROM ? WHERE ?>0",
- new String[] { KEY_ID, TABLE_NAME_FEED_MEDIA, KEY_DOWNLOADED });
- final int result = c.getInt(0);
+ Cursor c = db.rawQuery(query, null);
+ int result = 0;
+ if (c.moveToFirst()) {
+ result = c.getInt(0);
+ }
c.close();
return result;
}