From 07277b2fef6dcb1470ef18c55947b50ed710a7d5 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Wed, 14 Aug 2013 15:12:14 -0400 Subject: [PATCH] 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. --- .../danoeh/antennapod/storage/DBWriter.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 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. *