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);
itemsCopy.remove(item);
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(
mediaId,
item,
@ -1092,7 +1100,8 @@ public class FeedManager {
cursor.getString(PodDBAdapter.KEY_MIME_TYPE_INDEX),
cursor.getString(PodDBAdapter.KEY_FILE_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());

View File

@ -1,5 +1,7 @@
package de.danoeh.antennapod.feed;
import java.util.Date;
public class FeedMedia extends FeedFile {
public static final int FEEDFILETYPE_FEEDMEDIA = 2;
@ -9,6 +11,7 @@ public class FeedMedia extends FeedFile {
private long size; // File size in Byte
private String mime_type;
private FeedItem item;
private Date playbackCompletionDate;
public FeedMedia(FeedItem i, String download_url, long size,
String mime_type) {
@ -20,7 +23,7 @@ public class FeedMedia extends FeedFile {
public FeedMedia(long id, FeedItem item, int duration, int position,
long size, String mime_type, String file_url, String download_url,
boolean downloaded) {
boolean downloaded, Date playbackCompletionDate) {
super(file_url, download_url, downloaded);
this.id = id;
this.item = item;
@ -28,6 +31,7 @@ public class FeedMedia extends FeedFile {
this.position = position;
this.size = size;
this.mime_type = mime_type;
this.playbackCompletionDate = playbackCompletionDate;
}
public FeedMedia(long id, FeedItem item) {
@ -106,4 +110,12 @@ public class FeedMedia extends FeedFile {
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 {
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";
/** 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_SIZE_INDEX = 6;
public static final int KEY_MIME_TYPE_INDEX = 7;
public static final int KEY_PLAYBACK_COMPLETION_DATE_INDEX = 8;
// --------- Download log indices
public static final int KEY_FEEDFILE_INDEX = 1;
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_DOWNLOADSTATUS_TITLE = "title";
public static final String KEY_CHAPTER_TYPE = "type";
public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
@ -155,7 +157,8 @@ public class PodDBAdapter {
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
+ " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL
+ " 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 "
+ 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_DOWNLOADED, media.isDownloaded());
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) {
media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values));
} else {
@ -529,34 +535,6 @@ public class PodDBAdapter {
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) {
int length = mediaIds.length;
if (length > IN_OPERATOR_MAXIMUM) {
@ -684,6 +662,11 @@ public class PodDBAdapter {
db.execSQL("ALTER TABLE " + TABLE_NAME_SIMPLECHAPTERS
+ " ADD COLUMN " + KEY_CHAPTER_TYPE + " INTEGER");
}
if (oldVersion <= 7) {
db.execSQL("ALTER TABLE " + TABLE_NAME_FEED_MEDIA
+ " ADD COLUMN " + KEY_PLAYBACK_COMPLETION_DATE
+ " INTEGER");
}
}
}