Better way of getting songs with no genre
This commit is contained in:
parent
944b5fc1fa
commit
f51076eeb3
2 changed files with 5 additions and 36 deletions
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore.Audio.Genres;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
|
@ -22,6 +23,7 @@ public class GenreLoader {
|
|||
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 + "))";
|
||||
|
|
@ -76,30 +78,9 @@ public class GenreLoader {
|
|||
|
||||
@NonNull
|
||||
private static ArrayList<Song> getSongsWithNoGenre(@NonNull final Context context) {
|
||||
final Cursor cursor = makeAllSongsWithGenreCursor(context);
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
final int[] songIds = getSongIdsFromCursor(cursor);
|
||||
if (songIds.length > 0) {
|
||||
songs = SongLoader.getSongsNotIn(context, songIds);
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
private static int[] getSongIdsFromCursor(@Nullable final Cursor cursor) {
|
||||
if (cursor == null) {
|
||||
return new int[]{};
|
||||
}
|
||||
|
||||
int[] songIds = new int[cursor.getCount()];
|
||||
if (cursor.moveToFirst()) {
|
||||
int i = 0;
|
||||
do {
|
||||
songIds[i] = cursor.getInt(0);
|
||||
i++;
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
return songIds;
|
||||
String selection = BaseColumns._ID + " NOT IN " +
|
||||
"(SELECT " + Genres.Members.AUDIO_ID + " FROM audio_genres_map)";
|
||||
return SongLoader.getSongs(SongLoader.makeSongCursor(context, selection, null));
|
||||
}
|
||||
|
||||
private static boolean hasSongsWithNoGenre(@NonNull final Context context) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import com.kabouzeid.gramophone.model.Song;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -45,13 +44,6 @@ public class SongLoader {
|
|||
return getSongs(cursor);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ArrayList<Song> getSongsNotIn(@NonNull final Context context, final int[] query) {
|
||||
final String ids = convertArrayToQueryList(query);
|
||||
Cursor cursor = makeSongCursor(context, AudioColumns._ID + " NOT IN " + ids, null);
|
||||
return getSongs(cursor);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Song getSong(@NonNull final Context context, final int queryId) {
|
||||
Cursor cursor = makeSongCursor(context, AudioColumns._ID + "=?", new String[]{String.valueOf(queryId)});
|
||||
|
|
@ -122,8 +114,4 @@ public class SongLoader {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String convertArrayToQueryList(final int[] array) {
|
||||
return "(" + Arrays.toString(array).replaceAll("\\[|\\]|\\s", "") + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue