use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.
the class AlbumsFragment method enqueueAlbum.
/**
* Enqueues the album selected by the user
* @param index Index of the selected album
*/
private void enqueueAlbum(int index) {
MPDAlbum album = (MPDAlbum) mAlbumsAdapter.getItem(index);
// support group commands and therefore do not provide artist tags for albums)
if (mArtist != null && !mArtist.getArtistName().isEmpty() && album.getArtistName().isEmpty()) {
album.setArtistName(mArtist.getArtistName());
album.setArtistSortName(mArtist.getArtistName());
}
MPDQueryHandler.addArtistAlbum(album.getName(), album.getArtistName(), album.getMBID());
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.
the class MPDInterface method getAlbums.
/**
* Get a list of all albums available in the database.
*
* @return List of MPDAlbum
*/
public List<MPDAlbum> getAlbums() throws MPDException {
List<MPDAlbum> albums;
synchronized (this) {
// Get a list of albums. Check if server is new enough for MB and AlbumArtist filtering
mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMS(mConnection.getServerCapabilities()));
// Remove empty albums at beginning of the list
albums = MPDResponseParser.parseMPDAlbums(mConnection);
}
ListIterator<MPDAlbum> albumIterator = albums.listIterator();
while (albumIterator.hasNext()) {
MPDAlbum album = albumIterator.next();
if (album.getName().isEmpty()) {
albumIterator.remove();
} else {
break;
}
}
return albums;
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.
the class MPDInterface method getAlbumsInPath.
/**
* Get a list of all albums available in the database.
*
* @return List of MPDAlbum
*/
public List<MPDAlbum> getAlbumsInPath(String path) throws MPDException {
List<MPDAlbum> albums;
synchronized (this) {
// Get a list of albums. Check if server is new enough for MB and AlbumArtist filtering
mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMS_FOR_PATH(path, mConnection.getServerCapabilities()));
// Remove empty albums at beginning of the list
albums = MPDResponseParser.parseMPDAlbums(mConnection);
}
ListIterator<MPDAlbum> albumIterator = albums.listIterator();
while (albumIterator.hasNext()) {
MPDAlbum album = albumIterator.next();
if (album.getName().isEmpty()) {
albumIterator.remove();
} else {
break;
}
}
return albums;
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.
the class MPDResponseParser method parseMPDAlbums.
/**
* Parses the return of MPD when a list of albums was requested.
*
* @return List of MPDAlbum objects
* @throws MPDException if an error from MPD was received during reading
*/
static ArrayList<MPDAlbum> parseMPDAlbums(final MPDConnection connection) throws MPDException {
ArrayList<MPDAlbum> albumList = new ArrayList<>();
if (!connection.isConnected()) {
return albumList;
}
/* Parse the MPD response and create a list of MPD albums */
String albumName;
MPDAlbum tempAlbum = null;
String responseString = connection.readLine();
while (responseString != null && !responseString.startsWith("OK")) {
/* Check if the response is an album */
if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_NAME)) {
/* We found an album, add it to the list. */
if (null != tempAlbum) {
albumList.add(tempAlbum);
}
albumName = responseString.substring(MPDResponses.MPD_RESPONSE_ALBUM_NAME.length());
tempAlbum = new MPDAlbum(albumName);
}
if (tempAlbum != null) {
if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUM_MBID)) {
tempAlbum.setMBID(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUM_MBID.length()));
} else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME)) {
/* Check if the responseString is a album artist. */
tempAlbum.setArtistName(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME.length()));
} else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME)) {
/* Check if the responseString is a album artist. */
tempAlbum.setArtistSortName(responseString.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME.length()));
} else if (responseString.startsWith(MPDResponses.MPD_RESPONSE_DATE)) {
// Try to parse Date
String dateString = responseString.substring(MPDResponses.MPD_RESPONSE_DATE.length());
SimpleDateFormat format = new SimpleDateFormat("yyyy");
try {
tempAlbum.setDate(format.parse(dateString));
} catch (ParseException e) {
Log.w(TAG, "Error parsing date: " + dateString);
}
}
}
responseString = connection.readLine();
}
/* Because of the loop structure the last album has to be added because no
"ALBUM:" is sent anymore.
*/
if (null != tempAlbum) {
albumList.add(tempAlbum);
}
// Sort the albums for later sectioning.
Collections.sort(albumList);
return albumList;
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.
the class AsyncLoader method doInBackground.
/**
* Asynchronous task in parallel to the GUI thread.
* @param params Input parameter containing all the necessary informaton to fetch the image.
* @return Bitmap loaded from the database.
*/
@Override
protected Bitmap doInBackground(CoverViewHolder... params) {
// Save the time when loading started for later duration calculation
mStartTime = System.currentTimeMillis();
mCover = params[0];
Bitmap image = null;
// Check if model item is artist or album
if (mCover.modelItem instanceof MPDArtist) {
MPDArtist artist = (MPDArtist) mCover.modelItem;
try {
// Check if image is available. If it is not yet fetched it will throw an exception
// If it was already searched for and not found, this will be null.
image = mCover.artworkManager.getArtistImage(artist, mCover.imageDimension.first, mCover.imageDimension.second, false);
} catch (ImageNotFoundException e) {
// Check if fetching for this item is already ongoing
if (!artist.getFetching()) {
// If not set it as ongoing and request the image fetch.
mCover.artworkManager.fetchArtistImage(artist);
artist.setFetching(true);
}
}
} else if (mCover.modelItem instanceof MPDAlbum) {
MPDAlbum album = (MPDAlbum) mCover.modelItem;
try {
// Check if image is available. If it is not yet fetched it will throw an exception.
// If it was already searched for and not found, this will be null.
image = mCover.artworkManager.getAlbumImage(album, mCover.imageDimension.first, mCover.imageDimension.second, false);
} catch (ImageNotFoundException e) {
// Check if fetching for this item is already ongoing
if (!album.getFetching()) {
// If not set it as ongoing and request the image fetch.
mCover.artworkManager.fetchAlbumImage(album);
album.setFetching(true);
}
}
} else if (mCover.modelItem instanceof MPDTrack) {
MPDTrack track = (MPDTrack) mCover.modelItem;
try {
// Check if image is available. If it is not yet fetched it will throw an exception.
// If it was already searched for and not found, this will be null.
image = mCover.artworkManager.getAlbumImageForTrack(track, mCover.imageDimension.first, mCover.imageDimension.second, false);
} catch (ImageNotFoundException e) {
// Check if fetching for this item is already ongoing
if (!track.getFetching()) {
// If not set it as ongoing and request the image fetch.
mCover.artworkManager.fetchAlbumImage(track);
track.setFetching(true);
}
}
}
return image;
}
Aggregations