Fix crash related to genre tab
This commit is contained in:
parent
0eff79ca1a
commit
bd9c75787d
1 changed files with 33 additions and 19 deletions
|
|
@ -19,20 +19,7 @@ public class GenreLoader {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static ArrayList<Genre> getAllGenres(@NonNull final Context context) {
|
public static ArrayList<Genre> getAllGenres(@NonNull final Context context) {
|
||||||
final String[] projection = new String[]{
|
return getGenresFromCursor(context, makeGenreCursor(context));
|
||||||
Genres._ID,
|
|
||||||
Genres.NAME
|
|
||||||
};
|
|
||||||
// Genres that actually have songs
|
|
||||||
final String selection = Genres._ID + " IN" +
|
|
||||||
" (SELECT " + Genres.Members.GENRE_ID + " FROM audio_genres_map WHERE " + Genres.Members.AUDIO_ID + " IN" +
|
|
||||||
" (SELECT " + Genres._ID + " FROM audio_meta WHERE " + SongLoader.BASE_SELECTION + "))";
|
|
||||||
|
|
||||||
final Cursor cursor = context.getContentResolver().query(
|
|
||||||
Genres.EXTERNAL_CONTENT_URI,
|
|
||||||
projection, selection, null, PreferenceUtil.getInstance(context).getGenreSortOrder());
|
|
||||||
|
|
||||||
return getGenresFromCursor(context, cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -43,11 +30,7 @@ public class GenreLoader {
|
||||||
return getSongsWithNoGenre(context);
|
return getSongsWithNoGenre(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cursor cursor = context.getContentResolver().query(
|
return SongLoader.getSongs(makeGenreSongCursor(context, genreId));
|
||||||
Genres.Members.getContentUri("external", genreId),
|
|
||||||
SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, null);
|
|
||||||
|
|
||||||
return SongLoader.getSongs(cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -107,4 +90,35 @@ public class GenreLoader {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static Cursor makeGenreSongCursor(@NonNull final Context context, int genreId) {
|
||||||
|
try {
|
||||||
|
return context.getContentResolver().query(
|
||||||
|
Genres.Members.getContentUri("external", genreId),
|
||||||
|
SongLoader.BASE_PROJECTION, SongLoader.BASE_SELECTION, null, PreferenceUtil.getInstance(context).getSongSortOrder());
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static Cursor makeGenreCursor(@NonNull final Context context) {
|
||||||
|
final String[] projection = new String[]{
|
||||||
|
Genres._ID,
|
||||||
|
Genres.NAME
|
||||||
|
};
|
||||||
|
// Genres that actually have songs
|
||||||
|
final String selection = Genres._ID + " IN" +
|
||||||
|
" (SELECT " + Genres.Members.GENRE_ID + " FROM audio_genres_map WHERE " + Genres.Members.AUDIO_ID + " IN" +
|
||||||
|
" (SELECT " + Genres._ID + " FROM audio_meta WHERE " + SongLoader.BASE_SELECTION + "))";
|
||||||
|
|
||||||
|
try {
|
||||||
|
return context.getContentResolver().query(
|
||||||
|
Genres.EXTERNAL_CONTENT_URI,
|
||||||
|
projection, selection, null, PreferenceUtil.getInstance(context).getGenreSortOrder());
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue