Created abstract Chapter class to support other chapter types
This commit is contained in:
parent
81fbf3bcb6
commit
cc18f609d0
|
@ -62,7 +62,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
||||||
FeedMedia media = controller.getMedia();
|
FeedMedia media = controller.getMedia();
|
||||||
|
|
||||||
int tabcount = 2;
|
int tabcount = 2;
|
||||||
if (media != null && media.getItem().getSimpleChapters() != null) {
|
if (media != null && media.getItem().getChapters() != null) {
|
||||||
tabcount = 3;
|
tabcount = 3;
|
||||||
}
|
}
|
||||||
pagerAdapter = new MediaPlayerPagerAdapter(getSupportFragmentManager(),
|
pagerAdapter = new MediaPlayerPagerAdapter(getSupportFragmentManager(),
|
||||||
|
@ -132,7 +132,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
||||||
|
|
||||||
sCChapterFragment.setListAdapter(new SCListAdapter(
|
sCChapterFragment.setListAdapter(new SCListAdapter(
|
||||||
activity, 0, media.getItem()
|
activity, 0, media.getItem()
|
||||||
.getSimpleChapters()));
|
.getChapters()));
|
||||||
|
|
||||||
return sCChapterFragment;
|
return sCChapterFragment;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -20,15 +20,16 @@ import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.SimpleChapter;
|
import de.danoeh.antennapod.feed.SimpleChapter;
|
||||||
import de.danoeh.antennapod.util.Converter;
|
import de.danoeh.antennapod.util.Converter;
|
||||||
|
|
||||||
public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
public class SCListAdapter extends ArrayAdapter<Chapter> {
|
||||||
|
|
||||||
private static final String TAG = "SCListAdapter";
|
private static final String TAG = "SCListAdapter";
|
||||||
|
|
||||||
public SCListAdapter(Context context, int textViewResourceId,
|
public SCListAdapter(Context context, int textViewResourceId,
|
||||||
List<SimpleChapter> objects) {
|
List<Chapter> objects) {
|
||||||
super(context, textViewResourceId, objects);
|
super(context, textViewResourceId, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
Holder holder;
|
Holder holder;
|
||||||
|
|
||||||
SimpleChapter sc = getItem(position);
|
Chapter sc = getItem(position);
|
||||||
|
|
||||||
// Inflate Layout
|
// Inflate Layout
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
|
@ -114,7 +115,7 @@ public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
SimpleChapter current = sc.getItem().getCurrentChapter();
|
Chapter current = sc.getItem().getCurrentChapter();
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
if (current == sc) {
|
if (current == sc) {
|
||||||
holder.title.setTextColor(convertView.getResources().getColor(
|
holder.title.setTextColor(convertView.getResources().getColor(
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package de.danoeh.antennapod.feed;
|
||||||
|
|
||||||
|
public abstract class Chapter extends FeedComponent{
|
||||||
|
|
||||||
|
/** Defines starting point in milliseconds. */
|
||||||
|
protected long start;
|
||||||
|
protected String title;
|
||||||
|
protected FeedItem item;
|
||||||
|
protected String link;
|
||||||
|
|
||||||
|
public Chapter(long start, String title, FeedItem item, String link) {
|
||||||
|
super();
|
||||||
|
this.start = start;
|
||||||
|
this.title = title;
|
||||||
|
this.item = item;
|
||||||
|
this.link = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract int getChapterType();
|
||||||
|
|
||||||
|
public long getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeedItem getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLink() {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ public class FeedItem extends FeedComponent {
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
protected boolean read;
|
protected boolean read;
|
||||||
private String paymentLink;
|
private String paymentLink;
|
||||||
private ArrayList<SimpleChapter> simpleChapters;
|
private ArrayList<Chapter> chapters;
|
||||||
|
|
||||||
public FeedItem() {
|
public FeedItem() {
|
||||||
this.read = true;
|
this.read = true;
|
||||||
|
@ -41,11 +41,11 @@ public class FeedItem extends FeedComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the chapter that fits the position. */
|
/** Get the chapter that fits the position. */
|
||||||
public SimpleChapter getCurrentChapter(int position) {
|
public Chapter getCurrentChapter(int position) {
|
||||||
SimpleChapter current = null;
|
Chapter current = null;
|
||||||
if (simpleChapters != null) {
|
if (chapters != null) {
|
||||||
current = simpleChapters.get(0);
|
current = chapters.get(0);
|
||||||
for (SimpleChapter sc : simpleChapters) {
|
for (Chapter sc : chapters) {
|
||||||
if (sc.getStart() > position) {
|
if (sc.getStart() > position) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +57,7 @@ public class FeedItem extends FeedComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calls getCurrentChapter with current position. */
|
/** Calls getCurrentChapter with current position. */
|
||||||
public SimpleChapter getCurrentChapter() {
|
public Chapter getCurrentChapter() {
|
||||||
return getCurrentChapter(media.getPosition());
|
return getCurrentChapter(media.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +144,12 @@ public class FeedItem extends FeedComponent {
|
||||||
this.paymentLink = paymentLink;
|
this.paymentLink = paymentLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<SimpleChapter> getSimpleChapters() {
|
public ArrayList<Chapter> getChapters() {
|
||||||
return simpleChapters;
|
return chapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSimpleChapters(ArrayList<SimpleChapter> simpleChapters) {
|
public void setChapters(ArrayList<Chapter> chapters) {
|
||||||
this.simpleChapters = simpleChapters;
|
this.chapters = chapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItemIdentifier() {
|
public String getItemIdentifier() {
|
||||||
|
|
|
@ -919,19 +919,22 @@ public class FeedManager {
|
||||||
Cursor chapterCursor = adapter
|
Cursor chapterCursor = adapter
|
||||||
.getSimpleChaptersOfFeedItemCursor(item);
|
.getSimpleChaptersOfFeedItemCursor(item);
|
||||||
if (chapterCursor.moveToFirst()) {
|
if (chapterCursor.moveToFirst()) {
|
||||||
item.setSimpleChapters(new ArrayList<SimpleChapter>());
|
item.setChapters(new ArrayList<Chapter>());
|
||||||
do {
|
do {
|
||||||
SimpleChapter chapter = new SimpleChapter(
|
int chapterType = chapterCursor.getInt(PodDBAdapter.KEY_CHAPTER_TYPE_INDEX);
|
||||||
item,
|
Chapter chapter = null;
|
||||||
chapterCursor
|
long start = chapterCursor.getLong(PodDBAdapter.KEY_SC_START_INDEX);
|
||||||
.getLong(PodDBAdapter.KEY_SC_START_INDEX),
|
String title = chapterCursor.getString(PodDBAdapter.KEY_TITLE_INDEX);
|
||||||
chapterCursor
|
String link = chapterCursor.getString(PodDBAdapter.KEY_SC_LINK_INDEX);
|
||||||
.getString(PodDBAdapter.KEY_TITLE_INDEX),
|
|
||||||
chapterCursor
|
switch (chapterType) {
|
||||||
.getString(PodDBAdapter.KEY_SC_LINK_INDEX));
|
case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
|
||||||
|
chapter = new SimpleChapter(start, title, item, link);
|
||||||
|
break;
|
||||||
|
}
|
||||||
chapter.setId(chapterCursor
|
chapter.setId(chapterCursor
|
||||||
.getLong(PodDBAdapter.KEY_ID_INDEX));
|
.getLong(PodDBAdapter.KEY_ID_INDEX));
|
||||||
item.getSimpleChapters().add(chapter);
|
item.getChapters().add(chapter);
|
||||||
} while (chapterCursor.moveToNext());
|
} while (chapterCursor.moveToNext());
|
||||||
}
|
}
|
||||||
chapterCursor.close();
|
chapterCursor.close();
|
||||||
|
|
|
@ -114,8 +114,8 @@ public class FeedSearcher {
|
||||||
private static void searchFeedItemChaptersSingleFeed(String query,
|
private static void searchFeedItemChaptersSingleFeed(String query,
|
||||||
ArrayList<SearchResult> destination, Feed feed) {
|
ArrayList<SearchResult> destination, Feed feed) {
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
if (item.getSimpleChapters() != null) {
|
if (item.getChapters() != null) {
|
||||||
for (SimpleChapter sc : item.getSimpleChapters()) {
|
for (Chapter sc : item.getChapters()) {
|
||||||
SearchResult result = createSearchResult(item, query, sc
|
SearchResult result = createSearchResult(item, query, sc
|
||||||
.getTitle().toLowerCase(), VALUE_ITEM_CHAPTER);
|
.getTitle().toLowerCase(), VALUE_ITEM_CHAPTER);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package de.danoeh.antennapod.feed;
|
package de.danoeh.antennapod.feed;
|
||||||
|
|
||||||
public class SimpleChapter extends FeedComponent {
|
public class SimpleChapter extends Chapter {
|
||||||
/** Defines starting point in milliseconds. */
|
public static final int CHAPTERTYPE_SIMPLECHAPTER = 0;
|
||||||
private long start;
|
|
||||||
private String title;
|
public SimpleChapter(long start, String title, FeedItem item, String link) {
|
||||||
private FeedItem item;
|
super(start, title, item, link);
|
||||||
private String link;
|
|
||||||
|
|
||||||
public SimpleChapter(FeedItem item, long start, String title, String link) {
|
|
||||||
super();
|
|
||||||
this.item = item;
|
|
||||||
this.start = start;
|
|
||||||
this.title = title;
|
|
||||||
this.link = link;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
@ -35,4 +27,9 @@ public class SimpleChapter extends FeedComponent {
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChapterType() {
|
||||||
|
return CHAPTERTYPE_SIMPLECHAPTER;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
||||||
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.Feed;
|
import de.danoeh.antennapod.feed.Feed;
|
||||||
import de.danoeh.antennapod.feed.FeedImage;
|
import de.danoeh.antennapod.feed.FeedImage;
|
||||||
import de.danoeh.antennapod.feed.FeedItem;
|
import de.danoeh.antennapod.feed.FeedItem;
|
||||||
|
@ -25,7 +26,7 @@ import de.danoeh.antennapod.feed.SimpleChapter;
|
||||||
* */
|
* */
|
||||||
public class PodDBAdapter {
|
public class PodDBAdapter {
|
||||||
private static final String TAG = "PodDBAdapter";
|
private static final String TAG = "PodDBAdapter";
|
||||||
private static final int DATABASE_VERSION = 6;
|
private static final int DATABASE_VERSION = 7;
|
||||||
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. */
|
||||||
|
@ -72,10 +73,11 @@ public class PodDBAdapter {
|
||||||
// --------- Queue indices
|
// --------- Queue indices
|
||||||
public static final int KEY_FEEDITEM_INDEX = 1;
|
public static final int KEY_FEEDITEM_INDEX = 1;
|
||||||
public static final int KEY_QUEUE_FEED_INDEX = 2;
|
public static final int KEY_QUEUE_FEED_INDEX = 2;
|
||||||
// --------- Simplechapters indices
|
// --------- Chapters indices
|
||||||
public static final int KEY_SC_START_INDEX = 2;
|
public static final int KEY_SC_START_INDEX = 2;
|
||||||
public static final int KEY_SC_FEEDITEM_INDEX = 3;
|
public static final int KEY_SC_FEEDITEM_INDEX = 3;
|
||||||
public static final int KEY_SC_LINK_INDEX = 4;
|
public static final int KEY_SC_LINK_INDEX = 4;
|
||||||
|
public static final int KEY_CHAPTER_TYPE_INDEX = 5;
|
||||||
|
|
||||||
// Key-constants
|
// Key-constants
|
||||||
public static final String KEY_ID = "id";
|
public static final String KEY_ID = "id";
|
||||||
|
@ -113,6 +115,7 @@ public class PodDBAdapter {
|
||||||
public static final String KEY_FEED_IDENTIFIER = "feed_identifier";
|
public static final String KEY_FEED_IDENTIFIER = "feed_identifier";
|
||||||
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";
|
||||||
|
|
||||||
// Table names
|
// Table names
|
||||||
public static final String TABLE_NAME_FEEDS = "Feeds";
|
public static final String TABLE_NAME_FEEDS = "Feeds";
|
||||||
|
@ -170,7 +173,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_LINK + " TEXT," + KEY_CHAPTER_TYPE + " INTEGER)";
|
||||||
|
|
||||||
private SQLiteDatabase db;
|
private SQLiteDatabase db;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
@ -330,7 +333,7 @@ public class PodDBAdapter {
|
||||||
}
|
}
|
||||||
values.put(KEY_FEED, item.getFeed().getId());
|
values.put(KEY_FEED, item.getFeed().getId());
|
||||||
values.put(KEY_READ, item.isRead());
|
values.put(KEY_READ, item.isRead());
|
||||||
values.put(KEY_HAS_SIMPLECHAPTERS, item.getSimpleChapters() != null);
|
values.put(KEY_HAS_SIMPLECHAPTERS, item.getChapters() != null);
|
||||||
values.put(KEY_ITEM_IDENTIFIER, item.getItemIdentifier());
|
values.put(KEY_ITEM_IDENTIFIER, item.getItemIdentifier());
|
||||||
if (item.getId() == 0) {
|
if (item.getId() == 0) {
|
||||||
item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
|
item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
|
||||||
|
@ -338,7 +341,7 @@ public class PodDBAdapter {
|
||||||
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
|
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
|
||||||
new String[] { String.valueOf(item.getId()) });
|
new String[] { String.valueOf(item.getId()) });
|
||||||
}
|
}
|
||||||
if (item.getSimpleChapters() != null) {
|
if (item.getChapters() != null) {
|
||||||
setSimpleChapters(item);
|
setSimpleChapters(item);
|
||||||
}
|
}
|
||||||
return item.getId();
|
return item.getId();
|
||||||
|
@ -346,11 +349,12 @@ public class PodDBAdapter {
|
||||||
|
|
||||||
public void setSimpleChapters(FeedItem item) {
|
public void setSimpleChapters(FeedItem item) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
for (SimpleChapter chapter : item.getSimpleChapters()) {
|
for (Chapter chapter : item.getChapters()) {
|
||||||
values.put(KEY_TITLE, chapter.getTitle());
|
values.put(KEY_TITLE, chapter.getTitle());
|
||||||
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_CHAPTER_TYPE, chapter.getChapterType());
|
||||||
if (chapter.getId() == 0) {
|
if (chapter.getId() == 0) {
|
||||||
chapter.setId(db
|
chapter.setId(db
|
||||||
.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
|
.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
|
||||||
|
@ -670,6 +674,10 @@ public class PodDBAdapter {
|
||||||
db.execSQL("ALTER TABLE " + TABLE_NAME_DOWNLOAD_LOG
|
db.execSQL("ALTER TABLE " + TABLE_NAME_DOWNLOAD_LOG
|
||||||
+ " ADD COLUMN " + KEY_DOWNLOADSTATUS_TITLE + " TEXT");
|
+ " ADD COLUMN " + KEY_DOWNLOADSTATUS_TITLE + " TEXT");
|
||||||
}
|
}
|
||||||
|
if (oldVersion <= 6) {
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE_NAME_SIMPLECHAPTERS
|
||||||
|
+ " ADD COLUMN " + KEY_CHAPTER_TYPE + " INTEGER");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.SimpleChapter;
|
import de.danoeh.antennapod.feed.SimpleChapter;
|
||||||
import de.danoeh.antennapod.syndication.handler.HandlerState;
|
import de.danoeh.antennapod.syndication.handler.HandlerState;
|
||||||
import de.danoeh.antennapod.syndication.namespace.Namespace;
|
import de.danoeh.antennapod.syndication.namespace.Namespace;
|
||||||
|
@ -24,15 +25,14 @@ public class NSSimpleChapters extends Namespace {
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
public SyndElement handleElementStart(String localName, HandlerState state,
|
||||||
Attributes attributes) {
|
Attributes attributes) {
|
||||||
if (localName.equals(CHAPTERS)) {
|
if (localName.equals(CHAPTERS)) {
|
||||||
state.getCurrentItem().setSimpleChapters(
|
state.getCurrentItem().setChapters(new ArrayList<Chapter>());
|
||||||
new ArrayList<SimpleChapter>());
|
|
||||||
} else if (localName.equals(CHAPTER)) {
|
} else if (localName.equals(CHAPTER)) {
|
||||||
state.getCurrentItem()
|
state.getCurrentItem()
|
||||||
.getSimpleChapters()
|
.getChapters()
|
||||||
.add(new SimpleChapter(state.getCurrentItem(),
|
.add(new SimpleChapter(SyndDateUtils
|
||||||
SyndDateUtils.parseTimeString(attributes
|
.parseTimeString(attributes.getValue(START)),
|
||||||
.getValue(START)), attributes
|
attributes.getValue(TITLE), state.getCurrentItem(),
|
||||||
.getValue(TITLE), attributes.getValue(HREF)));
|
attributes.getValue(HREF)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SyndElement(localName, this);
|
return new SyndElement(localName, this);
|
||||||
|
|
Loading…
Reference in New Issue