Search in sources :

Example 6 with DataHolder

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

the class PlaylistAdapter 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 Playlist playlist = getItem(i);
        if (playlist == null) {
            continue;
        }
        // Build the data holder
        mData[i] = new DataHolder();
        // Playlist Id
        mData[i].mItemId = playlist.mPlaylistId;
        // Playlist names (line one)
        mData[i].mLineOne = playlist.mPlaylistName;
    }
}
Also used : Playlist(com.andrew.apollo.model.Playlist) DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder)

Example 7 with DataHolder

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

the class SongAdapter method getView.

/**
 * {@inheritDoc}
 */
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    convertView = prepareMusicViewHolder(mLayoutId, getContext(), convertView, parent);
    final MusicViewHolder musicViewHolder = (MusicViewHolder) convertView.getTag();
    final DataHolder dataHolder = mData[position];
    updateFirstTwoArtistLines(musicViewHolder, dataHolder);
    if (mImageFetcher == null) {
        Log.w("warning", "ArtistAdapter has null image fetcher");
    }
    if (mImageFetcher != null && dataHolder != null && Ref.alive(musicViewHolder.mImage)) {
        if (dataHolder.mParentId == -1) {
            mImageFetcher.loadAlbumImage(dataHolder.mLineTwo, dataHolder.mLineOne, R.drawable.list_item_audio_icon, musicViewHolder.mImage.get());
            async(getContext(), SongAdapter::updateDataHolderAlbumId, dataHolder, musicViewHolder, mImageFetcher, SongAdapter::updateAlbumImage);
        } else {
            mImageFetcher.loadAlbumImage(dataHolder.mLineTwo, dataHolder.mLineOne, dataHolder.mParentId, musicViewHolder.mImage.get());
        }
    }
    if (musicViewHolder != null) {
        if (Ref.alive(musicViewHolder.mLineThree)) {
            musicViewHolder.mLineThree.get().setVisibility(View.GONE);
        }
        if (dataHolder != null) {
            // Set each song name (line one)
            if (Ref.alive(musicViewHolder.mLineOne)) {
                musicViewHolder.mLineOne.get().setText(dataHolder.mLineOne);
            }
            // Set the song duration (line one, right)
            if (Ref.alive(musicViewHolder.mLineOneRight)) {
                musicViewHolder.mLineOneRight.get().setText(dataHolder.mLineOneRight);
            }
            // Set the artist name (line two)
            if (Ref.alive(musicViewHolder.mLineTwo)) {
                musicViewHolder.mLineTwo.get().setText(dataHolder.mLineTwo);
            }
            if (MusicUtils.getCurrentAudioId() == dataHolder.mItemId) {
                musicViewHolder.mLineOne.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_highlight));
                musicViewHolder.mLineOneRight.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_highlight));
                musicViewHolder.mLineTwo.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_highlight));
            } else {
                musicViewHolder.mLineOne.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_primary));
                musicViewHolder.mLineOneRight.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_primary));
                musicViewHolder.mLineTwo.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_primary));
            }
        }
    }
    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