Search in sources :

Example 1 with DataHolder

use of com.andrew.apollo.ui.MusicViewHolder.DataHolder in project frostwire by frostwire.

the class ArtistAdapter method buildCache.

/**
 * Method used to cache the data used to populate the list or grid. The idea
 * is to cache everything before {@code #getView(int, View, ViewGroup)} is
 * called.
 */
public void buildCache() {
    mData = new DataHolder[getCount()];
    for (int i = 0; i < getCount(); i++) {
        // Build the artist
        final Artist artist = getItem(i);
        if (artist != null) {
            // Build the data holder
            mData[i] = new DataHolder();
            // Artist Id
            mData[i].mItemId = artist.mArtistId;
            // Artist names (line one)
            mData[i].mLineOne = artist.mArtistName;
            // Number of albums (line two)
            mData[i].mLineTwo = MusicUtils.makeLabel(getContext(), R.plurals.Nalbums, artist.mAlbumNumber);
            // Number of songs (line three)
            mData[i].mLineThree = MusicUtils.makeLabel(getContext(), R.plurals.Nsongs, artist.mSongNumber);
        }
    }
}
Also used : Artist(com.andrew.apollo.model.Artist) DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder)

Example 2 with DataHolder

use of com.andrew.apollo.ui.MusicViewHolder.DataHolder in project frostwire by frostwire.

the class ArtistAdapter method getView.

/**
 * {@inheritDoc}
 */
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    convertView = prepareMusicViewHolder(mLayoutId, getContext(), convertView, parent);
    MusicViewHolder holder = (MusicViewHolder) convertView.getTag();
    final DataHolder dataHolder = mData[position];
    updateFirstTwoArtistLines(holder, dataHolder);
    if (mImageFetcher != null && dataHolder != null && Ref.alive(holder.mImage)) {
        // Asynchronously load the artist image into the adapter
        mImageFetcher.loadArtistImage(dataHolder.mLineOne, holder.mImage.get());
    }
    if (mLoadExtraData && mImageFetcher != null && holder != null) {
        if (Ref.alive(holder.mOverlay)) {
            // Make sure the background layer gets set
            holder.mOverlay.get().setBackgroundColor(mOverlayColor);
        }
        if (Ref.alive(holder.mLineThree)) {
            // Set the number of songs (line three)
            holder.mLineThree.get().setText(dataHolder.mLineThree);
        }
        if (Ref.alive(holder.mBackground)) {
            if (mLayoutId == R.layout.list_item_detailed_no_background) {
                holder.mBackground.get().setBackground(null);
                holder.mBackground.get().setBackgroundColor(convertView.getResources().getColor(R.color.app_background_white));
            } else {
                // Set the background image
                mImageFetcher.loadArtistImage(dataHolder.mLineOne, holder.mBackground.get());
            }
        }
        if (Ref.alive(holder.mImage)) {
            // Play the artist when the artwork is touched
            initArtistPlayOnClick(holder.mImage.get(), position);
        }
    }
    return convertView;
}
Also used : DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder) MusicViewHolder(com.andrew.apollo.ui.MusicViewHolder)

Example 3 with DataHolder

use of com.andrew.apollo.ui.MusicViewHolder.DataHolder in project frostwire by frostwire.

the class SongAdapter method buildCache.

/**
 * Method used to cache the data used to populate the list or grid. The idea
 * is to cache everything before {@code #getView(int, View, ViewGroup)} is
 * called.
 */
public void buildCache() {
    mData = new DataHolder[getCount()];
    for (int i = 0; i < getCount(); i++) {
        // Build the song
        final Song song = getItem(i);
        if (song == null) {
            continue;
        }
        // Build the data holder
        mData[i] = new DataHolder();
        // Song Id
        mData[i].mItemId = song.mSongId;
        // Song names (line one)
        mData[i].mLineOne = song.mSongName;
        // Song duration (line one, right)
        mData[i].mLineOneRight = MusicUtils.makeTimeString(getContext(), song.mDuration);
        // Artist name (line two)
        mData[i].mLineTwo = song.mArtistName;
    }
}
Also used : Song(com.andrew.apollo.model.Song) DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder)

Example 4 with DataHolder

use of com.andrew.apollo.ui.MusicViewHolder.DataHolder in project frostwire by frostwire.

the class AlbumAdapter method buildCache.

/**
 * Method used to cache the data used to populate the list or grid. The idea
 * is to cache everything before {@code #getView(int, View, ViewGroup)} is
 * called.
 */
public void buildCache() {
    mData = new DataHolder[getCount()];
    for (int i = 0; i < getCount(); i++) {
        // Build the album
        final Album album = getItem(i);
        if (album == null) {
            continue;
        }
        // Build the data holder
        mData[i] = new DataHolder();
        // Album Id
        mData[i].mItemId = album.mAlbumId;
        // Album names (line one)
        mData[i].mLineOne = album.mAlbumName;
        // Album artist names (line two)
        mData[i].mLineTwo = album.mArtistName;
        // Number of songs for each album (line three)
        mData[i].mLineThree = MusicUtils.makeLabel(getContext(), R.plurals.Nsongs, album.mSongNumber);
    }
}
Also used : DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder) Album(com.andrew.apollo.model.Album)

Example 5 with DataHolder

use of com.andrew.apollo.ui.MusicViewHolder.DataHolder in project frostwire by frostwire.

the class AlbumAdapter method getView.

/**
 * {@inheritDoc}
 */
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    // Recycle ViewHolder's items
    convertView = prepareMusicViewHolder(mLayoutId, getContext(), convertView, parent);
    MusicViewHolder holder = (MusicViewHolder) convertView.getTag();
    // Retrieve the data holder
    final DataHolder dataHolder = mData[position];
    updateFirstTwoArtistLines(holder, dataHolder);
    if (mImageFetcher == null) {
        LOG.warn("ArtistAdapter has null image fetcher");
    }
    if (mImageFetcher != null && dataHolder != null && Ref.alive(holder.mImage)) {
        // Asynchronously load the album images into the adapter
        mImageFetcher.loadAlbumImage(dataHolder.mLineTwo, dataHolder.mLineOne, dataHolder.mItemId, holder.mImage.get());
    }
    // List view only items
    if (mLoadExtraData && holder != null && dataHolder != null) {
        if (Ref.alive(holder.mOverlay)) {
            // Make sure the background layer gets set
            holder.mOverlay.get().setBackgroundColor(mOverlay);
        }
        if (Ref.alive(holder.mLineThree)) {
            // Set the number of songs (line three)
            holder.mLineThree.get().setText(dataHolder.mLineThree);
        }
        if (mImageFetcher != null && Ref.alive(holder.mBackground)) {
            if (mLayoutId == R.layout.list_item_detailed_no_background) {
                holder.mBackground.get().setBackground(null);
                holder.mBackground.get().setBackgroundColor(convertView.getResources().getColor(R.color.app_background_white));
            } else {
                // Asynchronously load the artist image on the background view
                mImageFetcher.loadArtistImage(dataHolder.mLineTwo, holder.mBackground.get());
            }
        }
    }
    if (mTouchPlay && holder != null && Ref.alive(holder.mImage)) {
        // Play the album when the artwork is touched
        initAlbumPlayOnClick(holder.mImage.get(), position);
    }
    return convertView;
}
Also used : DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder) MusicViewHolder(com.andrew.apollo.ui.MusicViewHolder)

Aggregations

DataHolder (com.andrew.apollo.ui.MusicViewHolder.DataHolder)7 MusicViewHolder (com.andrew.apollo.ui.MusicViewHolder)3 Album (com.andrew.apollo.model.Album)1 Artist (com.andrew.apollo.model.Artist)1 Playlist (com.andrew.apollo.model.Playlist)1 Song (com.andrew.apollo.model.Song)1