/*
* Copyright (C) 2015 Naman Dwivedi
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package com.naman14.timber.dataloaders;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import com.naman14.timber.models.Album;
import java.util.ArrayList;
public class ArtistAlbumLoader {
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;
}
public static Cursor makeAlbumForArtistCursor(Context context, long artistID) {
if (artistID == -1)
return null;
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Artists.Albums.getContentUri("external", artistID), new String[]{"_id", "album", "artist", "numsongs", "minyear"}, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
return cursor;
}
}