image: rework genre ordering

Rework genre ordering to be alphabetical based on album, but without
all of the mosaic being taken up by one artist.

With the ordering changes that were done previously, genre images
greatly differed compared to previously. May as well use this breakage
as an oppertunity to improve genre ordering. In this case, we want to
order albums alphabetically, as usual, but we also want to prevent
one artist from taking up the whole mosaic. Fix that by deduplicating
artists in the set of grouped albums.
This commit is contained in:
OxygenCobalt 2022-06-02 19:49:57 -06:00
parent 5bc5afa162
commit 490c291a14
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -56,14 +56,13 @@ class MusicKeyer : Keyer<Music> {
*/ */
class AlbumCoverFetcher class AlbumCoverFetcher
private constructor(private val context: Context, private val album: Album) : BaseFetcher() { private constructor(private val context: Context, private val album: Album) : BaseFetcher() {
override suspend fun fetch(): FetchResult? { override suspend fun fetch(): FetchResult? =
return fetchArt(context, album)?.let { stream -> fetchArt(context, album)?.let { stream ->
SourceResult( SourceResult(
source = ImageSource(stream.source().buffer(), context), source = ImageSource(stream.source().buffer(), context),
mimeType = null, mimeType = null,
dataSource = DataSource.DISK) dataSource = DataSource.DISK)
} }
}
class SongFactory : Fetcher.Factory<Song> { class SongFactory : Fetcher.Factory<Song> {
override fun create(data: Song, options: Options, imageLoader: ImageLoader): Fetcher { override fun create(data: Song, options: Options, imageLoader: ImageLoader): Fetcher {
@ -110,8 +109,21 @@ private constructor(
private val genre: Genre, private val genre: Genre,
) : BaseFetcher() { ) : BaseFetcher() {
override suspend fun fetch(): FetchResult? { override suspend fun fetch(): FetchResult? {
// Don't sort here to preserve compatibility with previous versions of this images // Genre logic is the most complicated, as we want to ensure album cover variation (i.e
val albums = genre.songs.groupBy { it.album }.keys // all four covers shouldn't be from the same artist) while also still leveraging mosaics
// whenever possible. So, if there are more than four distinct artists in a genre, make
// it so that one artist only adds one album cover to the mosaic. Otherwise, use order
// albums normally.
val artists = genre.songs.groupBy { it.album.artist.id }.keys
val albums =
Sort.ByName(true).albums(genre.songs.groupBy { it.album }.keys).run {
if (artists.size > 4) {
distinctBy { it.artist.rawName }
} else {
this
}
}
val results = albums.mapAtMost(4) { album -> fetchArt(context, album) } val results = albums.mapAtMost(4) { album -> fetchArt(context, album) }
return createMosaic(context, results, size) return createMosaic(context, results, size)
} }