Search in sources :

Example 1 with Playlist

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

the class PlaylistLoader method loadInBackground.

@Override
public List<Playlist> loadInBackground() {
    // Add the default playlists to the adapter
    List<Playlist> mPlaylistList = makeDefaultPlaylists();
    // Create the Cursor
    Cursor mCursor = makeCursor(getContext());
    // Gather the data
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the playlist id
            final long id = mCursor.getLong(0);
            // Copy the playlist name
            final String name = mCursor.getString(1);
            // Create a new playlist
            final Playlist playlist = new Playlist(id, name);
            // Add everything up
            mPlaylistList.add(playlist);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    return mPlaylistList;
}
Also used : Playlist(com.andrew.apollo.model.Playlist) Cursor(android.database.Cursor)

Example 2 with Playlist

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

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

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

the class MusicUtils method getPlaylists.

public static List<Playlist> getPlaylists(final Context context) {
    final List<Playlist> result = new ArrayList<>();
    final ContentResolver resolver = context.getContentResolver();
    final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.PlaylistsColumns.NAME };
    try {
        final Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, null, null, null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    result.add(new Playlist(cursor.getLong(0), cursor.getString(1)));
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
    } catch (Throwable e) {
        LOG.error("Could not fetch playlists", e);
    }
    return result;
}
Also used : Playlist(com.andrew.apollo.model.Playlist) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 5 with Playlist

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

the class PlaylistLoader method makeDefaultPlaylists.

/* Adds the favorites and last added playlists */
private List<Playlist> makeDefaultPlaylists() {
    final Resources resources = getContext().getResources();
    ArrayList<Playlist> mPlaylistList = new ArrayList<>();
    /* New Empty list */
    final Playlist newPlaylist = new Playlist(NEW_PLAYLIST_ID, resources.getString(R.string.new_empty_playlist));
    mPlaylistList.add(newPlaylist);
    /* Favorites list */
    final Playlist favorites = new Playlist(FAVORITE_PLAYLIST_ID, resources.getString(R.string.playlist_favorites));
    mPlaylistList.add(favorites);
    /* Last added list */
    final Playlist lastAdded = new Playlist(LAST_ADDED_PLAYLIST_ID, resources.getString(R.string.playlist_last_added));
    mPlaylistList.add(lastAdded);
    return mPlaylistList;
}
Also used : Playlist(com.andrew.apollo.model.Playlist) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources)

Aggregations

Playlist (com.andrew.apollo.model.Playlist)6 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 ContentResolver (android.content.ContentResolver)1 Resources (android.content.res.Resources)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 Artist (com.andrew.apollo.model.Artist)1 Genre (com.andrew.apollo.model.Genre)1 Song (com.andrew.apollo.model.Song)1 DataHolder (com.andrew.apollo.ui.MusicViewHolder.DataHolder)1 MenuAction (com.frostwire.android.gui.views.MenuAction)1