use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.
the class ArtistsFragment method enqueueArtist.
private void enqueueArtist(int index) {
MPDArtist artist = (MPDArtist) mArtistAdapter.getItem(index);
MPDQueryHandler.addArtist(artist.getArtistName(), mAlbumSortOrder);
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.
the class ArtworkManager method fetchArtistImage.
/**
* Starts an asynchronous fetch for the image of the given artist.
*
* @param artist Artist to fetch an image for.
*/
public void fetchArtistImage(final MPDArtist artist) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null) {
return;
}
boolean isWifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET;
if (mWifiOnly && !isWifi) {
return;
}
if (mArtistProvider.equals(mContext.getString(R.string.pref_artwork_provider_lastfm_key))) {
LastFMManager.getInstance(mContext).fetchArtistImage(artist, response -> new InsertArtistImageTask().execute(response), this);
} else if (mArtistProvider.equals(mContext.getString(R.string.pref_artwork_provider_fanarttv_key))) {
FanartTVManager.getInstance(mContext).fetchArtistImage(artist, response -> new InsertArtistImageTask().execute(response), this);
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.
the class ArtworkManager method fetchNextBulkArtist.
/**
* Iterates over the list of artists and downloads images for them.
*/
private void fetchNextBulkArtist() {
Log.v(TAG, "fetchNextBulkArtist");
boolean isEmpty;
synchronized (mArtistList) {
isEmpty = mArtistList.isEmpty();
}
while (!isEmpty) {
Log.v(TAG, "Next artist");
MPDArtist artist;
synchronized (mArtistList) {
artist = mArtistList.remove(0);
Log.v(TAG, "Bulk load next artist: " + artist.getArtistName() + " remaining: " + mArtistList.size());
mBulkProgressCallback.artistsRemaining(mArtistList.size());
}
mCurrentBulkArtist = artist;
// Check if image already there
try {
mDBManager.getArtistImage(mContext, artist);
// If this does not throw the exception it already has an image.
} catch (ImageNotFoundException e) {
fetchArtistImage(artist);
return;
}
synchronized (mArtistList) {
isEmpty = mArtistList.isEmpty();
}
}
if (mAlbumList.isEmpty()) {
mBulkProgressCallback.finishedLoading();
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.
the class MPDResponseParser method parseMPDArtists.
/**
* Parses the return stream of MPD when a list of artists was requested.
*
* @return List of MPDArtists objects
* @throws MPDException if an error from MPD was received during reading
*/
static ArrayList<MPDArtist> parseMPDArtists(final MPDConnection connection, final boolean hasMusicBrainz, final boolean hasListGroup) throws MPDException {
ArrayList<MPDArtist> artistList = new ArrayList<>();
if (!connection.isConnected()) {
return artistList;
}
/* Parse MPD artist return values and create a list of MPDArtist objects */
String response = connection.readLine();
/* Artist properties */
String artistName;
String artistMBID;
MPDArtist tempArtist = null;
while (response != null && !response.startsWith("OK")) {
// Handle new artist entry
if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_NAME)) {
if (null != tempArtist) {
artistList.add(tempArtist);
}
artistName = response.substring(MPDResponses.MPD_RESPONSE_ARTIST_NAME.length());
tempArtist = new MPDArtist(artistName);
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME)) {
if (null != tempArtist) {
artistList.add(tempArtist);
}
artistName = response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_NAME.length());
tempArtist = new MPDArtist(artistName);
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME)) {
if (null != tempArtist) {
artistList.add(tempArtist);
}
artistName = response.substring(MPDResponses.MPD_RESPONSE_ARTIST_SORT_NAME.length());
tempArtist = new MPDArtist(artistName);
} else if (response.startsWith(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME)) {
if (null != tempArtist) {
artistList.add(tempArtist);
}
artistName = response.substring(MPDResponses.MPD_RESPONSE_ALBUMARTIST_SORT_NAME.length());
tempArtist = new MPDArtist(artistName);
}
// Handle artist properties
if (tempArtist != null) {
if (response.startsWith(MPDResponses.MPD_RESPONSE_ARTIST_MBID)) {
artistMBID = response.substring(MPDResponses.MPD_RESPONSE_ARTIST_MBID.length());
tempArtist.addMBID(artistMBID);
}
}
response = connection.readLine();
}
// Add last artist
if (null != tempArtist) {
artistList.add(tempArtist);
}
// Sort the artists for later sectioning.
Collections.sort(artistList);
// and then remove duplicates.
if (hasMusicBrainz && hasListGroup) {
ArrayList<MPDArtist> clearedList = new ArrayList<>();
// Remove multiple entries when one artist is in list with and without MBID
int artistListSize = artistList.size();
for (int i = 0; i < artistListSize; i++) {
MPDArtist artist = artistList.get(i);
if (i + 1 != artistListSize) {
MPDArtist nextArtist = artistList.get(i + 1);
// Next artist is different, add this one (the one with most MBIDs)
if (!artist.getArtistName().equals(nextArtist.getArtistName())) {
clearedList.add(artist);
}
} else {
// Last artist in list -> add
clearedList.add(artist);
}
}
return clearedList;
} else {
return artistList;
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist 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