Search in sources :

Example 51 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class FeedSearcher method performSearch.

/**
     * Search through a feed, or all feeds, for episodes that match the query in either the title,
     * chapter, or show notes. The search is first performed on titles, then chapters, and finally
     * show notes. The list of resulting episodes also describes where the first match occurred
     * (title, chapters, or show notes).
     *
     * @param context
     * @param query search query
     * @param selectedFeed feed to search, 0 to search through all feeds
     * @return list of episodes containing the query
     */
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
    final int[] values = { 2, 1, 0, 0 };
    final String[] subtitles = { context.getString(R.string.found_in_title_label), context.getString(R.string.found_in_chapters_label), context.getString(R.string.found_in_shownotes_label), context.getString(R.string.found_in_shownotes_label) };
    List<SearchResult> result = new ArrayList<>();
    List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
    tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));
    tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
    tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
    tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
    for (FutureTask<List<FeedItem>> task : tasks) {
        task.run();
    }
    try {
        for (int i = 0; i < tasks.size(); i++) {
            FutureTask<List<FeedItem>> task = tasks.get(i);
            List<FeedItem> items = task.get();
            for (FeedItem item : items) {
                if (result.isEmpty() || !isDuplicate(result, item)) {
                    result.add(new SearchResult(item, values[i], subtitles[i]));
                }
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    Collections.sort(result, new SearchResultValueComparator());
    return result;
}
Also used : SearchResultValueComparator(de.danoeh.antennapod.core.util.comparator.SearchResultValueComparator) ArrayList(java.util.ArrayList) SearchResult(de.danoeh.antennapod.core.feed.SearchResult) FutureTask(java.util.concurrent.FutureTask) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) List(java.util.List) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 52 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class PlayerWidgetService method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "Service is about to be destroyed");
    if (playbackService != null) {
        Playable playable = playbackService.getPlayable();
        if (playable != null && playable instanceof FeedMedia) {
            FeedMedia media = (FeedMedia) playable;
            if (media.hasAlmostEnded()) {
                Log.d(TAG, "smart mark as read");
                FeedItem item = media.getItem();
                DBWriter.markItemPlayed(item, FeedItem.PLAYED, false);
                DBWriter.removeQueueItem(this, item, false);
                DBWriter.addItemToPlaybackHistory(media);
                if (item.getFeed().getPreferences().getCurrentAutoDelete()) {
                    Log.d(TAG, "Delete " + media.toString());
                    DBWriter.deleteFeedMediaOfItem(this, media.getId());
                }
            }
        }
    }
    try {
        unbindService(mConnection);
    } catch (IllegalArgumentException e) {
        Log.w(TAG, "IllegalArgumentException when trying to unbind service");
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 53 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class MediaplayerActivity method checkFavorite.

private void checkFavorite() {
    Playable playable = controller.getMedia();
    if (playable != null && playable instanceof FeedMedia) {
        FeedItem feedItem = ((FeedMedia) playable).getItem();
        if (feedItem != null) {
            Observable.fromCallable(() -> DBReader.getFeedItem(feedItem.getId())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(item -> {
                boolean isFav = item.isTagged(FeedItem.TAG_FAVORITE);
                if (isFavorite != isFav) {
                    isFavorite = isFav;
                    invalidateOptionsMenu();
                }
            }, error -> Log.e(TAG, Log.getStackTraceString(error)));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 54 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method beforeShowFeedInformation.

/**
     * Called after the feed has been downloaded and parsed and before showFeedInformation is called.
     * This method is executed on a background thread
     */
private void beforeShowFeedInformation(Feed feed) {
    final HtmlToPlainText formatter = new HtmlToPlainText();
    if (Feed.TYPE_ATOM1.equals(feed.getType()) && feed.getDescription() != null) {
        // remove HTML tags from descriptions
        Log.d(TAG, "Removing HTML from feed description");
        Document feedDescription = Jsoup.parse(feed.getDescription());
        feed.setDescription(StringUtils.trim(formatter.getPlainText(feedDescription)));
    }
    Log.d(TAG, "Removing HTML from shownotes");
    if (feed.getItems() != null) {
        for (FeedItem item : feed.getItems()) {
            if (item.getDescription() != null) {
                Document itemDescription = Jsoup.parse(item.getDescription());
                item.setDescription(StringUtils.trim(formatter.getPlainText(itemDescription)));
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) Document(org.jsoup.nodes.Document)

Example 55 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class AdapterUtils method updateEpisodePlaybackProgress.

/**
     * Updates the contents of the TextView that shows the current playback position and the ProgressBar.
     */
static void updateEpisodePlaybackProgress(FeedItem item, TextView txtvPos, ProgressBar episodeProgress) {
    FeedMedia media = item.getMedia();
    episodeProgress.setVisibility(View.GONE);
    if (media == null) {
        txtvPos.setVisibility(View.GONE);
        return;
    } else {
        txtvPos.setVisibility(View.VISIBLE);
    }
    FeedItem.State state = item.getState();
    if (state == FeedItem.State.PLAYING || state == FeedItem.State.IN_PROGRESS) {
        if (media.getDuration() > 0) {
            episodeProgress.setVisibility(View.VISIBLE);
            episodeProgress.setProgress((int) (((double) media.getPosition()) / media.getDuration() * 100));
            txtvPos.setText(Converter.getDurationStringLong(media.getDuration() - media.getPosition()));
        }
    } else if (!media.isDownloaded()) {
        if (media.getSize() > 0) {
            txtvPos.setText(Converter.byteToString(media.getSize()));
        } else if (NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) {
            txtvPos.setText("{fa-spinner}");
            Iconify.addIcons(txtvPos);
            NetworkUtils.getFeedMediaSizeObservable(media).subscribe(size -> {
                if (size > 0) {
                    txtvPos.setText(Converter.byteToString(size));
                } else {
                    txtvPos.setText("");
                }
            }, error -> {
                txtvPos.setText("");
                Log.e(TAG, Log.getStackTraceString(error));
            });
        } else {
            txtvPos.setText("");
        }
    } else {
        txtvPos.setText(Converter.getDurationStringLong(media.getDuration()));
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4