Search in sources :

Example 1 with Album

use of com.andrew.apollo.model.Album in project frostwire by frostwire.

the class AlbumLoader method loadInBackground.

/**
 * {@inheritDoc}
 */
@Override
public List<Album> loadInBackground() {
    final ArrayList<Album> mAlbumsList = new ArrayList<>();
    // Create the Cursor
    Cursor mCursor;
    try {
        mCursor = makeCursor(getContext());
    } catch (Throwable e) {
        return Collections.emptyList();
    }
    // Gather the data
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            mAlbumsList.add(getAlbumEntryFromCursor(mCursor));
        // String an = mCursor.getString(1) != null ? mCursor.getString(1) : "n/a";
        // String art = mCursor.getString(2) != null ? mCursor.getString(2) : "n/a";
        // LOGGER.info("Adding id: " + mCursor.getLong(0) + " - albumName: " + an + " - artist: " + art);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    return mAlbumsList;
}
Also used : ArrayList(java.util.ArrayList) Album(com.andrew.apollo.model.Album) Cursor(android.database.Cursor)

Example 2 with Album

use of com.andrew.apollo.model.Album 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 3 with Album

use of com.andrew.apollo.model.Album in project frostwire by frostwire.

the class ApolloFragment method onCreateContextMenu.

@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    int mSelectedPosition = info.position - mAdapter.getOffset();
    // Create a new song
    mItem = mAdapter.getItem(mSelectedPosition);
    // TODO: Remove these mutable properties, parametrize the onMenuEvent handlers.
    if (mItem instanceof Song) {
        Song mSong = (Song) mItem;
        mSelectedId = mSong.mSongId;
        mSongName = mSong.mSongName;
        mAlbumName = mSong.mAlbumName;
        mArtistName = mSong.mArtistName;
        mSongList = null;
    } else if (mItem instanceof Album) {
        Album mAlbum = (Album) mItem;
        mSelectedId = mAlbum.mAlbumId;
        mSongName = null;
        mAlbumName = mAlbum.mAlbumName;
        mArtistName = mAlbum.mArtistName;
        mSongList = MusicUtils.getSongListForAlbum(getActivity(), mAlbum.mAlbumId);
    } else if (mItem instanceof Artist) {
        Artist mArtist = (Artist) mItem;
        mSelectedId = mArtist.mArtistId;
        mSongName = null;
        mArtistName = mArtist.mArtistName;
        mSongList = MusicUtils.getSongListForArtist(getActivity(), mArtist.mArtistId);
    } else if (mItem instanceof Genre) {
        Genre mGenre = (Genre) mItem;
        mSelectedId = mGenre.mGenreId;
        mSongList = MusicUtils.getSongListForGenre(getActivity(), mGenre.mGenreId);
    } else if (mItem instanceof Playlist) {
        Playlist mPlaylist = (Playlist) mItem;
        mSelectedId = mPlaylist.mPlaylistId;
        if (mSelectedId == PlaylistLoader.FAVORITE_PLAYLIST_ID) {
            mSongList = MusicUtils.getSongListForFavorites(getActivity());
        } else if (mSelectedId == PlaylistLoader.LAST_ADDED_PLAYLIST_ID) {
            mSongList = MusicUtils.getSongListForLastAdded(getActivity());
        } else {
            mSongList = MusicUtils.getSongListForPlaylist(getActivity(), mPlaylist.mPlaylistId);
        }
    }
    // Play the selected songs
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE, getString(R.string.context_menu_play_selection)).setIcon(R.drawable.contextmenu_icon_play);
    // Play the next song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next)).setIcon(R.drawable.contextmenu_icon_next);
    // Add the song/album to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue)).setIcon(R.drawable.contextmenu_icon_queue_add);
    // Add the song to favorite's playlist
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_FAVORITES, Menu.NONE, R.string.add_to_favorites).setIcon(R.drawable.contextmenu_icon_favorite);
    // Add the song/album to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE, R.string.add_to_playlist).setIcon(R.drawable.contextmenu_icon_add_to_existing_playlist_dark);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);
    if (mItem instanceof Song) {
        menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE, getString(R.string.context_menu_use_as_ringtone)).setIcon(R.drawable.contextmenu_icon_ringtone);
    }
    // More by artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE, getString(R.string.context_menu_more_by_artist)).setIcon(R.drawable.contextmenu_icon_artist);
    // Delete the album
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete)).setIcon(R.drawable.contextmenu_icon_trash);
}
Also used : Artist(com.andrew.apollo.model.Artist) Song(com.andrew.apollo.model.Song) Playlist(com.andrew.apollo.model.Playlist) CreateNewPlaylist(com.andrew.apollo.menu.CreateNewPlaylist) Album(com.andrew.apollo.model.Album) AdapterView(android.widget.AdapterView) SubMenu(android.view.SubMenu) Genre(com.andrew.apollo.model.Genre)

Example 4 with Album

use of com.andrew.apollo.model.Album in project frostwire by frostwire.

the class ArtistAlbumAdapter method getView.

/**
 * {@inheritDoc}
 */
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    // Return a faux header at position 0
    if (position == 0) {
        return mHeader;
    }
    // Recycle MusicHolder's items
    convertView = prepareMusicViewHolder(mLayoutId, getContext(), convertView, parent);
    MusicViewHolder holder = (MusicViewHolder) convertView.getTag();
    if (holder != null && Ref.alive(holder.mOverlay)) {
        holder.mOverlay.get().setBackgroundColor(0);
    }
    // Retrieve the album
    final Album album = getItem(position - getOffset());
    final String albumName = album.mAlbumName;
    if (holder != null) {
        if (Ref.alive(holder.mLineOne)) {
            // Set each album name (line one)
            holder.mLineOne.get().setText(albumName);
        }
        if (Ref.alive(holder.mLineTwo)) {
            // Set the number of songs (line two)
            holder.mLineTwo.get().setText(MusicUtils.makeLabel(getContext(), R.plurals.Nsongs, album.mSongNumber));
        }
        if (Ref.alive(holder.mLineThree)) {
            // Set the album year (line three)
            holder.mLineThree.get().setText(album.mYear);
        }
    }
    if (mImageFetcher != null && Ref.alive(holder.mImage)) {
        // Asynchronously load the album images into the adapter
        mImageFetcher.loadAlbumImage(album.mArtistName, albumName, album.mAlbumId, holder.mImage.get());
    }
    // Play the album when the artwork is touched
    if (holder != null && Ref.alive(holder.mImage)) {
        initAlbumPlayOnClick(holder.mImage.get(), position - getOffset());
    }
    return convertView;
}
Also used : Album(com.andrew.apollo.model.Album) MusicViewHolder(com.andrew.apollo.ui.MusicViewHolder)

Aggregations

Album (com.andrew.apollo.model.Album)4 Cursor (android.database.Cursor)1 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1 CreateNewPlaylist (com.andrew.apollo.menu.CreateNewPlaylist)1 Artist (com.andrew.apollo.model.Artist)1 Genre (com.andrew.apollo.model.Genre)1 Playlist (com.andrew.apollo.model.Playlist)1 Song (com.andrew.apollo.model.Song)1 MusicViewHolder (com.andrew.apollo.ui.MusicViewHolder)1 DataHolder (com.andrew.apollo.ui.MusicViewHolder.DataHolder)1 ArrayList (java.util.ArrayList)1