Search in sources :

Example 71 with FeedItem

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

the class DBReader method getUnreadItemsList.

/**
     * Loads a list of FeedItems whose 'read'-attribute is set to false.
     *
     * @return A list of FeedItems whose 'read'-attribute it set to false.
     */
public static List<FeedItem> getUnreadItemsList() {
    Log.d(TAG, "getUnreadItemsList() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getUnreadItemsCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    adapter.close();
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 72 with FeedItem

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

the class DBReader method getFeedItems.

static List<FeedItem> getFeedItems(PodDBAdapter adapter, final long... itemIds) {
    String[] ids = new String[itemIds.length];
    for (int i = 0; i < itemIds.length; i++) {
        long itemId = itemIds[i];
        ids[i] = Long.toString(itemId);
    }
    List<FeedItem> result;
    Cursor itemCursor = adapter.getFeedItemCursor(ids);
    if (itemCursor.moveToFirst()) {
        result = extractItemlistFromCursor(adapter, itemCursor);
        loadAdditionalFeedItemListData(result);
        for (FeedItem item : result) {
            if (item.hasChapters()) {
                loadChaptersOfFeedItem(adapter, item);
            }
        }
    } else {
        result = Collections.emptyList();
    }
    itemCursor.close();
    return result;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 73 with FeedItem

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

the class DBReader method getNewItemsList.

/**
     * Loads a list of FeedItems that are considered new.
     * Excludes items from feeds that do not have keep updated enabled.
     * @return A list of FeedItems that are considered new.
     */
public static List<FeedItem> getNewItemsList() {
    Log.d(TAG, "getNewItemsList() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getNewItemsCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    adapter.close();
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 74 with FeedItem

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

the class DBTasks method updateFeed.

/**
     * Adds new Feeds to the database or updates the old versions if they already exists. If another Feed with the same
     * identifying value already exists, this method will add new FeedItems from the new Feed to the existing Feed.
     * These FeedItems will be marked as unread with the exception of the most recent FeedItem.
     * <p/>
     * This method can update multiple feeds at once. Submitting a feed twice in the same method call can result in undefined behavior.
     * <p/>
     * This method should NOT be executed on the GUI thread.
     *
     * @param context  Used for accessing the DB.
     * @param newFeeds The new Feed objects.
     * @return The updated Feeds from the database if it already existed, or the new Feed from the parameters otherwise.
     */
public static synchronized Feed[] updateFeed(final Context context, final Feed... newFeeds) {
    List<Feed> newFeedsList = new ArrayList<>();
    List<Feed> updatedFeedsList = new ArrayList<>();
    Feed[] resultFeeds = new Feed[newFeeds.length];
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int feedIdx = 0; feedIdx < newFeeds.length; feedIdx++) {
        final Feed newFeed = newFeeds[feedIdx];
        // Look up feed in the feedslist
        final Feed savedFeed = searchFeedByIdentifyingValueOrID(adapter, newFeed);
        if (savedFeed == null) {
            Log.d(TAG, "Found no existing Feed with title " + newFeed.getTitle() + ". Adding as new one.");
            // Add a new Feed
            // all new feeds will have the most recent item marked as unplayed
            FeedItem mostRecent = newFeed.getMostRecentItem();
            if (mostRecent != null) {
                mostRecent.setNew();
            }
            newFeedsList.add(newFeed);
            resultFeeds[feedIdx] = newFeed;
        } else {
            Log.d(TAG, "Feed with title " + newFeed.getTitle() + " already exists. Syncing new with existing one.");
            Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator());
            if (newFeed.getPageNr() == savedFeed.getPageNr()) {
                if (savedFeed.compareWithOther(newFeed)) {
                    Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes");
                    savedFeed.updateFromOther(newFeed);
                }
            } else {
                Log.d(TAG, "New feed has a higher page number.");
                savedFeed.setNextPageLink(newFeed.getNextPageLink());
            }
            if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) {
                Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences");
                savedFeed.getPreferences().updateFromOther(newFeed.getPreferences());
            }
            // get the most recent date now, before we start changing the list
            FeedItem priorMostRecent = savedFeed.getMostRecentItem();
            Date priorMostRecentDate = null;
            if (priorMostRecent != null) {
                priorMostRecentDate = priorMostRecent.getPubDate();
            }
            // Look for new or updated Items
            for (int idx = 0; idx < newFeed.getItems().size(); idx++) {
                final FeedItem item = newFeed.getItems().get(idx);
                FeedItem oldItem = searchFeedItemByIdentifyingValue(savedFeed, item.getIdentifyingValue());
                if (oldItem == null) {
                    // item is new
                    item.setFeed(savedFeed);
                    item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
                    savedFeed.getItems().add(idx, item);
                    // and this is the first, hence 'new')
                    if (priorMostRecentDate == null || priorMostRecentDate.before(item.getPubDate()) || priorMostRecentDate.equals(item.getPubDate())) {
                        Log.d(TAG, "Marking item published on " + item.getPubDate() + " new, prior most recent date = " + priorMostRecentDate);
                        item.setNew();
                    }
                } else {
                    oldItem.updateFromOther(item);
                }
            }
            // update attributes
            savedFeed.setLastUpdate(newFeed.getLastUpdate());
            savedFeed.setType(newFeed.getType());
            savedFeed.setLastUpdateFailed(false);
            updatedFeedsList.add(savedFeed);
            resultFeeds[feedIdx] = savedFeed;
        }
    }
    adapter.close();
    try {
        DBWriter.addNewFeed(context, newFeedsList.toArray(new Feed[newFeedsList.size()])).get();
        DBWriter.setCompleteFeed(updatedFeedsList.toArray(new Feed[updatedFeedsList.size()])).get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    EventDistributor.getInstance().sendFeedUpdateBroadcast();
    return resultFeeds;
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 75 with FeedItem

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

the class DBWriter method moveQueueItemHelper.

/**
     * Changes the position of a FeedItem in the queue.
     * <p/>
     * This function must be run using the ExecutorService (dbExec).
     *
     * @param from            Source index. Must be in range 0..queue.size()-1.
     * @param to              Destination index. Must be in range 0..queue.size()-1.
     * @param broadcastUpdate true if this operation should trigger a QueueUpdateBroadcast. This option should be set to
     *                        false if the caller wants to avoid unexpected updates of the GUI.
     * @throws IndexOutOfBoundsException if (to < 0 || to >= queue.size()) || (from < 0 || from >= queue.size())
     */
private static void moveQueueItemHelper(final int from, final int to, final boolean broadcastUpdate) {
    final PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    final List<FeedItem> queue = DBReader.getQueue(adapter);
    if (queue != null) {
        if (from >= 0 && from < queue.size() && to >= 0 && to < queue.size()) {
            final FeedItem item = queue.remove(from);
            queue.add(to, item);
            adapter.setQueue(queue);
            if (broadcastUpdate) {
                EventBus.getDefault().post(QueueEvent.moved(item, to));
            }
        }
    } else {
        Log.e(TAG, "moveQueueItemHelper: Could not load queue");
    }
    adapter.close();
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

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