@Override public boolean onContextItemSelected(final android.view.MenuItem item) { if (item.getGroupId() == GROUP_ID) { switch (item.getItemId()) { case FragmentMenuItems.PLAY_SELECTION: MusicUtils.playAll(getActivity(), new long[] {mSelectedId}, 0, false); return true; case FragmentMenuItems.PLAY_NEXT: MusicUtils.playNext(new long[] {mSelectedId}); return true; case FragmentMenuItems.EDIT_TAGS: ApolloUtils.showTagsEditor(getActivity(), mSong); return true; case FragmentMenuItems.ADD_TO_QUEUE: MusicUtils.addToQueue(getActivity(), new long[] {mSelectedId}); return true; case FragmentMenuItems.ADD_TO_FAVORITES: FavoritesStore.getInstance(getActivity()) .addSongId(mSelectedId, mSongName, mAlbumName, mArtistName); return true; case FragmentMenuItems.NEW_PLAYLIST: CreateNewPlaylist.getInstance(new long[] {mSelectedId}) .show(getFragmentManager(), "CreatePlaylist"); return true; case FragmentMenuItems.PLAYLIST_SELECTED: final long playlistId = item.getIntent().getLongExtra("playlist", 0); MusicUtils.addToPlaylist(getActivity(), new long[] {mSelectedId}, playlistId); return true; case FragmentMenuItems.MORE_BY_ARTIST: NavUtils.openArtistProfile(getActivity(), mArtistName); return true; case FragmentMenuItems.USE_AS_RINGTONE: MusicUtils.setRingtone(getActivity(), mSelectedId); return true; case FragmentMenuItems.DELETE: DeleteDialog.newInstance(mSong.mSongName, new long[] {mSelectedId}, null) .show(getFragmentManager(), "DeleteDialog"); SystemClock.sleep(10); mAdapter.notifyDataSetChanged(); getLoaderManager().restartLoader(LOADER, null, this); return true; case FragmentMenuItems.REMOVE_FROM_PLAYLIST: mAdapter.remove(mSong); mAdapter.notifyDataSetChanged(); MusicUtils.removeFromPlaylist(getActivity(), mSong.mSongId, mPlaylistId); getLoaderManager().restartLoader(LOADER, null, this); return true; default: break; } } return super.onContextItemSelected(item); }
/** {@inheritDoc} */ @Override public void drop(final int from, final int to) { if (from == 0 || to == 0) { mAdapter.notifyDataSetChanged(); return; } final int realFrom = from - 1; final int realTo = to - 1; mSong = mAdapter.getItem(realFrom); mAdapter.remove(mSong); mAdapter.insert(mSong, realTo); mAdapter.notifyDataSetChanged(); MediaStore.Audio.Playlists.Members.moveItem( getActivity().getContentResolver(), mPlaylistId, realFrom, realTo); }
/** {@inheritDoc} */ @Override public void remove(final int which) { mSong = mAdapter.getItem(which - 1); mAdapter.remove(mSong); mAdapter.notifyDataSetChanged(); final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", mPlaylistId); getActivity() .getContentResolver() .delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + mSong.mSongId, null); }