/** {@inheritDoc} */
  @Override
  public void onItemClick(
      final AdapterView<?> parent, final View view, final int position, final long id) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    if (cursor.isBeforeFirst() || cursor.isAfterLast()) {
      return;
    }
    // Get the MIME type
    final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.MIME_TYPE));

    // If it's an artist, open the artist profile
    if ("artist".equals(mimeType)) {
      NavUtils.openArtistProfile(
          this, cursor.getString(cursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)));
    } else if ("album".equals(mimeType)) {
      // If it's an album, open the album profile
      NavUtils.openAlbumProfile(
          this,
          cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ALBUM)),
          cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ARTIST)));
    } else if (position >= 0 && id >= 0) {
      // If it's a song, play it and leave
      final long[] list = new long[] {id};
      MusicUtils.playAll(this, list, 0, false);
    }

    // Close it up
    cursor.close();
    cursor = null;
    // All done
    finish();
  }
Example #2
0
 @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);
 }
Example #3
0
 @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.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 mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
         MusicUtils.addToPlaylist(getActivity(), new long[] {mSelectedId}, mPlaylistId);
         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:
         mShouldRefresh = true;
         DeleteDialog.newInstance(mSong.mSongName, new long[] {mSelectedId}, null)
             .show(getFragmentManager(), "DeleteDialog");
         return true;
       default:
         break;
     }
   }
   return super.onContextItemSelected(item);
 }