From 490c291a14ef4e807415693027fc449e16d51a74 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Thu, 2 Jun 2022 19:49:57 -0600 Subject: [PATCH] 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. --- .../org/oxycblt/auxio/image/Components.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/image/Components.kt b/app/src/main/java/org/oxycblt/auxio/image/Components.kt index e739b3f00..075180fc1 100644 --- a/app/src/main/java/org/oxycblt/auxio/image/Components.kt +++ b/app/src/main/java/org/oxycblt/auxio/image/Components.kt @@ -56,14 +56,13 @@ class MusicKeyer : Keyer { */ class AlbumCoverFetcher private constructor(private val context: Context, private val album: Album) : BaseFetcher() { - override suspend fun fetch(): FetchResult? { - return fetchArt(context, album)?.let { stream -> + override suspend fun fetch(): FetchResult? = + fetchArt(context, album)?.let { stream -> SourceResult( source = ImageSource(stream.source().buffer(), context), mimeType = null, dataSource = DataSource.DISK) } - } class SongFactory : Fetcher.Factory { override fun create(data: Song, options: Options, imageLoader: ImageLoader): Fetcher { @@ -110,8 +109,21 @@ private constructor( private val genre: Genre, ) : BaseFetcher() { override suspend fun fetch(): FetchResult? { - // Don't sort here to preserve compatibility with previous versions of this images - val albums = genre.songs.groupBy { it.album }.keys + // Genre logic is the most complicated, as we want to ensure album cover variation (i.e + // 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) } return createMosaic(context, results, size) }