/** {@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); }
@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 onLoadFinished(final Loader<List<Song>> loader, final List<Song> data) { // Check for any errors if (data.isEmpty()) { return; } // Start fresh mAdapter.unload(); // Return the correct count mAdapter.setCount(data); // Add the data to the adpater for (final Song song : data) { mAdapter.add(song); } }
/** {@inheritDoc} */ @Override public float getSpeed(final float w, final long t) { if (w > 0.8f) { return mAdapter.getCount() / 0.001f; } else { return 10.0f * w; } }
/** {@inheritDoc} */ @Override public void onCreateContextMenu( final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Get the position of the selected item final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; mSelectedPosition = info.position - 1; // Creat a new song mSong = mAdapter.getItem(mSelectedPosition); mSelectedId = mSong.mSongId; mSongName = mSong.mSongName; mAlbumName = mSong.mAlbumName; mArtistName = mSong.mArtistName; // Play the song menu.add( GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE, getString(R.string.context_menu_play_selection)); // Play next menu.add( GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next)); // Add the song to the queue menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue)); // Add the song to a playlist final SubMenu subMenu = menu.addSubMenu( GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE, R.string.add_to_playlist); MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, false); // View more content by the song artist menu.add( GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE, getString(R.string.context_menu_more_by_artist)); // Make the song a ringtone menu.add( GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE, getString(R.string.context_menu_use_as_ringtone)); // Delete the song menu.add( GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete)); }
/** {@inheritDoc} */ @Override public void onLoadFinished(final Loader<List<Song>> loader, final List<Song> data) { // Check for any errors if (data.isEmpty()) { // Set the empty text final TextView empty = (TextView) mRootView.findViewById(R.id.empty); empty.setText(getString(R.string.empty_last_added)); mListView.setEmptyView(empty); return; } // Start fresh mAdapter.unload(); // Return the correct count mAdapter.setCount(data); // Add the data to the adpater for (final Song song : data) { mAdapter.add(song); } }
/** {@inheritDoc} */ @Override public void onLoaderReset(final Loader<List<Song>> loader) { // Clear the data in the adapter mAdapter.unload(); }