use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChapterUtils method readID3ChaptersFromPlayableStreamUrl.
/**
* Uses the download URL of a media object of a feeditem to read its ID3
* chapters.
*/
public static void readID3ChaptersFromPlayableStreamUrl(Playable p) {
if (p != null && p.getStreamUrl() != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
InputStream in = null;
try {
URL url = new URL(p.getStreamUrl());
ChapterReader reader = new ChapterReader();
in = url.openStream();
reader.readInputStream(in);
List<Chapter> chapters = reader.getChapters();
if (chapters != null) {
Collections.sort(chapters, new ChapterStartTimeComparator());
processChapters(chapters, p);
if (chaptersValid(chapters)) {
p.setChapters(chapters);
Log.i(TAG, "Chapters loaded");
} else {
Log.e(TAG, "Chapter data was invalid");
}
} else {
Log.i(TAG, "ChapterReader could not find any ID3 chapters");
}
} catch (IOException | ID3ReaderException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
Log.e(TAG, "Unable to read ID3 chapters: media or download URL was null");
}
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChapterUtils method readOggChaptersFromInputStream.
private static void readOggChaptersFromInputStream(Playable p, InputStream input) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Trying to read chapters from item with title " + p.getEpisodeTitle());
try {
VorbisCommentChapterReader reader = new VorbisCommentChapterReader();
reader.readInputStream(input);
List<Chapter> chapters = reader.getChapters();
if (chapters != null) {
Collections.sort(chapters, new ChapterStartTimeComparator());
processChapters(chapters, p);
if (chaptersValid(chapters)) {
p.setChapters(chapters);
Log.i(TAG, "Chapters loaded");
} else {
Log.e(TAG, "Chapter data was invalid");
}
} else {
Log.i(TAG, "ChapterReader could not find any Ogg vorbis chapters");
}
} catch (VorbisCommentReaderException e) {
e.printStackTrace();
}
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class DBReader method loadChaptersOfFeedItem.
static void loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
Cursor chapterCursor = adapter.getSimpleChaptersOfFeedItemCursor(item);
if (chapterCursor.moveToFirst()) {
item.setChapters(new ArrayList<>());
do {
int indexType = chapterCursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
int indexStart = chapterCursor.getColumnIndex(PodDBAdapter.KEY_START);
int indexTitle = chapterCursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
int indexLink = chapterCursor.getColumnIndex(PodDBAdapter.KEY_LINK);
int chapterType = chapterCursor.getInt(indexType);
Chapter chapter = null;
long start = chapterCursor.getLong(indexStart);
String title = chapterCursor.getString(indexTitle);
String link = chapterCursor.getString(indexLink);
switch(chapterType) {
case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
chapter = new SimpleChapter(start, title, item, link);
break;
case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
chapter = new ID3Chapter(start, title, item, link);
break;
case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
chapter = new VorbisCommentChapter(start, title, item, link);
break;
}
if (chapter != null) {
int indexId = chapterCursor.getColumnIndex(PodDBAdapter.KEY_ID);
chapter.setId(chapterCursor.getLong(indexId));
item.getChapters().add(chapter);
}
} while (chapterCursor.moveToNext());
} else {
item.setChapters(null);
}
chapterCursor.close();
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChaptersListAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder;
Chapter sc = getItem(position);
// Inflate Layout
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.simplechapter_item, parent, false);
holder.view = convertView;
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
defaultTextColor = holder.title.getTextColors().getDefaultColor();
holder.start = (TextView) convertView.findViewById(R.id.txtvStart);
holder.link = (TextView) convertView.findViewById(R.id.txtvLink);
holder.butPlayChapter = (ImageButton) convertView.findViewById(R.id.butPlayChapter);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.title.setText(sc.getTitle());
holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
if (sc.getLink() != null) {
holder.link.setVisibility(View.VISIBLE);
holder.link.setText(sc.getLink());
Linkify.addLinks(holder.link, Linkify.WEB_URLS);
} else {
holder.link.setVisibility(View.GONE);
}
holder.link.setMovementMethod(null);
holder.link.setOnTouchListener((v, event) -> {
// from
// http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures
TextView widget = (TextView) v;
Object text = widget.getText();
if (text instanceof Spanned) {
Spannable buffer = (Spannable) text;
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
}
return true;
}
}
}
return false;
});
holder.butPlayChapter.setOnClickListener(v -> {
if (callback != null) {
callback.onPlayChapterButtonClicked(position);
}
});
Chapter current = ChapterUtils.getCurrentChapter(media);
if (current != null) {
if (current == sc) {
int playingBackGroundColor;
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_dark);
} else {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_light);
}
holder.view.setBackgroundColor(playingBackGroundColor);
} else {
holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
holder.title.setTextColor(defaultTextColor);
holder.start.setTextColor(defaultTextColor);
}
} else {
Log.w(TAG, "Could not find out what the current chapter is.");
}
return convertView;
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChaptersFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// add padding
final ListView lv = getListView();
lv.setClipToPadding(false);
final int vertPadding = getResources().getDimensionPixelSize(R.dimen.list_vertical_padding);
lv.setPadding(0, vertPadding, 0, vertPadding);
adapter = new ChaptersListAdapter(getActivity(), 0, pos -> {
if (controller == null) {
Log.d(TAG, "controller is null");
return;
}
Chapter chapter = (Chapter) getListAdapter().getItem(pos);
controller.seekToChapter(chapter);
});
setListAdapter(adapter);
}
Aggregations