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>
|
|
@ -214,6 +214,20 @@ public class FeedManager {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
@ -42,7 +43,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
|
|
||||||
protected FeedItem selectedItem;
|
protected FeedItem selectedItem;
|
||||||
protected ActionMode mActionMode;
|
protected ActionMode mActionMode;
|
||||||
|
|
||||||
/** Argument for FeeditemlistAdapter */
|
/** Argument for FeeditemlistAdapter */
|
||||||
protected boolean showFeedtitle;
|
protected boolean showFeedtitle;
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -70,7 +74,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
i.setArguments(b);
|
i.setArguments(b);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -91,7 +95,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -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);
|
||||||
|
@ -114,7 +117,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
|
|
||||||
startActivity(showItem);
|
startActivity(showItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
|
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -149,39 +152,38 @@ public class ItemlistFragment extends SherlockListFragment {
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
this.getListView().setItemsCanFocus(true);
|
this.getListView().setItemsCanFocus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem);
|
return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
mActionMode = null;
|
mActionMode = null;
|
||||||
selectedItem = null;
|
selectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
mode.setTitle(selectedItem.getTitle());
|
mode.setTitle(selectedItem.getTitle());
|
||||||
return FeedItemMenuHandler.onCreateMenu(mode.getMenuInflater(), menu);
|
return FeedItemMenuHandler.onCreateMenu(mode.getMenuInflater(), menu);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
FeedItemMenuHandler.onMenuItemClicked(getSherlockActivity(), item, selectedItem);
|
boolean handled = 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