diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2013-08-14 15:12:14 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2013-08-14 15:12:14 -0400 |
commit | 07277b2fef6dcb1470ef18c55947b50ed710a7d5 (patch) | |
tree | 4f7afe548b873ce7c6ae1fdc2da8dea59f6bc659 /src/de | |
parent | 6b69f7fe28b0996d4cbaa97bf274ebc0d3c7cf34 (diff) | |
download | AntennaPod-07277b2fef6dcb1470ef18c55947b50ed710a7d5.zip |
added a 'move to top' function to DBWriter that puts the provided item at the top of the queue. There may be a way to do this while re-using the existing move function. Perhaps a helper is in order.
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/storage/DBWriter.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java index 5cdd6aee4..4b0dd9c2d 100644 --- a/src/de/danoeh/antennapod/storage/DBWriter.java +++ b/src/de/danoeh/antennapod/storage/DBWriter.java @@ -456,7 +456,41 @@ public class DBWriter { }); } + + /** + * Moves the specified item to the top of the queue. + * + * @param context A context that is used for opening a database connection. + * @param selectedItem 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 + * false if the caller wants to avoid unexpected updates of the GUI. + * @throws IndexOutOfBoundsException if (to < 0 || to >= queue.size()) || (from < 0 || from >= queue.size()) + */ + public static Future<?> moveQueueItemToTop(final Context context, final FeedItem selectedItem, final boolean broadcastUpdate) { + return dbExec.submit(new Runnable() { + + @Override + public void run() { + final PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + final List<FeedItem> queue = DBReader + .getQueue(context, adapter); + if (queue != null) { + if (queue.remove(selectedItem)) { + // it was removed, put it on the front + queue.add(0, selectedItem); + } else { + Log.e(TAG, "moveQueueItemToTop: Could not move to top, no such item"); + } + } else { + Log.e(TAG, "moveQueueItemToTop: Could not move to top, no queue"); + } + adapter.close(); + } + }); + } + /** * Changes the position of a FeedItem in the queue. * |