Initial database support for chapter images
This commit is contained in:
parent
cf5a876dc4
commit
5caaaa9e5a
|
@ -58,7 +58,8 @@ class DBTestUtils {
|
||||||
List<Chapter> chapters = new ArrayList<>();
|
List<Chapter> chapters = new ArrayList<>();
|
||||||
item.setChapters(chapters);
|
item.setChapters(chapters);
|
||||||
for (int k = 0; k < numChapters; k++) {
|
for (int k = 0; k < numChapters; k++) {
|
||||||
chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, item, "http://example.com"));
|
chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k,
|
||||||
|
"http://example.com", "http://example.com/image.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.getItems().add(item);
|
f.getItems().add(item);
|
||||||
|
|
|
@ -2,14 +2,18 @@ package de.danoeh.antennapod.core.feed;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class Chapter extends FeedComponent {
|
public abstract class Chapter extends FeedComponent {
|
||||||
|
|
||||||
/** Defines starting point in milliseconds. */
|
/** Defines starting point in milliseconds. */
|
||||||
long start;
|
long start;
|
||||||
String title;
|
String title;
|
||||||
String link;
|
String link;
|
||||||
|
String imageUrl;
|
||||||
|
|
||||||
Chapter() {
|
Chapter() {
|
||||||
}
|
}
|
||||||
|
@ -19,43 +23,45 @@ public abstract class Chapter extends FeedComponent {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chapter(long start, String title, FeedItem item, String link) {
|
Chapter(long start, String title, String link, String imageUrl) {
|
||||||
super();
|
super();
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.link = link;
|
this.link = link;
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Chapter fromCursor(Cursor cursor, FeedItem item) {
|
public static Chapter fromCursor(Cursor cursor) {
|
||||||
int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
|
int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
|
||||||
int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
|
int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
|
||||||
int indexStart = cursor.getColumnIndex(PodDBAdapter.KEY_START);
|
int indexStart = cursor.getColumnIndex(PodDBAdapter.KEY_START);
|
||||||
int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
|
int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
|
||||||
|
int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE_URL);
|
||||||
int indexChapterType = cursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
|
int indexChapterType = cursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
|
||||||
|
|
||||||
long id = cursor.getLong(indexId);
|
long id = cursor.getLong(indexId);
|
||||||
String title = cursor.getString(indexTitle);
|
String title = cursor.getString(indexTitle);
|
||||||
long start = cursor.getLong(indexStart);
|
long start = cursor.getLong(indexStart);
|
||||||
String link = cursor.getString(indexLink);
|
String link = cursor.getString(indexLink);
|
||||||
|
String imageUrl = cursor.getString(indexImage);
|
||||||
int chapterType = cursor.getInt(indexChapterType);
|
int chapterType = cursor.getInt(indexChapterType);
|
||||||
|
|
||||||
Chapter chapter = null;
|
Chapter chapter = null;
|
||||||
switch (chapterType) {
|
switch (chapterType) {
|
||||||
case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
|
case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
|
||||||
chapter = new SimpleChapter(start, title, item, link);
|
chapter = new SimpleChapter(start, title, link, imageUrl);
|
||||||
break;
|
break;
|
||||||
case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
|
case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
|
||||||
chapter = new ID3Chapter(start, title, item, link);
|
chapter = new ID3Chapter(start, title, link, imageUrl);
|
||||||
break;
|
break;
|
||||||
case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
|
case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
|
||||||
chapter = new VorbisCommentChapter(start, title, item, link);
|
chapter = new VorbisCommentChapter(start, title, link, imageUrl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
chapter.setId(id);
|
chapter.setId(id);
|
||||||
return chapter;
|
return chapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract int getChapterType();
|
public abstract int getChapterType();
|
||||||
|
|
||||||
public long getStart() {
|
public long getStart() {
|
||||||
|
@ -82,6 +88,14 @@ public abstract class Chapter extends FeedComponent {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHumanReadableIdentifier() {
|
public String getHumanReadableIdentifier() {
|
||||||
return title;
|
return title;
|
||||||
|
|
|
@ -14,8 +14,8 @@ public class ID3Chapter extends Chapter {
|
||||||
this.id3ID = id3ID;
|
this.id3ID = id3ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ID3Chapter(long start, String title, FeedItem item, String link) {
|
public ID3Chapter(long start, String title, String link, String imageUrl) {
|
||||||
super(start, title, item, link);
|
super(start, title, link, imageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,23 +3,12 @@ package de.danoeh.antennapod.core.feed;
|
||||||
public class SimpleChapter extends Chapter {
|
public class SimpleChapter extends Chapter {
|
||||||
public static final int CHAPTERTYPE_SIMPLECHAPTER = 0;
|
public static final int CHAPTERTYPE_SIMPLECHAPTER = 0;
|
||||||
|
|
||||||
public SimpleChapter(long start, String title, FeedItem item, String link) {
|
public SimpleChapter(long start, String title, String link, String imageUrl) {
|
||||||
super(start, title, item, link);
|
super(start, title, link, imageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChapterType() {
|
public int getChapterType() {
|
||||||
return CHAPTERTYPE_SIMPLECHAPTER;
|
return CHAPTERTYPE_SIMPLECHAPTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFromOther(SimpleChapter other) {
|
|
||||||
super.updateFromOther(other);
|
|
||||||
start = other.start;
|
|
||||||
if (other.title != null) {
|
|
||||||
title = other.title;
|
|
||||||
}
|
|
||||||
if (other.link != null) {
|
|
||||||
link = other.link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,8 @@ public class VorbisCommentChapter extends Chapter {
|
||||||
this.vorbisCommentId = vorbisCommentId;
|
this.vorbisCommentId = vorbisCommentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VorbisCommentChapter(long start, String title, FeedItem item,
|
public VorbisCommentChapter(long start, String title, String link, String imageUrl) {
|
||||||
String link) {
|
super(start, title, link, imageUrl);
|
||||||
super(start, title, item, link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,8 +54,7 @@ public class VorbisCommentChapter extends Chapter {
|
||||||
* @return the id of the chapter key or -1 if the id couldn't be read.
|
* @return the id of the chapter key or -1 if the id couldn't be read.
|
||||||
* @throws VorbisCommentReaderException
|
* @throws VorbisCommentReaderException
|
||||||
* */
|
* */
|
||||||
public static int getIDFromKey(String key)
|
public static int getIDFromKey(String key) throws VorbisCommentReaderException {
|
||||||
throws VorbisCommentReaderException {
|
|
||||||
if (key.length() >= CHAPTERXXX_LENGTH) { // >= CHAPTERxxx
|
if (key.length() >= CHAPTERXXX_LENGTH) { // >= CHAPTERxxx
|
||||||
try {
|
try {
|
||||||
String strId = key.substring(8, 10);
|
String strId = key.substring(8, 10);
|
||||||
|
@ -74,7 +72,7 @@ public class VorbisCommentChapter extends Chapter {
|
||||||
*/
|
*/
|
||||||
public static String getAttributeTypeFromKey(String key) {
|
public static String getAttributeTypeFromKey(String key) {
|
||||||
if (key.length() > CHAPTERXXX_LENGTH) {
|
if (key.length() > CHAPTERXXX_LENGTH) {
|
||||||
return key.substring(CHAPTERXXX_LENGTH, key.length());
|
return key.substring(CHAPTERXXX_LENGTH);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -84,26 +82,7 @@ public class VorbisCommentChapter extends Chapter {
|
||||||
return CHAPTERTYPE_VORBISCOMMENT_CHAPTER;
|
return CHAPTERTYPE_VORBISCOMMENT_CHAPTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLink(String link) {
|
|
||||||
this.link = link;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStart(long start) {
|
|
||||||
this.start = start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVorbisCommentId() {
|
public int getVorbisCommentId() {
|
||||||
return vorbisCommentId;
|
return vorbisCommentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVorbisCommentId(int vorbisCommentId) {
|
|
||||||
this.vorbisCommentId = vorbisCommentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -795,9 +795,7 @@ public final class DBReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
|
private static void loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
|
||||||
Cursor cursor = null;
|
try (Cursor cursor = adapter.getSimpleChaptersOfFeedItemCursor(item)) {
|
||||||
try {
|
|
||||||
cursor = adapter.getSimpleChaptersOfFeedItemCursor(item);
|
|
||||||
int chaptersCount = cursor.getCount();
|
int chaptersCount = cursor.getCount();
|
||||||
if (chaptersCount == 0) {
|
if (chaptersCount == 0) {
|
||||||
item.setChapters(null);
|
item.setChapters(null);
|
||||||
|
@ -805,14 +803,7 @@ public final class DBReader {
|
||||||
}
|
}
|
||||||
item.setChapters(new ArrayList<>(chaptersCount));
|
item.setChapters(new ArrayList<>(chaptersCount));
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
Chapter chapter = Chapter.fromCursor(cursor, item);
|
item.getChapters().add(Chapter.fromCursor(cursor));
|
||||||
if (chapter != null) {
|
|
||||||
item.getChapters().add(chapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ class DBUpgrader {
|
||||||
+ " ADD COLUMN " + PodDBAdapter.KEY_PASSWORD
|
+ " ADD COLUMN " + PodDBAdapter.KEY_PASSWORD
|
||||||
+ " TEXT");
|
+ " TEXT");
|
||||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
|
||||||
+ " ADD COLUMN " + PodDBAdapter.KEY_IMAGE
|
+ " ADD COLUMN image"
|
||||||
+ " INTEGER");
|
+ " INTEGER");
|
||||||
}
|
}
|
||||||
if (oldVersion <= 12) {
|
if (oldVersion <= 12) {
|
||||||
|
@ -280,13 +280,13 @@ class DBUpgrader {
|
||||||
+ " SELECT " + PodDBAdapter.KEY_DOWNLOAD_URL
|
+ " SELECT " + PodDBAdapter.KEY_DOWNLOAD_URL
|
||||||
+ " FROM " + PodDBAdapter.TABLE_NAME_FEED_IMAGES
|
+ " FROM " + PodDBAdapter.TABLE_NAME_FEED_IMAGES
|
||||||
+ " WHERE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES + "." + PodDBAdapter.KEY_ID
|
+ " WHERE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES + "." + PodDBAdapter.KEY_ID
|
||||||
+ " = " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_IMAGE + ")");
|
+ " = " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + ".image)");
|
||||||
|
|
||||||
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEEDS + " SET " + PodDBAdapter.KEY_IMAGE_URL + " = ("
|
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEEDS + " SET " + PodDBAdapter.KEY_IMAGE_URL + " = ("
|
||||||
+ " SELECT " + PodDBAdapter.KEY_DOWNLOAD_URL
|
+ " SELECT " + PodDBAdapter.KEY_DOWNLOAD_URL
|
||||||
+ " FROM " + PodDBAdapter.TABLE_NAME_FEED_IMAGES
|
+ " FROM " + PodDBAdapter.TABLE_NAME_FEED_IMAGES
|
||||||
+ " WHERE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES + "." + PodDBAdapter.KEY_ID
|
+ " WHERE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES + "." + PodDBAdapter.KEY_ID
|
||||||
+ " = " + PodDBAdapter.TABLE_NAME_FEEDS + "." + PodDBAdapter.KEY_IMAGE + ")");
|
+ " = " + PodDBAdapter.TABLE_NAME_FEEDS + ".image)");
|
||||||
|
|
||||||
db.execSQL("DROP TABLE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES);
|
db.execSQL("DROP TABLE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES);
|
||||||
}
|
}
|
||||||
|
@ -301,6 +301,8 @@ class DBUpgrader {
|
||||||
if (oldVersion < 1090000) {
|
if (oldVersion < 1090000) {
|
||||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
|
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
|
||||||
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_VOLUME_ADAPTION + " INTEGER DEFAULT 0");
|
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_VOLUME_ADAPTION + " INTEGER DEFAULT 0");
|
||||||
|
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_SIMPLECHAPTERS
|
||||||
|
+ " ADD COLUMN " + PodDBAdapter.KEY_IMAGE_URL + " TEXT DEFAULT NULL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@ public class PodDBAdapter {
|
||||||
public static final String KEY_POSITION = "position";
|
public static final String KEY_POSITION = "position";
|
||||||
public static final String KEY_SIZE = "filesize";
|
public static final String KEY_SIZE = "filesize";
|
||||||
public static final String KEY_MIME_TYPE = "mime_type";
|
public static final String KEY_MIME_TYPE = "mime_type";
|
||||||
public static final String KEY_IMAGE = "image";
|
|
||||||
public static final String KEY_IMAGE_URL = "image_url";
|
public static final String KEY_IMAGE_URL = "image_url";
|
||||||
public static final String KEY_FEED = "feed";
|
public static final String KEY_FEED = "feed";
|
||||||
public static final String KEY_MEDIA = "media";
|
public static final String KEY_MEDIA = "media";
|
||||||
|
@ -183,7 +182,7 @@ public class PodDBAdapter {
|
||||||
private static final String CREATE_TABLE_SIMPLECHAPTERS = "CREATE TABLE "
|
private static final String CREATE_TABLE_SIMPLECHAPTERS = "CREATE TABLE "
|
||||||
+ TABLE_NAME_SIMPLECHAPTERS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
+ TABLE_NAME_SIMPLECHAPTERS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
||||||
+ " TEXT," + KEY_START + " INTEGER," + KEY_FEEDITEM + " INTEGER,"
|
+ " TEXT," + KEY_START + " INTEGER," + KEY_FEEDITEM + " INTEGER,"
|
||||||
+ KEY_LINK + " TEXT," + KEY_CHAPTER_TYPE + " INTEGER)";
|
+ KEY_LINK + " TEXT," + KEY_IMAGE_URL + " TEXT," + KEY_CHAPTER_TYPE + " INTEGER)";
|
||||||
|
|
||||||
// SQL Statements for creating indexes
|
// SQL Statements for creating indexes
|
||||||
static final String CREATE_INDEX_FEEDITEMS_FEED = "CREATE INDEX "
|
static final String CREATE_INDEX_FEEDITEMS_FEED = "CREATE INDEX "
|
||||||
|
@ -674,6 +673,7 @@ public class PodDBAdapter {
|
||||||
values.put(KEY_START, chapter.getStart());
|
values.put(KEY_START, chapter.getStart());
|
||||||
values.put(KEY_FEEDITEM, item.getId());
|
values.put(KEY_FEEDITEM, item.getId());
|
||||||
values.put(KEY_LINK, chapter.getLink());
|
values.put(KEY_LINK, chapter.getLink());
|
||||||
|
values.put(KEY_IMAGE_URL, chapter.getImageUrl());
|
||||||
values.put(KEY_CHAPTER_TYPE, chapter.getChapterType());
|
values.put(KEY_CHAPTER_TYPE, chapter.getChapterType());
|
||||||
if (chapter.getId() == 0) {
|
if (chapter.getId() == 0) {
|
||||||
chapter.setId(db.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
|
chapter.setId(db.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
|
||||||
|
|
|
@ -22,10 +22,10 @@ public class NSSimpleChapters extends Namespace {
|
||||||
private static final String START = "start";
|
private static final String START = "start";
|
||||||
private static final String TITLE = "title";
|
private static final String TITLE = "title";
|
||||||
private static final String HREF = "href";
|
private static final String HREF = "href";
|
||||||
|
private static final String IMAGE = "image";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
|
||||||
Attributes attributes) {
|
|
||||||
FeedItem currentItem = state.getCurrentItem();
|
FeedItem currentItem = state.getCurrentItem();
|
||||||
if (currentItem != null) {
|
if (currentItem != null) {
|
||||||
if (localName.equals(CHAPTERS)) {
|
if (localName.equals(CHAPTERS)) {
|
||||||
|
@ -35,7 +35,8 @@ public class NSSimpleChapters extends Namespace {
|
||||||
long start = DateUtils.parseTimeString(attributes.getValue(START));
|
long start = DateUtils.parseTimeString(attributes.getValue(START));
|
||||||
String title = attributes.getValue(TITLE);
|
String title = attributes.getValue(TITLE);
|
||||||
String link = attributes.getValue(HREF);
|
String link = attributes.getValue(HREF);
|
||||||
SimpleChapter chapter = new SimpleChapter(start, title, currentItem, link);
|
String imageUrl = attributes.getValue(IMAGE);
|
||||||
|
SimpleChapter chapter = new SimpleChapter(start, title, link, imageUrl);
|
||||||
currentItem.getChapters().add(chapter);
|
currentItem.getChapters().add(chapter);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "Unable to read chapter", e);
|
Log.e(TAG, "Unable to read chapter", e);
|
||||||
|
|
Loading…
Reference in New Issue