Search in sources :

Example 1 with LongList

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);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) LongList(de.danoeh.antennapod.core.util.LongList)

Example 2 with LongList

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");
        }
    });
}
Also used : LongList(de.danoeh.antennapod.core.util.LongList)

Example 3 with LongList

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);
            }
        }
    });
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ArrayList(java.util.ArrayList) QueueEvent(de.danoeh.antennapod.core.event.QueueEvent) LongList(de.danoeh.antennapod.core.util.LongList)

Example 4 with LongList

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");
        }
    });
}
Also used : LongList(de.danoeh.antennapod.core.util.LongList)

Example 5 with LongList

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;
}
Also used : LongList(de.danoeh.antennapod.core.util.LongList)

Aggregations

LongList (de.danoeh.antennapod.core.util.LongList)13 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)5 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 View (android.view.View)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1 DefaultActionButtonCallback (de.danoeh.antennapod.adapter.DefaultActionButtonCallback)1 QueueEvent (de.danoeh.antennapod.core.event.QueueEvent)1 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)1 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)1