diff --git a/src/main/java/com/github/nutomic/controldlna/gui/MainActivity.java b/src/main/java/com/github/nutomic/controldlna/gui/MainActivity.java index 5894523..68d47b3 100644 --- a/src/main/java/com/github/nutomic/controldlna/gui/MainActivity.java +++ b/src/main/java/com/github/nutomic/controldlna/gui/MainActivity.java @@ -258,4 +258,13 @@ public class MainActivity extends ActionBarActivity { mRouteFragment.play(playlist, start); } + /** + * Appends a list of tracks to the current playlist + * + * @param playlist - the list of items to add + */ + public void add(List playlist) { + mRouteFragment.append(playlist); + } + } diff --git a/src/main/java/com/github/nutomic/controldlna/gui/RouteFragment.java b/src/main/java/com/github/nutomic/controldlna/gui/RouteFragment.java index ad7bf58..c8d171c 100644 --- a/src/main/java/com/github/nutomic/controldlna/gui/RouteFragment.java +++ b/src/main/java/com/github/nutomic/controldlna/gui/RouteFragment.java @@ -531,6 +531,14 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements } } + /** + * Appends the supplied playlist to the current playlist + */ + public void append(List playlist) { + mPlaylistAdapter.add(playlist); + mMediaRouterPlayService.append(playlist); + } + /** * Generates a time string in the format mm:ss from a time value in seconds. * diff --git a/src/main/java/com/github/nutomic/controldlna/gui/ServerFragment.java b/src/main/java/com/github/nutomic/controldlna/gui/ServerFragment.java index 47228a5..a09b28f 100644 --- a/src/main/java/com/github/nutomic/controldlna/gui/ServerFragment.java +++ b/src/main/java/com/github/nutomic/controldlna/gui/ServerFragment.java @@ -41,9 +41,13 @@ import android.os.IBinder; import android.os.Parcelable; import android.support.v4.app.ListFragment; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ListView; import android.widget.TextView; @@ -232,6 +236,54 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene } } + /** + * Create a suitable context menu for the currently selected item. + */ + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo info) + { + super.onCreateContextMenu(menu, v, info); + + if (getListAdapter() != mFileAdapter) + return; + + int position = ((AdapterContextMenuInfo)info).position; + if (mFileAdapter.getItem(position) instanceof Container) + return; + + menu.add(Menu.NONE, 1, Menu.NONE, "Append track to playlist"); + menu.add(Menu.NONE, 2, Menu.NONE, "Append folder playlist"); + } + + /** + * Process a context menu item selection + * @param item - the menu entry that was selected + * @return - true if the entry was processed + */ + @Override + public boolean onContextItemSelected(MenuItem item) + { + MainActivity activity = (MainActivity) getActivity(); + List playlist = new ArrayList(); + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + + switch(item.getItemId()) + { + case 1: + playlist.add((Item) mFileAdapter.getItem((info.position))); + activity.add(playlist); + return true; + case 2: + for (int i = 0; i < mFileAdapter.getCount(); i++) + if (mFileAdapter.getItem(i) instanceof Item) + playlist.add((Item) mFileAdapter.getItem(i)); + activity.add(playlist); + return true; + default: + return super.onContextItemSelected(item); + } + } + /** * Displays available servers in the ListView. */ @@ -251,6 +303,7 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene getFiles(ROOT_DIRECTORY); mEmptyView.setText(R.string.folder_list_empty); getListView().setFastScrollEnabled(true); + registerForContextMenu(getListView()); } /** diff --git a/src/main/java/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java b/src/main/java/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java index 4eae772..e7cb6aa 100644 --- a/src/main/java/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java +++ b/src/main/java/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java @@ -500,6 +500,11 @@ public class MediaRouterPlayService extends Service { return mPlaylist; } + public void append(List list) + { + mPlaylist.addAll(list); + } + public void toggleShuffleEnabled() { mShuffle = !mShuffle; }