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.
This commit is contained in:
parent
6b69f7fe28
commit
07277b2fef
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue