summaryrefslogtreecommitdiff
path: root/src/de/podfetcher/storage/PodDBAdapter.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-17 17:56:39 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-17 17:56:39 +0200
commit2f5e0dd0233ff0209e1a70a2a96e03f697bfee72 (patch)
tree679cb64b53c999136dab8b3c59a7aa0a0fc51bca /src/de/podfetcher/storage/PodDBAdapter.java
parentc41a61752f89a3430548b271b6c463decffe5815 (diff)
downloadAntennaPod-2f5e0dd0233ff0209e1a70a2a96e03f697bfee72.zip
FeedManager now maintains a list of DownloadStatus entries
Diffstat (limited to 'src/de/podfetcher/storage/PodDBAdapter.java')
-rw-r--r--src/de/podfetcher/storage/PodDBAdapter.java66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java
index 90a8cd7b3..6d05b61eb 100644
--- a/src/de/podfetcher/storage/PodDBAdapter.java
+++ b/src/de/podfetcher/storage/PodDBAdapter.java
@@ -5,6 +5,7 @@ import de.podfetcher.feed.FeedCategory;
import de.podfetcher.feed.FeedImage;
import de.podfetcher.feed.FeedItem;
import de.podfetcher.feed.FeedMedia;
+import de.podfetcher.service.DownloadStatus;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@@ -42,13 +43,18 @@ public class PodDBAdapter {
public static final String KEY_MEDIA = "media";
public static final String KEY_DOWNLOADED = "downloaded";
public static final String KEY_LASTUPDATE = "last_update";
-
+ public static final String KEY_FEEDFILE = "feedfile";
+ public static final String KEY_REASON = "reason";
+ public static final String KEY_SUCCESSFUL = "successful";
+ public static final String KEY_FEEDFILETYPE = "feedfile_type";
+ public static final String KEY_COMPLETION_DATE = "completion_date";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
public static final String TABLE_NAME_FEED_ITEMS = "FeedItems";
public static final String TABLE_NAME_FEED_CATEGORIES = "FeedCategories";
public static final String TABLE_NAME_FEED_IMAGES = "FeedImages";
public static final String TABLE_NAME_FEED_MEDIA = "FeedMedia";
+ public static final String TABLE_NAME_DOWNLOAD_LOG = "DownloadLog";
// SQL Statements for creating new tables
private static final String TABLE_PRIMARY_KEY = KEY_ID
@@ -81,6 +87,20 @@ public class PodDBAdapter {
+ KEY_MIME_TYPE + " TEXT," + KEY_FILE_URL + " TEXT,"
+ KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
+ private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
+ + TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE
+ + " INTEGER," + KEY_FEEDFILETYPE + " INTEGER," + KEY_REASON
+ + " INTEGER," + KEY_SUCCESSFUL + " INTEGER," + KEY_COMPLETION_DATE
+ + " INTEGER)";
+
+ /**
+ * Used for storing download status entries to determine the type of the
+ * Feedfile.
+ */
+ public static final int FEEDFILETYPE_FEED = 0;
+ public static final int FEEDFILETYPE_FEEDIMAGE = 1;
+ public static final int FEEDFILETYPE_FEEDMEDIA = 2;
+
private SQLiteDatabase db;
private final Context context;
private PodDBHelper helper;
@@ -247,6 +267,41 @@ public class PodDBAdapter {
}
/**
+ * Inserts or updates a download status.
+ * */
+ public long setDownloadStatus(DownloadStatus status) {
+ ContentValues values = new ContentValues();
+ values.put(KEY_FEEDFILE, status.getFeedFile().getId());
+ if (status.getFeedFile().getClass() == Feed.class) {
+ values.put(KEY_FEEDFILETYPE, FEEDFILETYPE_FEED);
+ } else if (status.getFeedFile().getClass() == FeedImage.class) {
+ values.put(KEY_FEEDFILETYPE, FEEDFILETYPE_FEEDIMAGE);
+ } else if (status.getFeedFile().getClass() == FeedMedia.class) {
+ values.put(KEY_FEEDFILETYPE, FEEDFILETYPE_FEEDMEDIA);
+ }
+
+ values.put(KEY_REASON, status.getReason());
+ values.put(KEY_SUCCESSFUL, status.isSuccessful());
+ values.put(KEY_COMPLETION_DATE, status.getCompletionDate().getTime());
+ open();
+ if (status.getId() == 0) {
+ status.setId(db.insert(TABLE_NAME_DOWNLOAD_LOG, null, values));
+ } else {
+ db.update(TABLE_NAME_DOWNLOAD_LOG, values, KEY_ID + "=?",
+ new String[] { String.valueOf(status.getId()) });
+ }
+ close();
+ return status.getId();
+ }
+
+ public void removeDownloadStatus(DownloadStatus remove) {
+ open();
+ db.delete(TABLE_NAME_DOWNLOAD_LOG, KEY_ID + "=?",
+ new String[] { String.valueOf(remove.getId()) });
+ close();
+ }
+
+ /**
* Get all Categories from the Categories Table.
*
* @return The cursor of the query
@@ -315,6 +370,13 @@ public class PodDBAdapter {
return c;
}
+ public final Cursor getDownloadLogCursor() {
+ open();
+ Cursor c = db.query(TABLE_NAME_DOWNLOAD_LOG, null, null, null, null,
+ null, null);
+ return c;
+ }
+
/**
* Get a FeedMedia object from the Database.
*
@@ -393,6 +455,7 @@ public class PodDBAdapter {
db.execSQL(CREATE_TABLE_FEED_CATEGORIES);
db.execSQL(CREATE_TABLE_FEED_IMAGES);
db.execSQL(CREATE_TABLE_FEED_MEDIA);
+ db.execSQL(CREATE_TABLE_DOWNLOAD_LOG);
}
@Override
@@ -403,4 +466,5 @@ public class PodDBAdapter {
// TODO delete Database
}
}
+
}