Items in queue can now be reordered
This commit is contained in:
parent
5920c96ae7
commit
c0c9e2fed2
|
@ -1,6 +1,8 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<item type="id" name="action_bar_refresh" />
|
<item name="action_bar_refresh" type="id"/>
|
||||||
<item type="id" name="action_bar_add" />
|
<item name="action_bar_add" type="id"/>
|
||||||
|
<item name="move_up_item" type="id"/>
|
||||||
|
<item name="move_down_item" type="id"/>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -73,5 +73,7 @@
|
||||||
<string name="playback_error_unknown">Unknown Error</string>
|
<string name="playback_error_unknown">Unknown Error</string>
|
||||||
<string name="author_label">Author</string>
|
<string name="author_label">Author</string>
|
||||||
<string name="language_label">Language</string>
|
<string name="language_label">Language</string>
|
||||||
|
<string name="move_up_label">Move up</string>
|
||||||
|
<string name="move_down_label">Move down</string>
|
||||||
|
|
||||||
</resources>
|
</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) {
|
public boolean isInQueue(FeedItem item) {
|
||||||
return queue.contains(item);
|
return queue.contains(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ import de.podfetcher.storage.DownloadRequester;
|
||||||
import de.podfetcher.util.FeedItemMenuHandler;
|
import de.podfetcher.util.FeedItemMenuHandler;
|
||||||
|
|
||||||
/** Displays a list of FeedItems. */
|
/** Displays a list of FeedItems. */
|
||||||
public class ItemlistFragment extends SherlockListFragment {
|
public class ItemlistFragment extends SherlockListFragment implements
|
||||||
|
ActionMode.Callback {
|
||||||
|
|
||||||
private static final String TAG = "FeedItemlistFragment";
|
private static final String TAG = "FeedItemlistFragment";
|
||||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
||||||
|
@ -57,9 +58,12 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
public ItemlistFragment() {
|
public ItemlistFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates new ItemlistFragment which shows the Feeditems of a specific feed.
|
/**
|
||||||
* Sets 'showFeedtitle' to false
|
* Creates new ItemlistFragment which shows the Feeditems of a specific
|
||||||
* @param feedId The id of the feed to show
|
* feed. Sets 'showFeedtitle' to false
|
||||||
|
*
|
||||||
|
* @param feedId
|
||||||
|
* The id of the feed to show
|
||||||
* @return the newly created instance of an ItemlistFragment
|
* @return the newly created instance of an ItemlistFragment
|
||||||
*/
|
*/
|
||||||
public static ItemlistFragment newInstance(long feedId) {
|
public static ItemlistFragment newInstance(long feedId) {
|
||||||
|
@ -103,7 +107,6 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
getActivity().registerReceiver(contentUpdate, filter);
|
getActivity().registerReceiver(contentUpdate, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
FeedItem selection = fila.getItem(position);
|
FeedItem selection = fila.getItem(position);
|
||||||
|
@ -136,7 +139,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
|
|
||||||
selectedItem = newSelectedItem;
|
selectedItem = newSelectedItem;
|
||||||
mActionMode = getSherlockActivity().startActionMode(
|
mActionMode = getSherlockActivity().startActionMode(
|
||||||
mActionModeCallback);
|
ItemlistFragment.this);
|
||||||
} else {
|
} else {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
}
|
}
|
||||||
|
@ -150,38 +153,37 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
this.getListView().setItemsCanFocus(true);
|
this.getListView().setItemsCanFocus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
@Override
|
||||||
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
|
return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem);
|
mActionMode = null;
|
||||||
}
|
selectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
mActionMode = null;
|
mode.setTitle(selectedItem.getTitle());
|
||||||
selectedItem = null;
|
return FeedItemMenuHandler.onCreateMenu(mode.getMenuInflater(), menu);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
||||||
mode.setTitle(selectedItem.getTitle());
|
|
||||||
return FeedItemMenuHandler.onCreateMenu(mode.getMenuInflater(), menu);
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
@Override
|
boolean handled = FeedItemMenuHandler.onMenuItemClicked(
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
getSherlockActivity(), item, selectedItem);
|
||||||
FeedItemMenuHandler.onMenuItemClicked(getSherlockActivity(), item, selectedItem);
|
if (handled) {
|
||||||
fila.notifyDataSetChanged();
|
fila.notifyDataSetChanged();
|
||||||
mode.finish();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
mode.finish();
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
public FeedItemlistAdapter getListAdapter() {
|
public FeedItemlistAdapter getListAdapter() {
|
||||||
return fila;
|
return fila;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package de.podfetcher.fragment;
|
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;
|
import de.podfetcher.feed.FeedManager;
|
||||||
|
|
||||||
public class QueueFragment extends ItemlistFragment {
|
public class QueueFragment extends ItemlistFragment {
|
||||||
|
@ -8,4 +13,32 @@ public class QueueFragment extends ItemlistFragment {
|
||||||
super(FeedManager.getInstance().getQueue(), true);
|
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