Added playbackCompletionDate attribute

This commit is contained in:
daniel oeh 2012-10-02 16:45:20 +02:00
parent 2b69696359
commit f614b0fa72
3 changed files with 36 additions and 32 deletions

View File

@ -1083,6 +1083,14 @@ public class FeedManager {
FeedItem item = getMatchingItemForMedia(mediaId, itemsCopy); FeedItem item = getMatchingItemForMedia(mediaId, itemsCopy);
itemsCopy.remove(item); itemsCopy.remove(item);
if (item != null) { if (item != null) {
Date playbackCompletionDate = null;
long playbackCompletionTime = cursor
.getLong(PodDBAdapter.KEY_PLAYBACK_COMPLETION_DATE_INDEX);
if (playbackCompletionTime > 0) {
playbackCompletionDate = new Date(
playbackCompletionTime);
}
item.setMedia(new FeedMedia( item.setMedia(new FeedMedia(
mediaId, mediaId,
item, item,
@ -1092,7 +1100,8 @@ public class FeedManager {
cursor.getString(PodDBAdapter.KEY_MIME_TYPE_INDEX), cursor.getString(PodDBAdapter.KEY_MIME_TYPE_INDEX),
cursor.getString(PodDBAdapter.KEY_FILE_URL_INDEX), cursor.getString(PodDBAdapter.KEY_FILE_URL_INDEX),
cursor.getString(PodDBAdapter.KEY_DOWNLOAD_URL_INDEX), cursor.getString(PodDBAdapter.KEY_DOWNLOAD_URL_INDEX),
cursor.getInt(PodDBAdapter.KEY_DOWNLOADED_INDEX) > 0)); cursor.getInt(PodDBAdapter.KEY_DOWNLOADED_INDEX) > 0,
playbackCompletionDate));
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext());

View File

@ -1,5 +1,7 @@
package de.danoeh.antennapod.feed; package de.danoeh.antennapod.feed;
import java.util.Date;
public class FeedMedia extends FeedFile { public class FeedMedia extends FeedFile {
public static final int FEEDFILETYPE_FEEDMEDIA = 2; public static final int FEEDFILETYPE_FEEDMEDIA = 2;
@ -9,6 +11,7 @@ public class FeedMedia extends FeedFile {
private long size; // File size in Byte private long size; // File size in Byte
private String mime_type; private String mime_type;
private FeedItem item; private FeedItem item;
private Date playbackCompletionDate;
public FeedMedia(FeedItem i, String download_url, long size, public FeedMedia(FeedItem i, String download_url, long size,
String mime_type) { String mime_type) {
@ -20,7 +23,7 @@ public class FeedMedia extends FeedFile {
public FeedMedia(long id, FeedItem item, int duration, int position, public FeedMedia(long id, FeedItem item, int duration, int position,
long size, String mime_type, String file_url, String download_url, long size, String mime_type, String file_url, String download_url,
boolean downloaded) { boolean downloaded, Date playbackCompletionDate) {
super(file_url, download_url, downloaded); super(file_url, download_url, downloaded);
this.id = id; this.id = id;
this.item = item; this.item = item;
@ -28,6 +31,7 @@ public class FeedMedia extends FeedFile {
this.position = position; this.position = position;
this.size = size; this.size = size;
this.mime_type = mime_type; this.mime_type = mime_type;
this.playbackCompletionDate = playbackCompletionDate;
} }
public FeedMedia(long id, FeedItem item) { public FeedMedia(long id, FeedItem item) {
@ -106,4 +110,12 @@ public class FeedMedia extends FeedFile {
this.item = item; this.item = item;
} }
public Date getPlaybackCompletionDate() {
return playbackCompletionDate;
}
public void setPlaybackCompletionDate(Date playbackCompletionDate) {
this.playbackCompletionDate = playbackCompletionDate;
}
} }

View File

@ -25,7 +25,7 @@ import de.danoeh.antennapod.feed.FeedMedia;
* */ * */
public class PodDBAdapter { public class PodDBAdapter {
private static final String TAG = "PodDBAdapter"; private static final String TAG = "PodDBAdapter";
private static final int DATABASE_VERSION = 7; private static final int DATABASE_VERSION = 8;
private static final String DATABASE_NAME = "Antennapod.db"; private static final String DATABASE_NAME = "Antennapod.db";
/** Maximum number of arguments for IN-operator. */ /** Maximum number of arguments for IN-operator. */
@ -61,6 +61,7 @@ public class PodDBAdapter {
public static final int KEY_POSITION_INDEX = 5; public static final int KEY_POSITION_INDEX = 5;
public static final int KEY_SIZE_INDEX = 6; public static final int KEY_SIZE_INDEX = 6;
public static final int KEY_MIME_TYPE_INDEX = 7; public static final int KEY_MIME_TYPE_INDEX = 7;
public static final int KEY_PLAYBACK_COMPLETION_DATE_INDEX = 8;
// --------- Download log indices // --------- Download log indices
public static final int KEY_FEEDFILE_INDEX = 1; public static final int KEY_FEEDFILE_INDEX = 1;
public static final int KEY_FEEDFILETYPE_INDEX = 2; public static final int KEY_FEEDFILETYPE_INDEX = 2;
@ -115,6 +116,7 @@ public class PodDBAdapter {
public static final String KEY_REASON_DETAILED = "reason_detailed"; public static final String KEY_REASON_DETAILED = "reason_detailed";
public static final String KEY_DOWNLOADSTATUS_TITLE = "title"; public static final String KEY_DOWNLOADSTATUS_TITLE = "title";
public static final String KEY_CHAPTER_TYPE = "type"; public static final String KEY_CHAPTER_TYPE = "type";
public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date";
// Table names // Table names
public static final String TABLE_NAME_FEEDS = "Feeds"; public static final String TABLE_NAME_FEEDS = "Feeds";
@ -155,7 +157,8 @@ public class PodDBAdapter {
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION + TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
+ " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL
+ " TEXT," + KEY_DOWNLOADED + " INTEGER," + KEY_POSITION + " TEXT," + KEY_DOWNLOADED + " INTEGER," + KEY_POSITION
+ " INTEGER," + KEY_SIZE + " INTEGER," + KEY_MIME_TYPE + " TEXT)"; + " INTEGER," + KEY_SIZE + " INTEGER," + KEY_MIME_TYPE + " TEXT,"
+ KEY_PLAYBACK_COMPLETION_DATE + " INTEGER)";
private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE " private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
+ TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE + TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE
@ -276,6 +279,9 @@ public class PodDBAdapter {
values.put(KEY_DOWNLOAD_URL, media.getDownload_url()); values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
values.put(KEY_DOWNLOADED, media.isDownloaded()); values.put(KEY_DOWNLOADED, media.isDownloaded());
values.put(KEY_FILE_URL, media.getFile_url()); values.put(KEY_FILE_URL, media.getFile_url());
if (media.getPlaybackCompletionDate() != null) {
values.put(KEY_PLAYBACK_COMPLETION_DATE, media.getPlaybackCompletionDate().getTime());
}
if (media.getId() == 0) { if (media.getId() == 0) {
media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values)); media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values));
} else { } else {
@ -529,34 +535,6 @@ public class PodDBAdapter {
return c; return c;
} }
/**
* Get a FeedMedia object from the Database.
*
* @param rowIndex
* DB Index of Media object
* @param owner
* FeedItem the Media object belongs to
* @return A newly created FeedMedia object
* */
public final FeedMedia getFeedMedia(final long rowIndex,
final FeedItem owner) throws SQLException {
Cursor cursor = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
new String[] { String.valueOf(rowIndex) }, null, null, null);
if (!cursor.moveToFirst()) {
throw new SQLException("No FeedMedia found at index: " + rowIndex);
}
FeedMedia media = new FeedMedia(rowIndex, owner, cursor.getInt(cursor
.getColumnIndex(KEY_DURATION)), cursor.getInt(cursor
.getColumnIndex(KEY_POSITION)), cursor.getLong(cursor
.getColumnIndex(KEY_SIZE)), cursor.getString(cursor
.getColumnIndex(KEY_MIME_TYPE)), cursor.getString(cursor
.getColumnIndex(KEY_FILE_URL)), cursor.getString(cursor
.getColumnIndex(KEY_DOWNLOAD_URL)), cursor.getInt(cursor
.getColumnIndex(KEY_DOWNLOADED)) > 0);
cursor.close();
return media;
}
public final Cursor getFeedMediaCursor(String... mediaIds) { public final Cursor getFeedMediaCursor(String... mediaIds) {
int length = mediaIds.length; int length = mediaIds.length;
if (length > IN_OPERATOR_MAXIMUM) { if (length > IN_OPERATOR_MAXIMUM) {
@ -684,6 +662,11 @@ public class PodDBAdapter {
db.execSQL("ALTER TABLE " + TABLE_NAME_SIMPLECHAPTERS db.execSQL("ALTER TABLE " + TABLE_NAME_SIMPLECHAPTERS
+ " ADD COLUMN " + KEY_CHAPTER_TYPE + " INTEGER"); + " ADD COLUMN " + KEY_CHAPTER_TYPE + " INTEGER");
} }
if (oldVersion <= 7) {
db.execSQL("ALTER TABLE " + TABLE_NAME_FEED_MEDIA
+ " ADD COLUMN " + KEY_PLAYBACK_COMPLETION_DATE
+ " INTEGER");
}
} }
} }