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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations