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);
}
});
}
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);
}
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;
}
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);
}
}
}
}
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();
}
}
Aggregations