Timber
Timber copied to clipboard
[Feature Request] Browse by Genre
It seems that the only semi-decent app that has Genre sorting is Google Play Music, and that isn't open source.
Would love to be able to listen to a category of music instead of needing to make playlists and the sort.
Thank you!
public class GenresLoader {
public static Genres getGenres(Cursor cursor) {
Genres genres = new Genres();
if (cursor != null) {
if (cursor.moveToFirst())
genres = new Genres(cursor.getInt(0),cursor.getString(1));
}
if (cursor != null)
cursor.close();
return genres;
}
public static List<Genres> getGenresForCursor(Cursor cursor) {
ArrayList arrayList = new ArrayList();
if ((cursor != null) && (cursor.moveToFirst()))
do {
arrayList.add(new Genres(cursor.getInt(0),cursor.getString(1)));
}
while (cursor.moveToNext());
if (cursor != null)
cursor.close();
return arrayList;
}
public static List<Genres> getAllGenres(Context context) {
return getGenresForCursor(makeGenresCursor(context, null, null));
}
public static Genres getGenres(Context context, long id) {
return getGenres(makeGenresCursor(context, "_id=?", new String[]{String.valueOf(id)}));
}
public static List<Genres> getArtists(Context context, String paramString, int limit) {
List<Genres> result = getGenresForCursor(makeGenresCursor(context, "genres LIKE ?", new String[]{paramString + "%"}));
if (result.size() < limit) {
result.addAll(getGenresForCursor(makeGenresCursor(context, "genres LIKE ?", new String[]{"%_" + paramString + "%"})));
}
return result.size() < limit ? result : result.subList(0, limit);
}
public static Cursor makeGenresCursor(Context context, String selection, String[] paramArrayOfString) {
final String genresSortOrder = PreferencesUtility.getInstance(context).getGenresSortOrder();
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, new String[]{"_id","name"}, selection, paramArrayOfString, null);
return cursor;
}
}
Enjoy and complete the task