Search in sources :

Example 6 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChaptersListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ChapterHolder holder, int position) {
    Chapter sc = getItem(position);
    if (sc == null) {
        holder.title.setText("Error");
        return;
    }
    holder.title.setText(sc.getTitle());
    holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
    long duration;
    if (position + 1 < media.getChapters().size()) {
        duration = media.getChapters().get(position + 1).getStart() - sc.getStart();
    } else {
        duration = media.getDuration() - sc.getStart();
    }
    holder.duration.setText(context.getString(R.string.chapter_duration, Converter.getDurationStringLocalized(context, (int) duration)));
    if (TextUtils.isEmpty(sc.getLink())) {
        holder.link.setVisibility(View.GONE);
    } else {
        holder.link.setVisibility(View.VISIBLE);
        holder.link.setText(sc.getLink());
        holder.link.setOnClickListener(v -> IntentUtils.openInBrowser(context, sc.getLink()));
    }
    holder.secondaryActionIcon.setImageResource(R.drawable.ic_play_48dp);
    holder.secondaryActionButton.setContentDescription(context.getString(R.string.play_chapter));
    holder.secondaryActionButton.setOnClickListener(v -> {
        if (callback != null) {
            callback.onPlayChapterButtonClicked(position);
        }
    });
    if (position == currentChapterIndex) {
        int playingBackGroundColor = ThemeUtils.getColorFromAttr(context, R.attr.currently_playing_background);
        holder.itemView.setBackgroundColor(playingBackGroundColor);
        float progress = ((float) (currentChapterPosition - sc.getStart())) / duration;
        progress = Math.max(progress, CircularProgressBar.MINIMUM_PERCENTAGE);
        progress = Math.min(progress, CircularProgressBar.MAXIMUM_PERCENTAGE);
        holder.progressBar.setPercentage(progress, position);
        holder.secondaryActionIcon.setImageResource(R.drawable.ic_replay);
    } else {
        holder.itemView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
        holder.progressBar.setPercentage(0, null);
    }
    if (hasImages) {
        holder.image.setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(sc.getImageUrl())) {
            Glide.with(context).clear(holder.image);
        } else {
            Glide.with(context).load(EmbeddedChapterImage.getModelFor(media, position)).apply(new RequestOptions().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).dontAnimate().transforms(new FitCenter(), new RoundedCorners((int) (4 * context.getResources().getDisplayMetrics().density)))).into(holder.image);
        }
    } else {
        holder.image.setVisibility(View.GONE);
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Chapter(de.danoeh.antennapod.model.feed.Chapter) FitCenter(com.bumptech.glide.load.resource.bitmap.FitCenter) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners)

Example 7 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChaptersFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater) {
    View root = inflater.inflate(R.layout.simple_list_fragment, null, false);
    root.findViewById(R.id.toolbar).setVisibility(View.GONE);
    RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
    progressBar = root.findViewById(R.id.progLoading);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), layoutManager.getOrientation()));
    adapter = new ChaptersListAdapter(getActivity(), pos -> {
        if (controller.getStatus() != PlayerStatus.PLAYING) {
            controller.playPause();
        }
        Chapter chapter = adapter.getItem(pos);
        controller.seekTo((int) chapter.getStart());
        updateChapterSelection(pos);
    });
    recyclerView.setAdapter(adapter);
    progressBar.setVisibility(View.VISIBLE);
    RelativeLayout.LayoutParams wrapHeight = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    recyclerView.setLayoutParams(wrapHeight);
    return root;
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Maybe(io.reactivex.Maybe) Dialog(android.app.Dialog) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) AppCompatDialogFragment(androidx.appcompat.app.AppCompatDialogFragment) EventBus(org.greenrobot.eventbus.EventBus) PlaybackPositionEvent(de.danoeh.antennapod.event.playback.PlaybackPositionEvent) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) Log(android.util.Log) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) Playable(de.danoeh.antennapod.model.playback.Playable) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) PlayerStatus(de.danoeh.antennapod.playback.base.PlayerStatus) Disposable(io.reactivex.disposables.Disposable) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) ChapterUtils(de.danoeh.antennapod.core.util.ChapterUtils) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) RelativeLayout(android.widget.RelativeLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChapterCursorMapper method convert.

/**
 * Create a {@link Chapter} instance from a database row (cursor).
 */
@NonNull
public static Chapter convert(@NonNull Cursor cursor) {
    int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
    int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
    int indexStart = cursor.getColumnIndex(PodDBAdapter.KEY_START);
    int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
    int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE_URL);
    int indexChapterType = cursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
    long id = cursor.getLong(indexId);
    String title = cursor.getString(indexTitle);
    long start = cursor.getLong(indexStart);
    String link = cursor.getString(indexLink);
    String imageUrl = cursor.getString(indexImage);
    int chapterType = cursor.getInt(indexChapterType);
    Chapter chapter;
    switch(chapterType) {
        case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
            chapter = new SimpleChapter(start, title, link, imageUrl);
            break;
        case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
            chapter = new ID3Chapter(start, title, link, imageUrl);
            break;
        case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
            chapter = new VorbisCommentChapter(start, title, link, imageUrl);
            break;
        default:
            throw new IllegalArgumentException("Unknown chapter type");
    }
    chapter.setId(id);
    return chapter;
}
Also used : SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) NonNull(androidx.annotation.NonNull)

Example 9 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class PodDBAdapter method setChapters.

private void setChapters(FeedItem item) {
    ContentValues values = new ContentValues();
    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_IMAGE_URL, chapter.getImageUrl());
        values.put(KEY_CHAPTER_TYPE, chapter.getChapterType());
        if (chapter.getId() == 0) {
            chapter.setId(db.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
        } else {
            db.update(TABLE_NAME_SIMPLECHAPTERS, values, KEY_ID + "=?", new String[] { String.valueOf(chapter.getId()) });
        }
    }
}
Also used : ContentValues(android.content.ContentValues) Chapter(de.danoeh.antennapod.model.feed.Chapter)

Example 10 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChapterUtils method readOggChaptersFromInputStream.

@NonNull
private static List<Chapter> readOggChaptersFromInputStream(InputStream input) throws VorbisCommentReaderException {
    VorbisCommentChapterReader reader = new VorbisCommentChapterReader();
    reader.readInputStream(input);
    List<Chapter> chapters = reader.getChapters();
    if (chapters == null) {
        return Collections.emptyList();
    }
    Collections.sort(chapters, new ChapterStartTimeComparator());
    enumerateEmptyChapterTitles(chapters);
    if (chaptersValid(chapters)) {
        return chapters;
    }
    return Collections.emptyList();
}
Also used : ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) Chapter(de.danoeh.antennapod.model.feed.Chapter) VorbisCommentChapterReader(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapterReader) NonNull(androidx.annotation.NonNull)

Aggregations

Chapter (de.danoeh.antennapod.model.feed.Chapter)20 CountingInputStream (org.apache.commons.io.input.CountingInputStream)7 Test (org.junit.Test)7 NonNull (androidx.annotation.NonNull)4 FrameHeader (de.danoeh.antennapod.parser.media.id3.model.FrameHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)2 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)2 SimpleChapter (de.danoeh.antennapod.parser.feed.element.SimpleChapter)2 VorbisCommentChapterReader (de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapterReader)2 Dialog (android.app.Dialog)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1