Search in sources :

Example 1 with FileListItem

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

the class CurrentPlaylistAdapter 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.
    MPDTrack track = getTrack(position);
    // Check if the track was available in local data set already (or is currently fetching)
    if (track != null) {
        String trackAlbum = track.getTrackAlbum();
        VIEW_TYPES type = VIEW_TYPES.values()[getItemViewType(position)];
        // Normal track item type
        if (type == VIEW_TYPES.TYPE_TRACK_ITEM) {
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, false);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setTrack(track, true, mContext);
            tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
        } else if (type == VIEW_TYPES.TYPE_SECTION_TRACK_ITEM) {
            // Section track type.
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, trackAlbum, false, this);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setSectionHeader(trackAlbum);
            tracksListViewItem.setTrack(track, true, mContext);
            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.
            ((FileListItem) convertView).prepareArtworkFetching(mArtworkManager, track);
            // starts the loading.
            if (mScrollSpeed == 0) {
                ((FileListItem) convertView).startCoverImageTask();
            }
        }
        if (null != mLastStatus && mLastStatus.getCurrentSongIndex() == position) {
            ((FileListItem) convertView).setPlaying(true);
        } else {
            ((FileListItem) convertView).setPlaying(false);
        }
    } else {
        // the running fetch.
        if (convertView == null) {
            // If not create a new Listitem
            convertView = new FileListItem(mContext, false);
        } else {
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setTrack(null, true, mContext);
        }
    }
    // The view that is used for the position in the list
    return convertView;
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) FileListItem(org.gateshipone.malp.application.listviewitems.FileListItem)

Example 2 with FileListItem

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

FileListItem (org.gateshipone.malp.application.listviewitems.FileListItem)2 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)2 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)1 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)1 MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)1