Items in queue can now be reordered
This commit is contained in:
parent
5920c96ae7
commit
c0c9e2fed2
|
@ -1,6 +1,8 @@
|
|||
<resources>
|
||||
|
||||
<item type="id" name="action_bar_refresh" />
|
||||
<item type="id" name="action_bar_add" />
|
||||
<item name="action_bar_refresh" type="id"/>
|
||||
<item name="action_bar_add" type="id"/>
|
||||
<item name="move_up_item" type="id"/>
|
||||
<item name="move_down_item" type="id"/>
|
||||
|
||||
</resources>
|
|
@ -73,5 +73,7 @@
|
|||
<string name="playback_error_unknown">Unknown Error</string>
|
||||
<string name="author_label">Author</string>
|
||||
<string name="language_label">Language</string>
|
||||
<string name="move_up_label">Move up</string>
|
||||
<string name="move_down_label">Move down</string>
|
||||
|
||||
</resources>
|
|
@ -215,6 +215,20 @@ public class FeedManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void moveQueueItem(Context context, FeedItem item, int delta) {
|
||||
Log.d(TAG, "Moving queue item");
|
||||
int itemIndex = queue.indexOf(item);
|
||||
int newIndex = itemIndex + delta;
|
||||
if (newIndex >= 0 && newIndex < queue.size()) {
|
||||
FeedItem oldItem = queue.set(newIndex, item);
|
||||
queue.set(itemIndex, oldItem);
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
adapter.setQueue(queue);
|
||||
adapter.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInQueue(FeedItem item) {
|
||||
return queue.contains(item);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ import de.podfetcher.storage.DownloadRequester;
|
|||
import de.podfetcher.util.FeedItemMenuHandler;
|
||||
|
||||
/** Displays a list of FeedItems. */
|
||||
public class ItemlistFragment extends SherlockListFragment {
|
||||
public class ItemlistFragment extends SherlockListFragment implements
|
||||
ActionMode.Callback {
|
||||
|
||||
private static final String TAG = "FeedItemlistFragment";
|
||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
||||
|
@ -57,9 +58,12 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
public ItemlistFragment() {
|
||||
}
|
||||
|
||||
/** Creates new ItemlistFragment which shows the Feeditems of a specific feed.
|
||||
* Sets 'showFeedtitle' to false
|
||||
* @param feedId The id of the feed to show
|
||||
/**
|
||||
* Creates new ItemlistFragment which shows the Feeditems of a specific
|
||||
* feed. Sets 'showFeedtitle' to false
|
||||
*
|
||||
* @param feedId
|
||||
* The id of the feed to show
|
||||
* @return the newly created instance of an ItemlistFragment
|
||||
*/
|
||||
public static ItemlistFragment newInstance(long feedId) {
|
||||
|
@ -103,7 +107,6 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
getActivity().registerReceiver(contentUpdate, filter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
FeedItem selection = fila.getItem(position);
|
||||
|
@ -136,7 +139,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
|
||||
selectedItem = newSelectedItem;
|
||||
mActionMode = getSherlockActivity().startActionMode(
|
||||
mActionModeCallback);
|
||||
ItemlistFragment.this);
|
||||
} else {
|
||||
mActionMode.finish();
|
||||
}
|
||||
|
@ -150,8 +153,6 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
this.getListView().setItemsCanFocus(true);
|
||||
}
|
||||
|
||||
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem);
|
||||
|
@ -172,16 +173,17 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
FeedItemMenuHandler.onMenuItemClicked(getSherlockActivity(), item, selectedItem);
|
||||
boolean handled = FeedItemMenuHandler.onMenuItemClicked(
|
||||
getSherlockActivity(), item, selectedItem);
|
||||
if (handled) {
|
||||
fila.notifyDataSetChanged();
|
||||
mode.finish();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
mode.finish();
|
||||
return handled;
|
||||
}
|
||||
|
||||
public FeedItemlistAdapter getListAdapter() {
|
||||
return fila;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package de.podfetcher.fragment;
|
||||
|
||||
import com.actionbarsherlock.view.ActionMode;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import de.podfetcher.R;
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
|
||||
public class QueueFragment extends ItemlistFragment {
|
||||
|
@ -8,4 +13,32 @@ public class QueueFragment extends ItemlistFragment {
|
|||
super(FeedManager.getInstance().getQueue(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
super.onCreateActionMode(mode, menu);
|
||||
menu.add(Menu.NONE, R.id.move_up_item, Menu.NONE, R.string.move_up_label);
|
||||
menu.add(Menu.NONE, R.id.move_down_item, Menu.NONE, R.string.move_down_label);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
boolean handled = false;
|
||||
switch(item.getItemId()) {
|
||||
case R.id.move_up_item:
|
||||
manager.moveQueueItem(getActivity(), selectedItem, -1);
|
||||
handled = true;
|
||||
break;
|
||||
case R.id.move_down_item:
|
||||
manager.moveQueueItem(getActivity(), selectedItem, 1);
|
||||
handled = true;
|
||||
break;
|
||||
default:
|
||||
handled = super.onActionItemClicked(mode, item);
|
||||
}
|
||||
fila.notifyDataSetChanged();
|
||||
mode.finish();
|
||||
return handled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue