Search in sources :

Example 1 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class AlbumsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MPDAlbum album = (MPDAlbum) getItem(position);
    String label = album.getName();
    if (label.isEmpty()) {
        label = mContext.getResources().getString(R.string.no_album_tag);
    }
    String albumArtist = album.getArtistName();
    if (mUseList) {
        // Check if a view can be recycled
        ImageListItem listItem;
        if (convertView != null) {
            listItem = (ImageListItem) convertView;
            // Make sure to reset the layoutParams in case of change (rotation for example)
            listItem.setText(label);
            listItem.setDetails(albumArtist);
        } else {
            // Create new view if no reusable is available
            listItem = new ImageListItem(mContext, label, albumArtist, this);
        }
        // This will prepare the view for fetching the image from the internet if not already saved in local database.
        listItem.prepareArtworkFetching(mArtworkManager, album);
        // Check if the scroll speed currently is already 0, then start the image task right away.
        if (mScrollSpeed == 0) {
            listItem.setImageDimension(mListItemHeight, mListItemHeight);
            listItem.startCoverImageTask();
        }
        return listItem;
    } else {
        GenericGridItem gridItem;
        ViewGroup.LayoutParams layoutParams;
        int width = ((GridView) mListView).getColumnWidth();
        // Check if a view can be recycled
        if (convertView == null) {
            // Create new view if no reusable is available
            gridItem = new GenericGridItem(mContext, label, this);
            layoutParams = new android.widget.AbsListView.LayoutParams(width, width);
        } else {
            gridItem = (GenericGridItem) convertView;
            gridItem.setTitle(label);
            layoutParams = gridItem.getLayoutParams();
            layoutParams.height = width;
            layoutParams.width = width;
        }
        // Make sure to reset the layoutParams in case of change (rotation for example)
        gridItem.setLayoutParams(layoutParams);
        // This will prepare the view for fetching the image from the internet if not already saved in local database.
        gridItem.prepareArtworkFetching(mArtworkManager, album);
        // Check if the scroll speed currently is already 0, then start the image task right away.
        if (mScrollSpeed == 0) {
            gridItem.setImageDimension(width, width);
            gridItem.startCoverImageTask();
        }
        return gridItem;
    }
}
Also used : ImageListItem(org.gateshipone.malp.application.listviewitems.ImageListItem) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) GenericGridItem(org.gateshipone.malp.application.listviewitems.GenericGridItem) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView)

Example 2 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class ArtworkManager method fetchNextBulkAlbum.

/**
 * Iterates over the list of albums and downloads images for them.
 */
private void fetchNextBulkAlbum() {
    boolean isEmpty;
    synchronized (mAlbumList) {
        isEmpty = mAlbumList.isEmpty();
    }
    while (!isEmpty) {
        MPDAlbum album;
        synchronized (mAlbumList) {
            album = mAlbumList.remove(0);
            Log.v(TAG, "Bulk load next album: " + album.getName() + ":" + album.getArtistName() + " remaining: " + mAlbumList.size());
            mBulkProgressCallback.albumsRemaining(mAlbumList.size());
        }
        mCurrentBulkAlbum = album;
        // Check if image already there
        try {
            mDBManager.getAlbumImage(mContext, album);
        // If this does not throw the exception it already has an image.
        } catch (ImageNotFoundException e) {
            fetchAlbumImage(album);
            return;
        }
        synchronized (mAlbumList) {
            isEmpty = mAlbumList.isEmpty();
        }
    }
    if (mArtistList.isEmpty()) {
        mBulkProgressCallback.finishedLoading();
    }
}
Also used : MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 3 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class ArtworkManager method fetchAlbumImage.

/**
 * Starts an asynchronous fetch for the image of the given album
 *
 * @param track Track to be used for image fetching
 */
public void fetchAlbumImage(final MPDTrack track) {
    // Create a dummy album
    MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
    album.setMBID(track.getTrackAlbumMBID());
    album.setArtistName(track.getTrackAlbumArtist());
    // Check if user-specified HTTP cover download is activated
    if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
        HTTPAlbumImageProvider.getInstance(mContext).fetchAlbumImage(track, response -> new InsertTrackAlbumImageTask().execute(response), new TrackAlbumFetchError() {

            @Override
            public void fetchJSONException(MPDTrack track, JSONException exception) {
            }

            @Override
            public void fetchVolleyError(MPDTrack track, VolleyError error) {
                Log.v(TAG, "Local HTTP download failed, try user-selected download provider");
                MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
                album.setMBID(track.getTrackAlbumMBID());
                album.setArtistName(track.getTrackAlbumArtist());
                fetchAlbumImage(album);
                synchronized (mTrackList) {
                    if (!mTrackList.isEmpty()) {
                        fetchNextBulkTrackAlbum();
                    }
                }
            }
        });
    } else {
        // Use the dummy album to fetch the image
        fetchAlbumImage(album);
    }
}
Also used : VolleyError(com.android.volley.VolleyError) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) JSONException(org.json.JSONException) TrackAlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)

Example 4 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class ArtworkManager method bulkLoadImages.

/**
 * Entrance point to start downloading all images for the complete database of the current
 * default MPD server.
 *
 * @param progressCallback Used callback interface to be notified about the download progress.
 */
public void bulkLoadImages(BulkLoadingProgressCallback progressCallback) {
    if (progressCallback == null) {
        return;
    }
    mBulkProgressCallback = progressCallback;
    mArtistList.clear();
    mAlbumList.clear();
    mBulkLoadAlbumsReady = false;
    mBulkLoadArtistsReady = false;
    Log.v(TAG, "Start bulk loading");
    if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
        Log.v(TAG, "Try to get all tracks from MPD");
        MPDQueryHandler.getAllTracks(new MPDResponseFileList() {

            @Override
            public void handleTracks(List<MPDFileEntry> fileList, int windowstart, int windowend) {
                Log.v(TAG, "Received track count: " + fileList.size());
                new ParseMPDTrackListTask().execute(fileList);
            }
        });
    } else {
        if (!mAlbumProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
            MPDQueryHandler.getAlbums(new MPDResponseAlbumList() {

                @Override
                public void handleAlbums(List<MPDAlbum> albumList) {
                    new ParseMPDAlbumListTask().execute(albumList);
                }
            });
        }
    }
    if (!mArtistProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
        MPDQueryHandler.getArtists(new MPDResponseArtistList() {

            @Override
            public void handleArtists(List<MPDArtist> artistList) {
                new ParseMPDArtistListTask().execute(artistList);
            }
        });
    }
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDResponseFileList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList) MPDResponseAlbumList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDResponseArtistList(org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)

Example 5 with MPDAlbum

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum in project malp by gateship-one.

the class FileAdapter method getView.

/**
 * Create the actual listview items if no reusable object is provided.
 *
 * @param position    Index of the item to create.
 * @param convertView If != null this view can be reused to optimize performance.
 * @param parent      Parent of the view
 * @return
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get MPDTrack at the given index used for this item.
    MPDFileEntry file = (MPDFileEntry) getItem(position);
    if (file instanceof MPDTrack) {
        MPDTrack track = (MPDTrack) file;
        // Normal file entry
        if (!mShowSectionItems || (VIEW_TYPES.values()[getItemViewType(position)] == VIEW_TYPES.TYPE_FILE_ITEM)) {
            if (convertView == null) {
                convertView = new FileListItem(mContext, mShowIcons);
            }
            ((FileListItem) convertView).setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                ((FileListItem) convertView).setTrackNumber(String.valueOf(position + 1));
            }
            return convertView;
        } else {
            // Section items
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, track.getTrackAlbum(), mShowIcons, this);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setSectionHeader(track.getTrackAlbum());
            tracksListViewItem.setTrack(track, mUseTags, mContext);
            if (!mShowTrackNumbers) {
                tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
            }
            // This will prepare the view for fetching the image from the internet if not already saved in local database.
            // Dummy MPDAlbum
            MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
            tmpAlbum.setMBID(track.getTrackAlbumMBID());
            ((FileListItem) convertView).prepareArtworkFetching(ArtworkManager.getInstance(mContext.getApplicationContext()), tmpAlbum);
            // starts the loading.
            if (mScrollSpeed == 0) {
                ((FileListItem) convertView).startCoverImageTask();
            }
            return convertView;
        }
    } else if (file instanceof MPDDirectory) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setDirectory((MPDDirectory) file, mContext);
        return convertView;
    } else if (file instanceof MPDPlaylist) {
        if (convertView == null) {
            convertView = new FileListItem(mContext, mShowIcons);
        }
        ((FileListItem) convertView).setPlaylist((MPDPlaylist) file, mContext);
        return convertView;
    }
    return new FileListItem(mContext, mShowIcons);
}
Also used : MPDFileEntry(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) MPDDirectory(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory) MPDPlaylist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist) FileListItem(org.gateshipone.malp.application.listviewitems.FileListItem)

Aggregations

MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)15 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)5 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)5 Bitmap (android.graphics.Bitmap)3 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)3 VolleyError (com.android.volley.VolleyError)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)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 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 BitmapFactory (android.graphics.BitmapFactory)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkInfo (android.net.NetworkInfo)1