summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2013-08-14 15:12:14 -0400
committerTom Hennen <tom.hennen@gmail.com>2013-08-14 15:12:14 -0400
commit07277b2fef6dcb1470ef18c55947b50ed710a7d5 (patch)
tree4f7afe548b873ce7c6ae1fdc2da8dea59f6bc659 /src/de/danoeh/antennapod/storage
parent6b69f7fe28b0996d4cbaa97bf274ebc0d3c7cf34 (diff)
downloadAntennaPod-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/danoeh/antennapod/storage')
-rw-r--r--src/de/danoeh/antennapod/storage/DBWriter.java34
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.
*