Search in sources :

Example 1 with Artist

use of com.andrew.apollo.model.Artist 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 Artist

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

the class ArtistLoader method loadInBackground.

/**
 * {@inheritDoc}
 */
@Override
public List<Artist> loadInBackground() {
    ArrayList<Artist> mArtistsList = new ArrayList<>();
    // Create the Cursor
    Cursor mCursor = makeCursor(getContext());
    // Gather the data
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the artist id
            final long id = mCursor.getLong(0);
            // Copy the artist name
            final String artistName = mCursor.getString(1);
            // Copy the number of albums
            final int albumCount = mCursor.getInt(2);
            // Copy the number of songs
            final int songCount = mCursor.getInt(3);
            // Create a new artist
            final Artist artist = new Artist(id, artistName, songCount, albumCount);
            // Add everything up
            mArtistsList.add(artist);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    return mArtistsList;
}
Also used : Artist(com.andrew.apollo.model.Artist) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 3 with Artist

use of com.andrew.apollo.model.Artist 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)

Aggregations

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