/** * Handles clicks on the context menu. * * <p>{@inheritDoc} * * @param item * @return */ @Override public boolean onContextItemSelected(MenuItem item) { Song song = getCurrentSong(); if (song == null || song.isRemote()) { return false; } // Note: Very similar to code in SongView:doItemContext(). Refactor? switch (item.getItemId()) { case R.id.download: mActivity.downloadItem(song); return true; case R.id.view_this_album: SongListActivity.show(getActivity(), song.getAlbum()); return true; case R.id.view_albums_by_song: AlbumListActivity.show(getActivity(), new Artist(song.getArtistId(), song.getArtist())); return true; case R.id.view_songs_by_artist: SongListActivity.show(getActivity(), new Artist(song.getArtistId(), song.getArtist())); return true; default: throw new IllegalStateException("Unknown menu ID."); } }
/** * Update the UI when the song changes, either because the track has changed, or the active player * has changed. * * @param playerState the player state for the song. */ @UiThread private void updateSongInfo(@NonNull PlayerState playerState) { updateTimeDisplayTo(playerState.getCurrentTimeSecond(), playerState.getCurrentSongDuration()); Song song = playerState.getCurrentSong(); if (song != null) { albumText.setText(song.getAlbumName()); trackText.setText(song.getName()); if (mFullHeightLayout) { artistText.setText(song.getArtist()); totalTime.setText(Util.formatElapsedTime(song.getDuration())); if (song.isRemote()) { if (song.getButtons().length() == 0) { nextButton.setEnabled(false); Util.setAlpha(nextButton, 0.25f); } else { // TODO: figure out how to parse the buttons HASH; // for now just assume the next button is enabled nextButton.setEnabled(true); Util.setAlpha(nextButton, 1.0f); } prevButton.setEnabled(false); Util.setAlpha(prevButton, 0.25f); btnContextMenu.setVisibility(View.GONE); } else { nextButton.setEnabled(true); Util.setAlpha(nextButton, 1.0f); prevButton.setEnabled(true); Util.setAlpha(prevButton, 1.0f); btnContextMenu.setVisibility(View.VISIBLE); } } } else { albumText.setText(""); trackText.setText(""); if (mFullHeightLayout) { artistText.setText(""); btnContextMenu.setVisibility(View.GONE); } } if (song == null || !song.hasArtwork()) { if (mFullHeightLayout) { albumArt.setImageResource( song != null && song.isRemote() ? R.drawable.icon_iradio_noart_fullscreen : R.drawable.icon_album_noart_fullscreen); } else { albumArt.setImageResource( song != null && song.isRemote() ? R.drawable.icon_iradio_noart : R.drawable.icon_album_noart); } return; } ImageFetcher.getInstance(mActivity).loadImage(song.getArtworkUrl(), albumArt); }