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