Add FancyMenu to ShowQueueFragment
This commit is contained in:
parent
893e96cbd4
commit
5e39f5ceec
@ -622,6 +622,7 @@ public class LibraryActivity
|
|||||||
private static final int CTX_MENU_PLUGINS = 11;
|
private static final int CTX_MENU_PLUGINS = 11;
|
||||||
private static final int CTX_MENU_SHOW_DETAILS = 12;
|
private static final int CTX_MENU_SHOW_DETAILS = 12;
|
||||||
private static final int CTX_MENU_ADD_TO_HOMESCREEN = 13;
|
private static final int CTX_MENU_ADD_TO_HOMESCREEN = 13;
|
||||||
|
private static final int CTX_MENU_ADD_TO_PLAYLIST = 14;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a context menu for an adapter row.
|
* Creates a context menu for an adapter row.
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package ch.blinkenlights.android.vanilla;
|
package ch.blinkenlights.android.vanilla;
|
||||||
|
|
||||||
|
import ch.blinkenlights.android.vanilla.ui.FancyMenu;
|
||||||
|
import ch.blinkenlights.android.vanilla.ui.FancyMenuItem;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -34,10 +37,11 @@ import com.mobeta.android.dslv.DragSortListView;
|
|||||||
|
|
||||||
public class ShowQueueFragment extends Fragment
|
public class ShowQueueFragment extends Fragment
|
||||||
implements TimelineCallback,
|
implements TimelineCallback,
|
||||||
AdapterView.OnItemClickListener,
|
AdapterView.OnItemClickListener,
|
||||||
DragSortListView.DropListener,
|
AdapterView.OnItemLongClickListener,
|
||||||
DragSortListView.RemoveListener,
|
DragSortListView.DropListener,
|
||||||
MenuItem.OnMenuItemClickListener
|
DragSortListView.RemoveListener,
|
||||||
|
FancyMenu.Callback
|
||||||
{
|
{
|
||||||
|
|
||||||
private DragSortListView mListView;
|
private DragSortListView mListView;
|
||||||
@ -57,7 +61,7 @@ public class ShowQueueFragment extends Fragment
|
|||||||
mListView.setDropListener(this);
|
mListView.setDropListener(this);
|
||||||
mListView.setRemoveListener(this);
|
mListView.setRemoveListener(this);
|
||||||
mListView.setOnItemClickListener(this);
|
mListView.setOnItemClickListener(this);
|
||||||
mListView.setOnCreateContextMenuListener(this);
|
mListView.setOnItemLongClickListener(this);
|
||||||
|
|
||||||
PlaybackService.addTimelineCallback(this);
|
PlaybackService.addTimelineCallback(this);
|
||||||
return view;
|
return view;
|
||||||
@ -83,42 +87,51 @@ public class ShowQueueFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final static int CTX_MENU_PLAY = 100;
|
private final static int CTX_MENU_PLAY = 100;
|
||||||
private final static int CTX_MENU_ENQUEUE_ALBUM = 101;
|
private final static int CTX_MENU_ENQUEUE_ALBUM = 101;
|
||||||
private final static int CTX_MENU_ENQUEUE_ARTIST = 102;
|
private final static int CTX_MENU_ENQUEUE_ARTIST = 102;
|
||||||
private final static int CTX_MENU_ENQUEUE_GENRE = 103;
|
private final static int CTX_MENU_ENQUEUE_GENRE = 103;
|
||||||
private final static int CTX_MENU_REMOVE = 104;
|
private final static int CTX_MENU_REMOVE = 104;
|
||||||
private final static int CTX_MENU_SHOW_DETAILS = 105;
|
private final static int CTX_MENU_SHOW_DETAILS = 105;
|
||||||
|
private final static int CTX_MENU_ADD_TO_PLAYLIST = 106;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by Android on long press. Builds the long press context menu.
|
* Called on long-click on a adapeter row
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View listView, ContextMenu.ContextMenuInfo absInfo) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
|
||||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)absInfo;
|
Song song = playbackService().getSongByQueuePosition(pos);
|
||||||
Song song = playbackService().getSongByQueuePosition(info.position);
|
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra("id", song.id);
|
intent.putExtra("id", song.id);
|
||||||
intent.putExtra("type", MediaUtils.TYPE_SONG);
|
intent.putExtra("type", MediaUtils.TYPE_SONG);
|
||||||
intent.putExtra("position", info.position);
|
intent.putExtra("position", pos);
|
||||||
menu.setHeaderTitle(song.title);
|
|
||||||
menu.add(0, CTX_MENU_PLAY, 0, R.string.play).setIntent(intent).setOnMenuItemClickListener(this);
|
FancyMenu fm = new FancyMenu(getContext(), this);
|
||||||
menu.add(0, CTX_MENU_ENQUEUE_ALBUM, 0, R.string.enqueue_current_album).setIntent(intent).setOnMenuItemClickListener(this);
|
fm.show(getFragmentManager(), "ShowQueueFragmentContext");
|
||||||
menu.add(0, CTX_MENU_ENQUEUE_ARTIST, 0, R.string.enqueue_current_artist).setIntent(intent).setOnMenuItemClickListener(this);
|
fm.setHeaderTitle(song.title);
|
||||||
menu.add(0, CTX_MENU_ENQUEUE_GENRE, 0, R.string.enqueue_current_genre).setIntent(intent).setOnMenuItemClickListener(this);
|
|
||||||
menu.addSubMenu(0, SlidingPlaybackActivity.CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(intent); // handled by fragment parent
|
fm.add(CTX_MENU_PLAY, 0, R.drawable.menu_play, R.string.play).setIntent(intent);
|
||||||
menu.add(0, CTX_MENU_SHOW_DETAILS, 0, R.string.details).setIntent(intent).setOnMenuItemClickListener(this);
|
|
||||||
menu.add(0, CTX_MENU_REMOVE, 0, R.string.remove).setIntent(intent).setOnMenuItemClickListener(this);
|
fm.addSpacer(0);
|
||||||
|
fm.add(CTX_MENU_ENQUEUE_ALBUM, 0, R.drawable.menu_enqueue, R.string.enqueue_current_album).setIntent(intent);
|
||||||
|
fm.add(CTX_MENU_ENQUEUE_ARTIST, 0, R.drawable.menu_enqueue, R.string.enqueue_current_artist).setIntent(intent);
|
||||||
|
fm.add(CTX_MENU_ENQUEUE_GENRE, 0, R.drawable.menu_enqueue, R.string.enqueue_current_genre).setIntent(intent);
|
||||||
|
fm.add(CTX_MENU_ADD_TO_PLAYLIST, 0, R.drawable.menu_add_to_playlist, R.string.add_to_playlist).setIntent(intent);
|
||||||
|
|
||||||
|
fm.addSpacer(0);
|
||||||
|
fm.add(CTX_MENU_SHOW_DETAILS, 0, R.drawable.menu_details, R.string.details).setIntent(intent);
|
||||||
|
fm.add(CTX_MENU_REMOVE, 90, R.drawable.menu_remove, R.string.remove).setIntent(intent);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by Android after the User selected a MenuItem.
|
* Callback for FancyMenu clicks.
|
||||||
*
|
*
|
||||||
* @param item The selected menu item.
|
* @param item The selected menu item.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onFancyItemSelected(FancyMenuItem item) {
|
||||||
Intent intent = item.getIntent();
|
Intent intent = item.getIntent();
|
||||||
int pos = intent.getIntExtra("position", -1);
|
int pos = intent.getIntExtra("position", -1);
|
||||||
|
|
||||||
@ -143,6 +156,11 @@ public class ShowQueueFragment extends Fragment
|
|||||||
case CTX_MENU_REMOVE:
|
case CTX_MENU_REMOVE:
|
||||||
remove(pos);
|
remove(pos);
|
||||||
break;
|
break;
|
||||||
|
case CTX_MENU_ADD_TO_PLAYLIST:
|
||||||
|
PlaylistDialog.Callback callback = ((PlaylistDialog.Callback)getActivity());
|
||||||
|
PlaylistDialog dialog = PlaylistDialog.newInstance(callback, intent, null);
|
||||||
|
dialog.show(getFragmentManager(), "PlaylistDialog");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unhandled menu id received!");
|
throw new IllegalArgumentException("Unhandled menu id received!");
|
||||||
// we could actually dispatch this to the hosting activity, but we do not need this for now.
|
// we could actually dispatch this to the hosting activity, but we do not need this for now.
|
||||||
|
@ -154,26 +154,6 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static final int CTX_MENU_ADD_TO_PLAYLIST = 300;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
if (item.getGroupId() != 0)
|
|
||||||
return super.onContextItemSelected(item);
|
|
||||||
|
|
||||||
final Intent intent = item.getIntent();
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case CTX_MENU_ADD_TO_PLAYLIST: {
|
|
||||||
PlaylistDialog dialog = PlaylistDialog.newInstance(this, intent, null);
|
|
||||||
dialog.show(getFragmentManager(), "PlaylistDialog");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Unhandled item id");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by PlaylistDialog.Callback to append data to
|
* Called by PlaylistDialog.Callback to append data to
|
||||||
* a playlist
|
* a playlist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user