Search in sources :

Example 1 with Chapter

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");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) ChapterReader(de.danoeh.antennapod.core.util.id3reader.ChapterReader) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader) Chapter(de.danoeh.antennapod.core.feed.Chapter) IOException(java.io.IOException) URL(java.net.URL) ID3ReaderException(de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)

Example 2 with Chapter

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();
    }
}
Also used : ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) Chapter(de.danoeh.antennapod.core.feed.Chapter) VorbisCommentReaderException(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)

Example 3 with Chapter

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();
}
Also used : SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Cursor(android.database.Cursor) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter)

Example 4 with Chapter

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;
}
Also used : Layout(android.text.Layout) LayoutInflater(android.view.LayoutInflater) Chapter(de.danoeh.antennapod.core.feed.Chapter) TextView(android.widget.TextView) Spanned(android.text.Spanned) ClickableSpan(android.text.style.ClickableSpan) Spannable(android.text.Spannable)

Example 5 with Chapter

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);
}
Also used : PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) Bundle(android.os.Bundle) ListFragment(android.support.v4.app.ListFragment) R(de.danoeh.antennapod.R) View(android.view.View) Chapter(de.danoeh.antennapod.core.feed.Chapter) ListView(android.widget.ListView) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Playable(de.danoeh.antennapod.core.util.playback.Playable) Log(android.util.Log) MediaplayerInfoContentFragment(de.danoeh.antennapod.activity.MediaplayerInfoActivity.MediaplayerInfoContentFragment) ListView(android.widget.ListView) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Chapter(de.danoeh.antennapod.core.feed.Chapter)

Aggregations

Chapter (de.danoeh.antennapod.core.feed.Chapter)12 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)3 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)3 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)3 VorbisCommentChapterReader (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)3 Cursor (android.database.Cursor)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)2 VorbisCommentChapter (de.danoeh.antennapod.core.feed.VorbisCommentChapter)2 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)2 ChapterReader (de.danoeh.antennapod.core.util.id3reader.ChapterReader)2 ID3ReaderException (de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)2 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2