private String getArtistForTrackList() { Music song; String lastArtist = null; boolean differentArtists = false; for (Item item : items) { song = (Music) item; if (lastArtist == null) { lastArtist = song.getAlbumArtist(); continue; } if (!lastArtist.equalsIgnoreCase(song.getAlbumArtist())) { differentArtists = true; break; } } if (differentArtists || lastArtist == null || lastArtist.equals("")) { differentArtists = false; for (Item item : items) { song = (Music) item; if (lastArtist == null) { lastArtist = song.getArtist(); continue; } if (!lastArtist.equalsIgnoreCase(song.getArtist())) { differentArtists = true; break; } } if (differentArtists || lastArtist == null || lastArtist.equals("")) { return getString(R.string.variousArtists); } return lastArtist; } return lastArtist; }
@Override public void updateFromItems() { super.updateFromItems(); if (items != null) { Music song; String lastArtist = null; for (Item item : items) { song = (Music) item; if (lastArtist == null) { lastArtist = song.getArtist(); continue; } } if (lastArtist == null) { for (Item item : items) { song = (Music) item; if (lastArtist == null) { lastArtist = song.getArtist(); continue; } } } String artistName = getArtistForTrackList(); headerArtist.setText(artistName); headerInfo.setText(getHeaderInfoString()); if (coverHelper != null) { String filename = null; String path = null; if (items.size() > 0) { song = (Music) items.get(0); filename = song.getFilename(); path = song.getPath(); artistName = song.getArtist(); } coverArtProgress.setVisibility(ProgressBar.VISIBLE); coverHelper.downloadCover(artistName, album.getName(), path, filename); } else { coverArtListener.onCoverNotFound(); } } }
@Override protected ListAdapter getCustomListAdapter() { if (items != null) { Music song; boolean differentArtists = false; String lastArtist = null; for (Item item : items) { song = (Music) item; if (lastArtist == null) { lastArtist = song.getArtist(); continue; } if (!lastArtist.equalsIgnoreCase(song.getArtist())) { differentArtists = true; break; } } return new ArrayIndexerAdapter(getActivity(), new SongDataBinder(differentArtists), items); } return super.getCustomListAdapter(); }
protected void update() { MPDApplication app = (MPDApplication) getApplicationContext(); try { MPDPlaylist playlist = app.oMPDAsyncHelper.oMPD.getPlaylist(); songlist = new ArrayList<HashMap<String, Object>>(); musics = playlist.getMusicList(); int playingID = app.oMPDAsyncHelper.oMPD.getStatus().getSongId(); // The position in the songlist of the currently played song int listPlayingID = -1; for (Music m : musics) { if (m == null) { continue; } HashMap<String, Object> item = new HashMap<String, Object>(); item.put("songid", m.getSongId()); item.put("artist", m.getArtist()); item.put("title", m.getTitle()); if (m.getSongId() == playingID) { item.put("play", android.R.drawable.ic_media_play); // Lie a little. Scroll to the previous song than the one playing. That way it shows that // there are other songs before // it listPlayingID = songlist.size() - 1; } else { item.put("play", 0); } songlist.add(item); } SimpleAdapter songs = new SimpleAdapter( this, songlist, R.layout.playlist_list_item, new String[] {"play", "title", "artist"}, new int[] {R.id.picture, android.R.id.text1, android.R.id.text2}); setListAdapter(songs); // Only scroll if there is a valid song to scroll to. 0 is a valid song but does not require // scroll anyway. // Also, only scroll if it's the first update. You don't want your playlist to scroll itself // while you are looking at other // stuff. if (firstUpdate && listPlayingID > 0) setSelection(listPlayingID); firstUpdate = false; } catch (MPDServerException e) { } }
public PlaylistSong(Music m) { super( m.getAlbum(), m.getArtist(), m.getAlbumArtist(), m.getFullpath(), m.getDisc(), m.getDate(), m.getTime(), m.getParentDirectory(), m.getTitle(), m.getTotalTracks(), m.getTrack(), m.getSongId(), m.getPos(), m.getName()); }
protected void update() { // TODO: Preserve position!!! MPDApplication app = (MPDApplication) getApplicationContext(); try { if (isPlayQueue) { MPDPlaylist playlist = app.oMPDAsyncHelper.oMPD.getPlaylist(); musics = playlist.getMusicList(); } else { musics = app.oMPDAsyncHelper.oMPD.getPlaylistSongs(playlistName); } songlist = new ArrayList<HashMap<String, Object>>(); int playingID = app.oMPDAsyncHelper.oMPD.getStatus().getSongId(); int pos = null == getListView() ? -1 : getListView().getFirstVisiblePosition(); View view = null == getListView() ? null : getListView().getChildAt(0); int top = null == view ? -1 : view.getTop(); for (Music m : musics) { HashMap<String, Object> item = new HashMap<String, Object>(); item.put("songid", m.getSongId()); item.put("artist", m.getArtist()); item.put("title", m.getTitle()); item.put("marked", false); if (isPlayQueue && m.getSongId() == playingID) item.put("play", android.R.drawable.ic_media_play); else item.put("play", 0); songlist.add(item); } SimpleAdapter songs = new SimpleAdapter( this, songlist, R.layout.playlist_editlist_item, new String[] {"play", "title", "artist", "marked"}, new int[] {R.id.picture, android.R.id.text1, android.R.id.text2, R.id.removeCBox}); setListAdapter(songs); if (-1 != pos && -1 != top) { getListView().setSelectionFromTop(pos, top); } } catch (MPDServerException e) { } }