Search in sources :

Example 16 with FeedItem

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

the class DBReader method getQueue.

static List<FeedItem> getQueue(PodDBAdapter adapter) {
    Log.d(TAG, "getQueue()");
    Cursor itemlistCursor = adapter.getQueueCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 17 with FeedItem

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

the class DBReader method getFeedItem.

static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
    Log.d(TAG, "Loading feeditem with podcast url " + podcastUrl + " and episode url " + episodeUrl);
    FeedItem item = null;
    Cursor itemCursor = adapter.getFeedItemCursor(podcastUrl, episodeUrl);
    if (itemCursor.moveToFirst()) {
        List<FeedItem> list = extractItemlistFromCursor(adapter, itemCursor);
        if (list.size() > 0) {
            item = list.get(0);
            loadAdditionalFeedItemListData(list);
            if (item.hasChapters()) {
                loadChaptersOfFeedItem(adapter, item);
            }
        }
    }
    itemCursor.close();
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 18 with FeedItem

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

the class DBReader method extractItemlistFromCursor.

private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
    List<FeedItem> result = new ArrayList<>(cursor.getCount());
    LongList imageIds = new LongList(cursor.getCount());
    LongList itemIds = new LongList(cursor.getCount());
    if (cursor.moveToFirst()) {
        do {
            int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE);
            long imageId = cursor.getLong(indexImage);
            imageIds.add(imageId);
            FeedItem item = FeedItem.fromCursor(cursor);
            result.add(item);
            itemIds.add(item.getId());
        } while (cursor.moveToNext());
        Map<Long, FeedImage> images = getFeedImages(adapter, imageIds.toArray());
        Map<Long, FeedMedia> medias = getFeedMedia(adapter, itemIds.toArray());
        for (int i = 0; i < result.size(); i++) {
            FeedItem item = result.get(i);
            long imageId = imageIds.get(i);
            FeedImage image = images.get(imageId);
            item.setImage(image);
            FeedMedia media = medias.get(item.getId());
            item.setMedia(media);
            if (media != null) {
                media.setItem(item);
            }
        }
    }
    return result;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) LongList(de.danoeh.antennapod.core.util.LongList)

Example 19 with FeedItem

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

the class DBReader method getFeedItem.

/**
     * Loads a specific FeedItem from the database. This method should not be used for loading more
     * than one FeedItem because this method might query the database several times for each item.
     *
     * @param itemId  The ID of the FeedItem
     * @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
     * as well as chapter marks of the FeedItem will also be loaded from the database.
     */
public static FeedItem getFeedItem(final long itemId) {
    Log.d(TAG, "getFeedItem() called with: " + "itemId = [" + itemId + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    FeedItem item = getFeedItem(itemId, adapter);
    adapter.close();
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 20 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)

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