Search in sources :

Example 1 with ImageNotFoundException

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;
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) Bitmap(android.graphics.Bitmap) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) ImageNotFoundException(org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException)

Aggregations

Bitmap (android.graphics.Bitmap)1 ImageNotFoundException (org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException)1 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)1 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)1