use of org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException 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