use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist in project malp by gateship-one.
the class SavedPlaylistsFragment method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mCallback) {
MPDPlaylist playlist = (MPDPlaylist) mPlaylistAdapter.getItem(position);
mCallback.openPlaylist(playlist.getPath());
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist in project malp by gateship-one.
the class MPDResponseParser method parseMPDTracks.
/**
* Parses the response of mpd on requests that return track items. This is also used
* for MPD file, directory and playlist responses. This allows the GUI to develop
* one adapter for all three types. Also MPD mixes them when requesting directory listings.
* <p/>
* It will return a list of MPDFileEntry objects which is a parent class for (MPDTrack, MPDPlaylist,
* MPDDirectory) you can use instanceof to check which type you got.
*
* @return List of MPDFileEntry objects
* @throws MPDException if an error from MPD was received during reading
*/
static ArrayList<MPDFileEntry> parseMPDTracks(final MPDConnection connection) throws MPDException {
ArrayList<MPDFileEntry> trackList = new ArrayList<>();
if (!connection.isConnected()) {
return trackList;
}
/* Temporary file entry (added to list later) */
MPDFileEntry tempFileEntry = null;
/* Response line from MPD */
String response = connection.readLine();
while (response != null && !response.startsWith("OK")) {
/* This if block will just check all the different response possible by MPDs file/dir/playlist response */
if (response.startsWith(MPDResponses.MPD_RESPONSE_FILE)) {
if (null != tempFileEntry) {
trackList.add(tempFileEntry);
}
tempFileEntry = new MPDTrack(response.substring(MPDResponses.MPD_RESPONSE_FILE.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_PLAYLIST)) {
if (null != tempFileEntry) {
trackList.add(tempFileEntry);
}
tempFileEntry = new MPDPlaylist(response.substring(MPDResponses.MPD_RESPONSE_PLAYLIST.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_DIRECTORY)) {
if (null != tempFileEntry) {
trackList.add(tempFileEntry);
}
tempFileEntry = new MPDDirectory(response.substring(MPDResponses.MPD_RESPONSE_DIRECTORY.length()));
}
// Currently parsing a file (check its properties)
if (tempFileEntry instanceof MPDTrack) {
if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_TITLE)) {
((MPDTrack) tempFileEntry).setTrackTitle(response.substring(MPDResponses.MPD_RESPONSE_TRACK_TITLE.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_NAME)) {
((MPDTrack) tempFileEntry).setTrackArtist(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME)) {
((MPDTrack) tempFileEntry).setTrackArtistSort(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_NAME)) {
((MPDTrack) tempFileEntry).setTrackName(response.substring(MPDResponses.MPD_RESPONSE_TRACK_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME)) {
((MPDTrack) tempFileEntry).setTrackAlbumArtist(response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME)) {
((MPDTrack) tempFileEntry).setTrackAlbumArtistSort(response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_NAME)) {
((MPDTrack) tempFileEntry).setTrackAlbum(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_NAME.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_DATE)) {
((MPDTrack) tempFileEntry).setDate(response.substring(MPDResponses.MPD_RESPONSE_DATE.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_MBID)) {
((MPDTrack) tempFileEntry).setTrackAlbumMBID(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_MBID.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_MBID)) {
((MPDTrack) tempFileEntry).setTrackArtistMBID(response.substring(MPDResponses.MPD_RESPONSE_ARTIST_MBID.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_ARTIST_MBID)) {
((MPDTrack) tempFileEntry).setTrackAlbumArtistMBID(response.substring(MPDResponses.MPD_RESPONSE_ALBUM_ARTIST_MBID.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_MBID)) {
((MPDTrack) tempFileEntry).setTrackMBID(response.substring(MPDResponses.MPD_RESPONSE_TRACK_MBID.length()));
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_TIME)) {
try {
((MPDTrack) tempFileEntry).setLength(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_TRACK_TIME.length())));
} catch (NumberFormatException ignored) {
}
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_SONG_ID)) {
try {
((MPDTrack) tempFileEntry).setSongID(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_SONG_ID.length())));
} catch (NumberFormatException ignored) {
}
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_SONG_POS)) {
try {
((MPDTrack) tempFileEntry).setSongPosition(Integer.valueOf(response.substring(MPDResponses.MPD_RESPONSE_SONG_POS.length())));
} catch (NumberFormatException ignored) {
}
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_DISC_NUMBER)) {
/*
* Check if MPD returned a discnumber like: "1" or "1/3" and set disc count accordingly.
*/
String discNumber = response.substring(MPDResponses.MPD_RESPONSE_DISC_NUMBER.length());
discNumber = discNumber.replaceAll(" ", "");
String[] discNumberSep = discNumber.split("/");
if (discNumberSep.length > 0) {
try {
((MPDTrack) tempFileEntry).setDiscNumber(Integer.valueOf(discNumberSep[0]));
} catch (NumberFormatException ignored) {
}
if (discNumberSep.length > 1) {
try {
((MPDTrack) tempFileEntry).psetAlbumDiscCount(Integer.valueOf(discNumberSep[1]));
} catch (NumberFormatException ignored) {
}
}
} else {
try {
((MPDTrack) tempFileEntry).setDiscNumber(Integer.valueOf(discNumber));
} catch (NumberFormatException ignored) {
}
}
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_TRACK_NUMBER)) {
/*
* Check if MPD returned a tracknumber like: "12" or "12/42" and set albumtrack count accordingly.
*/
String trackNumber = response.substring(MPDResponses.MPD_RESPONSE_TRACK_NUMBER.length());
trackNumber = trackNumber.replaceAll(" ", "");
String[] trackNumbersSep = trackNumber.split("/");
if (trackNumbersSep.length > 0) {
try {
((MPDTrack) tempFileEntry).setTrackNumber(Integer.valueOf(trackNumbersSep[0]));
} catch (NumberFormatException ignored) {
}
if (trackNumbersSep.length > 1) {
try {
((MPDTrack) tempFileEntry).setAlbumTrackCount(Integer.valueOf(trackNumbersSep[1]));
} catch (NumberFormatException ignored) {
}
}
} else {
try {
((MPDTrack) tempFileEntry).setTrackNumber(Integer.valueOf(trackNumber));
} catch (NumberFormatException ignored) {
}
}
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_LAST_MODIFIED)) {
tempFileEntry.setLastModified(response.substring(MPDResponses.MPD_RESPONSE_LAST_MODIFIED.length()));
}
} else if (tempFileEntry != null) {
// Other case tempFileEntry is a playlist or a directory (properties of generic files)
if (response.startsWith(MPDResponses.MPD_RESPONSE_LAST_MODIFIED)) {
tempFileEntry.setLastModified(response.substring(MPDResponses.MPD_RESPONSE_LAST_MODIFIED.length()));
}
}
// Move to the next line.
response = connection.readLine();
}
/* Add last remaining track to list. */
if (null != tempFileEntry) {
trackList.add(tempFileEntry);
}
return trackList;
}
Aggregations