/** {@inheritDoc} */ @Override public void remove(final int which) { mSong = mAdapter.getItem(which); mAdapter.remove(mSong); mAdapter.notifyDataSetChanged(); MusicUtils.removeTrack(mSong.mSongId); // Build the cache mAdapter.buildCache(); }
/** {@inheritDoc} */ @Override public void drop(final int from, final int to) { mSong = mAdapter.getItem(from); mAdapter.remove(mSong); mAdapter.insert(mSong, to); mAdapter.notifyDataSetChanged(); MusicUtils.moveQueueItem(from, to); // Build the cache mAdapter.buildCache(); }
/** * @return The position of an item in the list based on the name of the currently playing song. */ private int getItemPositionBySong() { final long trackId = MusicUtils.getCurrentAudioId(); if (mAdapter == null) { return 0; } for (int i = 0; i < mAdapter.getCount(); i++) { if (mAdapter.getItem(i).mSongId == trackId) { return i; } } return 0; }
/** {@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(); // Add the data to the adpater for (final Song song : data) { mAdapter.add(song); } // Build the cache mAdapter.buildCache(); }
/** {@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; // Creat a new song mSong = mAdapter.getItem(mSelectedPosition); mSelectedId = mSong.mSongId; mSongName = mSong.mSongName; mAlbumName = mSong.mAlbumName; mArtistName = mSong.mArtistName; // Play the song next menu.add( GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next)); // 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, true); // Remove the song from the queue menu.add( GROUP_ID, FragmentMenuItems.REMOVE_FROM_QUEUE, Menu.NONE, getString(R.string.remove_from_queue)); // 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 onLoaderReset(final Loader<List<Song>> loader) { // Clear the data in the adapter mAdapter.unload(); }