* updated code to reuse existing function for moving items in the queue
* added 'move to bottom'
This commit is contained in:
parent
2d83b39c27
commit
b886c38308
|
@ -72,5 +72,10 @@
|
||||||
android:showAsAction="collapseActionView"
|
android:showAsAction="collapseActionView"
|
||||||
android:title="@string/move_to_top_label">
|
android:title="@string/move_to_top_label">
|
||||||
</item>
|
</item>
|
||||||
|
<item
|
||||||
|
android:id="@+id/move_to_bottom_item"
|
||||||
|
android:showAsAction="collapseActionView"
|
||||||
|
android:title="@string/move_to_bottom_label">
|
||||||
|
</item>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
|
@ -127,6 +127,8 @@
|
||||||
<string name="organize_queue_label">Organize queue</string>
|
<string name="organize_queue_label">Organize queue</string>
|
||||||
<string name="undo">Undo</string>
|
<string name="undo">Undo</string>
|
||||||
<string name="removed_from_queue">Item removed</string>
|
<string name="removed_from_queue">Item removed</string>
|
||||||
|
<string name="move_to_top_label">Move to top</string>
|
||||||
|
<string name="move_to_bottom_label">Move to bottom</string>
|
||||||
|
|
||||||
<!-- Flattr -->
|
<!-- Flattr -->
|
||||||
<string name="flattr_auth_label">Flattr sign-in</string>
|
<string name="flattr_auth_label">Flattr sign-in</string>
|
||||||
|
@ -250,6 +252,5 @@
|
||||||
<string name="folder_not_empty_dialog_title">Folder is not empty</string>
|
<string name="folder_not_empty_dialog_title">Folder is not empty</string>
|
||||||
<string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other files will be placed directly in this folder. Continue anyway?</string>
|
<string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other files will be placed directly in this folder. Continue anyway?</string>
|
||||||
<string name="set_to_default_folder">Choose default folder</string>
|
<string name="set_to_default_folder">Choose default folder</string>
|
||||||
<string name="move_to_top_label">Move to top</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -467,44 +467,39 @@ public class DBWriter {
|
||||||
* @param selectedItem The item to move to the top of the queue
|
* @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
|
* @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.
|
* 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) {
|
public static Future<?> moveQueueItemToTop(final Context context, final long itemId, final boolean broadcastUpdate) {
|
||||||
return dbExec.submit(new Runnable() {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void run() {
|
* Moves the specified item to the bottom of the queue.
|
||||||
final PodDBAdapter adapter = new PodDBAdapter(context);
|
*
|
||||||
adapter.open();
|
* @param context A context that is used for opening a database connection.
|
||||||
final List<FeedItem> queue = DBReader
|
* @param selectedItem The item to move to the bottom of the queue
|
||||||
.getQueue(context, adapter);
|
* @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.
|
||||||
if (queue != null) {
|
*/
|
||||||
// it seems like there should be a better way to get
|
public static Future<?> moveQueueItemToBottom(final Context context, final long itemId, final boolean broadcastUpdate) {
|
||||||
// the item we need, but iterating seems to be the
|
List<Long> queueIdList = DBReader.getQueueIDList(context);
|
||||||
// only way
|
int currentLocation = 0;
|
||||||
for (FeedItem item : queue) {
|
for (long id : queueIdList) {
|
||||||
if (item.getId() == selectedItem.getId()) {
|
if (id == itemId) {
|
||||||
if (queue.remove(item)) {
|
return moveQueueItem(context, currentLocation, queueIdList.size() - 1, true);
|
||||||
queue.add(0, item);
|
|
||||||
Log.d(TAG, "moveQueueItemToTop: moved");
|
|
||||||
adapter.setQueue(queue);
|
|
||||||
if (broadcastUpdate) {
|
|
||||||
EventDistributor.getInstance()
|
|
||||||
.sendQueueUpdateBroadcast();
|
|
||||||
}
|
}
|
||||||
} else {
|
currentLocation++;
|
||||||
Log.e(TAG, "moveQueueItemToTop: Could not move to top, no such item");
|
|
||||||
}
|
}
|
||||||
break;
|
Log.e(TAG, "moveQueueItemToBottom: item not found");
|
||||||
}
|
return null;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "moveQueueItemToTop: Could not move to top, no queue");
|
|
||||||
}
|
|
||||||
adapter.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -151,7 +151,10 @@ public class FeedItemMenuHandler {
|
||||||
true);
|
true);
|
||||||
break;
|
break;
|
||||||
case R.id.move_to_top_item:
|
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;
|
break;
|
||||||
case R.id.visit_website_item:
|
case R.id.visit_website_item:
|
||||||
Uri uri = Uri.parse(selectedItem.getLink());
|
Uri uri = Uri.parse(selectedItem.getLink());
|
||||||
|
|
Loading…
Reference in New Issue