diff --git a/src/ch/blinkenlights/android/medialibrary/MediaLibraryBackend.java b/src/ch/blinkenlights/android/medialibrary/MediaLibraryBackend.java index 03fe022c..bdd59ee6 100644 --- a/src/ch/blinkenlights/android/medialibrary/MediaLibraryBackend.java +++ b/src/ch/blinkenlights/android/medialibrary/MediaLibraryBackend.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Adrian Ulrich + * Copyright (C) 2016-2017 Adrian Ulrich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -218,6 +218,19 @@ public class MediaLibraryBackend extends SQLiteOpenHelper { } } + if (MediaLibrary.VIEW_ALBUMS_ARTISTS.equals(table)) { + // looking up artists by albums will magically return every album where this + // artist has at least one item (while still using the primary_artist_id as the artist key) + Matcher artistMatch = sQueryMatchArtistSearch.matcher(selection); + if (artistMatch.matches()) { + selection = artistMatch.group(1); + final String artistId = artistMatch.group(2); + selection += MediaLibrary.SongColumns._ID+" IN (SELECT DISTINCT "+MediaLibrary.SongColumns.ALBUM_ID+" FROM "+MediaLibrary.TABLE_SONGS+" WHERE " + + MediaLibrary.SongColumns._ID+" IN (SELECT "+MediaLibrary.ContributorSongColumns.SONG_ID+" FROM "+MediaLibrary.TABLE_CONTRIBUTORS_SONGS+" WHERE " + + MediaLibrary.ContributorSongColumns.ROLE+"=0 AND "+MediaLibrary.ContributorSongColumns._CONTRIBUTOR_ID+"="+artistId+"))"; + } + } + // Genre queries are a special beast: 'optimize' all of them Matcher genreMatch = sQueryMatchGenreSearch.matcher(selection); if (genreMatch.matches()) {