use of de.danoeh.antennapod.core.util.LongList in project AntennaPod by AntennaPod.
the class DBReader method loadTagsOfFeedItemList.
public static void loadTagsOfFeedItemList(List<FeedItem> items) {
LongList favoriteIds = getFavoriteIDList();
LongList queueIds = getQueueIDList();
for (FeedItem item : items) {
if (favoriteIds.contains(item.getId())) {
item.addTag(FeedItem.TAG_FAVORITE);
}
if (queueIds.contains(item.getId())) {
item.addTag(FeedItem.TAG_QUEUE);
}
}
}
use of de.danoeh.antennapod.core.util.LongList in project AntennaPod by AntennaPod.
the class DBWriter method moveQueueItemToBottom.
/**
* Moves the specified item to the bottom of the queue.
* @param itemId The item to move to the bottom of the queue
* @param broadcastUpdate true if this operation should trigger a QueueUpdateBroadcast. This option should be set to
*/
public static Future<?> moveQueueItemToBottom(final long itemId, final boolean broadcastUpdate) {
return dbExec.submit(() -> {
LongList queueIdList = DBReader.getQueueIDList();
int index = queueIdList.indexOf(itemId);
if (index >= 0) {
moveQueueItemHelper(index, queueIdList.size() - 1, broadcastUpdate);
} else {
Log.e(TAG, "moveQueueItemToBottom: item not found");
}
});
}
use of de.danoeh.antennapod.core.util.LongList in project AntennaPod by AntennaPod.
the class DBWriter method addQueueItem.
/**
* Appends FeedItem objects to the end of the queue. The 'read'-attribute of all items will be set to true.
* If a FeedItem is already in the queue, the FeedItem will not change its position in the queue.
*
* @param context A context that is used for opening a database connection.
* @param performAutoDownload true if an auto-download process should be started after the operation.
* @param itemIds IDs of the FeedItem objects that should be added to the queue.
*/
public static Future<?> addQueueItem(final Context context, final boolean performAutoDownload, final long... itemIds) {
return dbExec.submit(() -> {
if (itemIds.length > 0) {
final PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
final List<FeedItem> queue = DBReader.getQueue(adapter);
if (queue != null) {
boolean queueModified = false;
LongList markAsUnplayedIds = new LongList();
List<QueueEvent> events = new ArrayList<>();
List<FeedItem> updatedItems = new ArrayList<>();
for (int i = 0; i < itemIds.length; i++) {
if (!itemListContains(queue, itemIds[i])) {
final FeedItem item = DBReader.getFeedItem(itemIds[i]);
if (item != null) {
// add item to either front ot back of queue
boolean addToFront = UserPreferences.enqueueAtFront();
if (addToFront) {
queue.add(0 + i, item);
events.add(QueueEvent.added(item, 0 + i));
} else {
queue.add(item);
events.add(QueueEvent.added(item, queue.size() - 1));
}
item.addTag(FeedItem.TAG_QUEUE);
updatedItems.add(item);
queueModified = true;
if (item.isNew()) {
markAsUnplayedIds.add(item.getId());
}
}
}
}
if (queueModified) {
adapter.setQueue(queue);
for (QueueEvent event : events) {
EventBus.getDefault().post(event);
}
EventBus.getDefault().post(FeedItemEvent.updated(updatedItems));
if (markAsUnplayedIds.size() > 0) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, markAsUnplayedIds.toArray());
}
}
}
adapter.close();
if (performAutoDownload) {
DBTasks.autodownloadUndownloadedItems(context);
}
}
});
}
use of de.danoeh.antennapod.core.util.LongList in project AntennaPod by AntennaPod.
the class DBWriter method moveQueueItemToTop.
/**
* Moves the specified item to the top of the queue.
* @param itemId The item to move to the top of the queue
* @param broadcastUpdate true if this operation should trigger a QueueUpdateBroadcast. This option should be set to
*/
public static Future<?> moveQueueItemToTop(final long itemId, final boolean broadcastUpdate) {
return dbExec.submit(() -> {
LongList queueIdList = DBReader.getQueueIDList();
int index = queueIdList.indexOf(itemId);
if (index >= 0) {
moveQueueItemHelper(index, 0, broadcastUpdate);
} else {
Log.e(TAG, "moveQueueItemToTop: item not found");
}
});
}
use of de.danoeh.antennapod.core.util.LongList in project AntennaPod by AntennaPod.
the class DBReader method getQueueIDList.
/**
* Loads the IDs of the FeedItems in the queue. This method should be preferred over
* {@link #getQueue()} if the FeedItems of the queue are not needed.
*
* @return A list of IDs sorted by the same order as the queue. The caller can wrap the returned
* list in a {@link de.danoeh.antennapod.core.util.QueueAccess} object for easier access to the queue's properties.
*/
public static LongList getQueueIDList() {
Log.d(TAG, "getQueueIDList() called");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
LongList result = getQueueIDList(adapter);
adapter.close();
return result;
}
Aggregations