summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2013-08-16 15:19:56 -0400
committerTom Hennen <tom.hennen@gmail.com>2013-08-16 15:19:56 -0400
commitb886c38308a4e7ff9ab733e52b3703962d789fbf (patch)
treeae2808d43cd5b4cd8b4fe499798d2ca52154d1bf /src/de/danoeh
parent2d83b39c27a32f51776dac14b032a72e0c3fbef8 (diff)
downloadAntennaPod-b886c38308a4e7ff9ab733e52b3703962d789fbf.zip
* updated code to reuse existing function for moving items in the queue
* added 'move to bottom'
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/storage/DBWriter.java67
-rw-r--r--src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java5
2 files changed, 35 insertions, 37 deletions
diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java
index c34f134ff..d879f3c83 100644
--- a/src/de/danoeh/antennapod/storage/DBWriter.java
+++ b/src/de/danoeh/antennapod/storage/DBWriter.java
@@ -467,44 +467,39 @@ public class DBWriter {
* @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) {
- // it seems like there should be a better way to get
- // the item we need, but iterating seems to be the
- // only way
- for (FeedItem item : queue) {
- if (item.getId() == selectedItem.getId()) {
- if (queue.remove(item)) {
- queue.add(0, item);
- Log.d(TAG, "moveQueueItemToTop: moved");
- adapter.setQueue(queue);
- if (broadcastUpdate) {
- EventDistributor.getInstance()
- .sendQueueUpdateBroadcast();
- }
- } else {
- Log.e(TAG, "moveQueueItemToTop: Could not move to top, no such item");
- }
- break;
- }
- }
- } else {
- Log.e(TAG, "moveQueueItemToTop: Could not move to top, no queue");
- }
- adapter.close();
+ public static Future<?> moveQueueItemToTop(final Context context, final long itemId, final boolean broadcastUpdate) {
+ List<Long> queueIdList = DBReader.getQueueIDList(context);
+ int currentLocation = 0;
+ for (long id : queueIdList) {
+ if (id == itemId) {
+ return moveQueueItem(context, currentLocation, 0, true);
}
- });
+ currentLocation++;
+ }
+ Log.e(TAG, "moveQueueItemToTop: item not found");
+ return null;
+ }
+
+ /**
+ * Moves the specified item to the bottom of the queue.
+ *
+ * @param context A context that is used for opening a database connection.
+ * @param selectedItem 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
+ * false if the caller wants to avoid unexpected updates of the GUI.
+ */
+ public static Future<?> moveQueueItemToBottom(final Context context, final long itemId, final boolean broadcastUpdate) {
+ List<Long> queueIdList = DBReader.getQueueIDList(context);
+ int currentLocation = 0;
+ for (long id : queueIdList) {
+ if (id == itemId) {
+ return moveQueueItem(context, currentLocation, queueIdList.size() - 1, true);
+ }
+ currentLocation++;
+ }
+ Log.e(TAG, "moveQueueItemToBottom: item not found");
+ return null;
}
/**
diff --git a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java
index 4b99b47fb..0116dbf21 100644
--- a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java
+++ b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java
@@ -151,7 +151,10 @@ public class FeedItemMenuHandler {
true);
break;
case R.id.move_to_top_item:
- DBWriter.moveQueueItemToTop(context, selectedItem, true);
+ DBWriter.moveQueueItemToTop(context, selectedItem.getId(), true);
+ break;
+ case R.id.move_to_bottom_item:
+ DBWriter.moveQueueItemToBottom(context, selectedItem.getId(), true);
break;
case R.id.visit_website_item:
Uri uri = Uri.parse(selectedItem.getLink());