use of de.danoeh.antennapod.core.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.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;
}
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;
}
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;
}
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;
}
Aggregations