Search in sources :

Example 11 with MPDArtist

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);
}
Also used : MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 12 with MPDArtist

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);
    }
}
Also used : LastFMManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.LastFMManager) Context(android.content.Context) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList) MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) R(org.gateshipone.malp.R) FanartTVManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.FanartTVManager) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) AlbumImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.AlbumImageResponse) ArrayList(java.util.ArrayList) ArtistFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.ArtistFetchError) JSONException(org.json.JSONException) HTTPAlbumImageProvider(org.gateshipone.malp.application.artworkdatabase.network.artprovider.HTTPAlbumImageProvider) BitmapUtils(org.gateshipone.malp.application.utils.BitmapUtils) MusicBrainzManager(org.gateshipone.malp.application.artworkdatabase.network.artprovider.MusicBrainzManager) MPDQueryHandler(org.gateshipone.malp.mpdservice.handlers.serverhandler.MPDQueryHandler) PreferenceManager(android.preference.PreferenceManager) NetworkResponse(com.android.volley.NetworkResponse) AlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.AlbumFetchError) Log(android.util.Log) ConnectivityManager(android.net.ConnectivityManager) TrackAlbumImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumImageResponse) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) AsyncTask(android.os.AsyncTask) MALPRequestQueue(org.gateshipone.malp.application.artworkdatabase.network.MALPRequestQueue) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) TrackAlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError) VolleyError(com.android.volley.VolleyError) BroadcastReceiver(android.content.BroadcastReceiver) FormatHelper(org.gateshipone.malp.application.utils.FormatHelper) List(java.util.List) SharedPreferences(android.content.SharedPreferences) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) Bitmap(android.graphics.Bitmap) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) ArtistImageResponse(org.gateshipone.malp.application.artworkdatabase.network.responses.ArtistImageResponse) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 13 with MPDArtist

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();
    }
}
Also used : MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 14 with MPDArtist

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;
    }
}
Also used : ArrayList(java.util.ArrayList) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 15 with MPDArtist

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;
}
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

MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)15 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)5 Bitmap (android.graphics.Bitmap)3 HashMap (java.util.HashMap)3 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)2 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)2 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)2 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1