Search in sources :

Example 6 with Song

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

the class SongLoader method loadInBackground.

/**
 * {@inheritDoc}
 */
@Override
public List<Song> loadInBackground() {
    ArrayList<Song> mSongList = new ArrayList<>();
    // Create the Cursor
    Cursor mCursor;
    try {
        mCursor = makeCursor(getContext());
    } catch (Throwable ignored) {
        LOGGER.error("SongLoader.loadInBackground(): " + ignored.getMessage(), ignored);
        return Collections.emptyList();
    }
    if (mCursor == null) {
        // LOGGER.warn("loadInBackground() - cursor == null, returning empty list.");
        return Collections.emptyList();
    }
    // Gather the data
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the song Id
            final long id = mCursor.getLong(0);
            // Copy the song name
            final String songName = mCursor.getString(1);
            // Copy the artist name
            final String artist = mCursor.getString(2);
            // Copy the album name
            final String album = mCursor.getString(3);
            // Copy the duration (Not available for all song Cursors, like on FavoritesLoader's)
            long duration = -1;
            int durationInSecs = -1;
            try {
                duration = mCursor.getLong(4);
                durationInSecs = (int) duration / 1000;
            } catch (Throwable ignored) {
                LOGGER.error("SongLoader.loadInBackground(): " + ignored.getMessage(), ignored);
            }
            // Create a new song
            final Song song = new Song(id, songName, artist, album, durationInSecs);
            // Add everything up
            mSongList.add(song);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    // LOGGER.info("loadInBackground() done (" + mSongList.size() + " songs)");
    return mSongList;
}
Also used : Song(com.andrew.apollo.model.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with Song

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

the class ApolloFragment method onRemoveFromPlaylist.

private boolean onRemoveFromPlaylist() {
    mAdapter.remove(mItem);
    mAdapter.notifyDataSetChanged();
    if (mItem instanceof Song) {
        Song song = (Song) mItem;
        MusicUtils.removeFromPlaylist(getActivity(), song.mSongId, mPlaylistId);
        restartLoader(true);
        return true;
    }
    return false;
}
Also used : Song(com.andrew.apollo.model.Song)

Example 8 with Song

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

the class ApolloFragment method onAddToFavorites.

private void onAddToFavorites() {
    if (mSongList != null) {
        int added = 0;
        for (Long songId : mSongList) {
            try {
                final Song song = MusicUtils.getSong(getActivity(), songId);
                if (song != null) {
                    FavoritesStore.getInstance(getActivity()).addSongId(songId, song.mSongName, song.mAlbumName, song.mArtistName);
                    added++;
                }
            } catch (Throwable ignored) {
                ignored.printStackTrace();
            }
        }
        if (added > 0) {
            final String message = getResources().getQuantityString(R.plurals.NNNtrackstoplaylist, added, added);
            AppMsg.makeText(getActivity(), message, AppMsg.STYLE_CONFIRM).show();
        }
    } else if (mSelectedId != -1) {
        FavoritesStore.getInstance(getActivity()).addSongId(mSelectedId, mSongName, mAlbumName, mArtistName);
    }
}
Also used : Song(com.andrew.apollo.model.Song)

Example 9 with Song

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

the class FavoritesLoader method loadInBackground.

@Override
public List<Song> loadInBackground() {
    Cursor mCursor = makeFavoritesCursor(getContext());
    ArrayList<Song> mSongList = new ArrayList<>();
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the song Id
            final long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(FavoriteColumns.ID));
            // Copy the song name
            final String songName = mCursor.getString(mCursor.getColumnIndexOrThrow(FavoriteColumns.SONGNAME));
            // Copy the artist name
            final String artist = mCursor.getString(mCursor.getColumnIndexOrThrow(FavoriteColumns.ARTISTNAME));
            // Copy the album name
            final String album = mCursor.getString(mCursor.getColumnIndexOrThrow(FavoriteColumns.ALBUMNAME));
            // Create a new song
            final Song song = new Song(id, songName, artist, album, -1);
            // Add everything up
            mSongList.add(song);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    return mSongList;
}
Also used : Song(com.andrew.apollo.model.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 10 with Song

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

the class PlaylistSongLoader method loadInBackground.

@Override
public List<Song> loadInBackground() {
    final ArrayList<Song> mSongList = new ArrayList<>();
    Cursor mCursor = makePlaylistSongCursor(getContext(), mPlaylistID);
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the song Id
            final long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID));
            // Copy the song name
            final String songName = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.TITLE));
            // Copy the artist name
            final String artist = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ARTIST));
            // Copy the album name
            final String album = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));
            // Copy the duration
            final long duration = mCursor.getLong(mCursor.getColumnIndexOrThrow(AudioColumns.DURATION));
            // Convert the duration into seconds
            final int durationInSecs = (int) duration / 1000;
            // Create a new song
            final Song song = new Song(id, songName, artist, album, durationInSecs);
            // Add everything up
            mSongList.add(song);
        } while (mCursor.moveToNext());
    }
    if (mCursor != null) {
        mCursor.close();
    }
    return mSongList;
}
Also used : Song(com.andrew.apollo.model.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Song (com.andrew.apollo.model.Song)10 Cursor (android.database.Cursor)5 ArrayList (java.util.ArrayList)4 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 Playlist (com.andrew.apollo.model.Playlist)1 MusicViewHolder (com.andrew.apollo.ui.MusicViewHolder)1 DataHolder (com.andrew.apollo.ui.MusicViewHolder.DataHolder)1