Search in sources :

Example 1 with GenericGridItem

use of org.gateshipone.malp.application.listviewitems.GenericGridItem 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 GenericGridItem

use of org.gateshipone.malp.application.listviewitems.GenericGridItem in project malp by gateship-one.

the class ArtistsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MPDArtist artist = (MPDArtist) getItem(position);
    String label = artist.getArtistName();
    if (label.isEmpty()) {
        label = mContext.getResources().getString(R.string.no_artist_tag);
    }
    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);
        } else {
            // Create new view if no reusable is available
            listItem = new ImageListItem(mContext, label, null, this);
        }
        // This will prepare the view for fetching the image from the internet if not already saved in local database.
        listItem.prepareArtworkFetching(mArtworkManager, artist);
        // 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, artist);
        // 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) GenericGridItem(org.gateshipone.malp.application.listviewitems.GenericGridItem) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) GridView(android.widget.GridView)

Aggregations

ViewGroup (android.view.ViewGroup)2 AbsListView (android.widget.AbsListView)2 GridView (android.widget.GridView)2 GenericGridItem (org.gateshipone.malp.application.listviewitems.GenericGridItem)2 ImageListItem (org.gateshipone.malp.application.listviewitems.ImageListItem)2 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)1