use of com.naman14.timber.models.Album in project Timber by naman14.
the class AlbumSongLoader method getSongsForAlbum.
public static ArrayList<Song> getSongsForAlbum(Context context, long albumID) {
Cursor cursor = makeAlbumSongCursor(context, albumID);
ArrayList arrayList = new ArrayList();
if ((cursor != null) && (cursor.moveToFirst()))
do {
long id = cursor.getLong(0);
String title = cursor.getString(1);
String artist = cursor.getString(2);
String album = cursor.getString(3);
int duration = cursor.getInt(4);
int trackNumber = cursor.getInt(5);
/*This fixes bug where some track numbers displayed as 100 or 200*/
while (trackNumber >= 1000) {
//When error occurs the track numbers have an extra 1000 or 2000 added, so decrease till normal.
trackNumber -= 1000;
}
long artistId = cursor.getInt(6);
long albumId = albumID;
arrayList.add(new Song(id, albumId, artistId, title, artist, album, duration, trackNumber));
} while (cursor.moveToNext());
if (cursor != null)
cursor.close();
return arrayList;
}
use of com.naman14.timber.models.Album in project Timber by naman14.
the class LastAddedLoader method getLastAddedSongs.
public static List<Song> getLastAddedSongs(Context context) {
ArrayList<Song> mSongList = new ArrayList<>();
mCursor = makeLastAddedCursor(context);
if (mCursor != null && mCursor.moveToFirst()) {
do {
long id = mCursor.getLong(0);
String title = mCursor.getString(1);
String artist = mCursor.getString(2);
String album = mCursor.getString(3);
int duration = mCursor.getInt(4);
int trackNumber = mCursor.getInt(5);
long artistId = mCursor.getInt(6);
long albumId = mCursor.getLong(7);
final Song song = new Song(id, albumId, artistId, title, artist, album, duration, trackNumber);
mSongList.add(song);
} while (mCursor.moveToNext());
}
if (mCursor != null) {
mCursor.close();
mCursor = null;
}
return mSongList;
}
use of com.naman14.timber.models.Album in project Timber by naman14.
the class SongLoader method getSongFromPath.
public static Song getSongFromPath(String songPath, Context context) {
ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.DATA;
String[] selectionArgs = { songPath };
String[] projection = new String[] { "_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id" };
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor cursor = cr.query(uri, projection, selection + "=?", selectionArgs, sortOrder);
if (cursor != null && cursor.getCount() > 0) {
Song song = getSongForCursor(cursor);
cursor.close();
return song;
} else
return new Song();
}
use of com.naman14.timber.models.Album in project Timber by naman14.
the class SongLoader method getSongForCursor.
public static Song getSongForCursor(Cursor cursor) {
Song song = new Song();
if ((cursor != null) && (cursor.moveToFirst())) {
long id = cursor.getLong(0);
String title = cursor.getString(1);
String artist = cursor.getString(2);
String album = cursor.getString(3);
int duration = cursor.getInt(4);
int trackNumber = cursor.getInt(5);
long artistId = cursor.getInt(6);
long albumId = cursor.getLong(7);
song = new Song(id, albumId, artistId, title, artist, album, duration, trackNumber);
}
if (cursor != null)
cursor.close();
return song;
}
use of com.naman14.timber.models.Album in project Timber by naman14.
the class ArtistAlbumLoader method getAlbumsForArtist.
public static ArrayList<Album> getAlbumsForArtist(Context context, long artistID) {
ArrayList albumList = new ArrayList();
Cursor cursor = makeAlbumForArtistCursor(context, artistID);
if (cursor != null) {
if (cursor.moveToFirst())
do {
Album album = new Album(cursor.getLong(0), cursor.getString(1), cursor.getString(2), artistID, cursor.getInt(3), cursor.getInt(4));
albumList.add(album);
} while (cursor.moveToNext());
}
if (cursor != null)
cursor.close();
return albumList;
}
Aggregations