Search in sources :

Example 26 with FeedItem

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

the class DBWriter method addQueueItemAt.

/**
 * Inserts a FeedItem in the queue at the specified index. The 'read'-attribute of the FeedItem will be set to
 * true. If the FeedItem is already in the queue, the queue will not be modified.
 *
 * @param context             A context that is used for opening a database connection.
 * @param itemId              ID of the FeedItem that should be added to the queue.
 * @param index               Destination index. Must be in range 0..queue.size()
 * @param performAutoDownload True if an auto-download process should be started after the operation
 * @throws IndexOutOfBoundsException if index < 0 || index >= queue.size()
 */
public static Future<?> addQueueItemAt(final Context context, final long itemId, final int index, final boolean performAutoDownload) {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        final List<FeedItem> queue = DBReader.getQueue(adapter);
        FeedItem item;
        if (queue != null) {
            if (!itemListContains(queue, itemId)) {
                item = DBReader.getFeedItem(itemId);
                if (item != null) {
                    queue.add(index, item);
                    adapter.setQueue(queue);
                    item.addTag(FeedItem.TAG_QUEUE);
                    EventBus.getDefault().post(QueueEvent.added(item, index));
                    EventBus.getDefault().post(FeedItemEvent.updated(item));
                    if (item.isNew()) {
                        DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
                    }
                }
            }
        }
        adapter.close();
        if (performAutoDownload) {
            DBTasks.autodownloadUndownloadedItems(context);
        }
    });
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem)

Example 27 with FeedItem

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

the class FeedItemCursorMapper method convert.

/**
 * Create a {@link FeedItem} instance from a database row (cursor).
 */
@NonNull
public static FeedItem convert(@NonNull Cursor cursor) {
    int indexId = cursor.getColumnIndexOrThrow(PodDBAdapter.SELECT_KEY_ITEM_ID);
    int indexTitle = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_TITLE);
    int indexLink = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_LINK);
    int indexPubDate = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_PUBDATE);
    int indexPaymentLink = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_PAYMENT_LINK);
    int indexFeedId = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED);
    int indexHasChapters = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_HAS_CHAPTERS);
    int indexRead = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_READ);
    int indexItemIdentifier = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_ITEM_IDENTIFIER);
    int indexAutoDownload = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_AUTO_DOWNLOAD_ATTEMPTS);
    int indexImageUrl = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_IMAGE_URL);
    long id = cursor.getInt(indexId);
    String title = cursor.getString(indexTitle);
    String link = cursor.getString(indexLink);
    Date pubDate = new Date(cursor.getLong(indexPubDate));
    String paymentLink = cursor.getString(indexPaymentLink);
    long feedId = cursor.getLong(indexFeedId);
    boolean hasChapters = cursor.getInt(indexHasChapters) > 0;
    int state = cursor.getInt(indexRead);
    String itemIdentifier = cursor.getString(indexItemIdentifier);
    long autoDownload = cursor.getLong(indexAutoDownload);
    String imageUrl = cursor.getString(indexImageUrl);
    return new FeedItem(id, title, link, pubDate, paymentLink, feedId, hasChapters, imageUrl, state, itemIdentifier, autoDownload);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Date(java.util.Date) NonNull(androidx.annotation.NonNull)

Example 28 with FeedItem

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

the class APCleanupAlgorithm method getCandidates.

@NonNull
private List<FeedItem> getCandidates() {
    List<FeedItem> candidates = new ArrayList<>();
    List<FeedItem> downloadedItems = DBReader.getDownloadedItems();
    Date mostRecentDateForDeletion = calcMostRecentDateForDeletion(new Date());
    for (FeedItem item : downloadedItems) {
        if (item.hasMedia() && item.getMedia().isDownloaded() && !item.isTagged(FeedItem.TAG_QUEUE) && item.isPlayed() && !item.isTagged(FeedItem.TAG_FAVORITE)) {
            FeedMedia media = item.getMedia();
            // to now
            if (media != null && media.getPlaybackCompletionDate() != null && media.getPlaybackCompletionDate().before(mostRecentDateForDeletion)) {
                candidates.add(item);
            }
        }
    }
    return candidates;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) NonNull(androidx.annotation.NonNull)

Example 29 with FeedItem

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

the class DownloadService method doCancel.

private void doCancel(String url) {
    Log.d(TAG, "Cancelling download with url " + url);
    for (Downloader downloader : downloads) {
        if (downloader.cancelled || !downloader.getDownloadRequest().getSource().equals(url)) {
            continue;
        }
        downloader.cancel();
        DownloadRequest request = downloader.getDownloadRequest();
        FeedItem item = getFeedItemFromId(request.getFeedfileId());
        if (item != null) {
            EventBus.getDefault().post(FeedItemEvent.updated(item));
            // undo enqueue upon cancel
            if (request.isMediaEnqueued()) {
                Log.v(TAG, "Undoing enqueue upon cancelling download");
                DBWriter.removeQueueItem(getApplicationContext(), false, item);
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem)

Example 30 with FeedItem

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

the class PodDBAdapter method storeFeedItemlist.

public void storeFeedItemlist(List<FeedItem> items) {
    try {
        db.beginTransactionNonExclusive();
        for (FeedItem item : items) {
            updateOrInsertFeedItem(item, true);
        }
        db.setTransactionSuccessful();
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        db.endTransaction();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) SQLException(android.database.SQLException)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4