Search in sources :

Example 6 with Album

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;
}
Also used : Song(com.naman14.timber.models.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with Album

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;
}
Also used : Song(com.naman14.timber.models.Song) ArrayList(java.util.ArrayList)

Example 8 with Album

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();
}
Also used : Song(com.naman14.timber.models.Song) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 9 with Album

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;
}
Also used : Song(com.naman14.timber.models.Song)

Example 10 with Album

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;
}
Also used : ArrayList(java.util.ArrayList) Album(com.naman14.timber.models.Album) Cursor(android.database.Cursor)

Aggregations

Song (com.naman14.timber.models.Song)8 ArrayList (java.util.ArrayList)6 Cursor (android.database.Cursor)4 Album (com.naman14.timber.models.Album)4 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 TargetApi (android.annotation.TargetApi)1 ContentResolver (android.content.ContentResolver)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 Palette (android.support.v7.graphics.Palette)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 AlbumSongsAdapter (com.naman14.timber.adapters.AlbumSongsAdapter)1 ArtistInfoListener (com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)1 ArtistQuery (com.naman14.timber.lastfmapi.models.ArtistQuery)1