image: fix cover image query config

This commit is contained in:
Alexander Capehart
2026-02-16 11:57:32 -07:00
parent 607f34952a
commit 0ff344973a
@@ -37,6 +37,7 @@ import androidx.annotation.DrawableRes
import androidx.annotation.Px import androidx.annotation.Px
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.children import androidx.core.view.children
import androidx.core.view.doOnLayout
import androidx.core.view.isEmpty import androidx.core.view.isEmpty
import androidx.core.view.updateMarginsRelative import androidx.core.view.updateMarginsRelative
import androidx.core.widget.ImageViewCompat import androidx.core.widget.ImageViewCompat
@@ -352,7 +353,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
*/ */
fun bind(song: Song) = fun bind(song: Song) =
bindImpl( bindImpl(
song.cover, { song.cover },
context.getString(R.string.desc_album_cover, song.album.name), context.getString(R.string.desc_album_cover, song.album.name),
R.drawable.ic_album_24, R.drawable.ic_album_24,
) )
@@ -363,19 +364,18 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
* @param album The [Album] to bind to the view. * @param album The [Album] to bind to the view.
*/ */
fun bind(album: Album) { fun bind(album: Album) {
// Generally it's not desirable for many albums to show all of their covers since unlike bindImpl(
// artists/genres they don't really change. {
// Therefore just pick the most "prominent" cover (the one with the most instances) and load // Generally it's not desirable for many albums to show all of their covers since
// that like you would a song instead. // unlike artists/genres they don't really change. Therefore just pick the most
val mostProminentCover = // "prominent" cover (the one with the most instances) and load that like you
// would a song instead.
album.covers.covers album.covers.covers
.groupBy { it.id } .groupBy { it.id }
.maxByOrNull { it.value.size } .maxByOrNull { it.value.size }
?.value ?.value
?.firstOrNull() ?.firstOrNull()
},
bindImpl(
mostProminentCover,
context.getString(R.string.desc_album_cover, album.name), context.getString(R.string.desc_album_cover, album.name),
R.drawable.ic_album_24, R.drawable.ic_album_24,
) )
@@ -392,6 +392,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
// stack of vinyl. // stack of vinyl.
val uidSeed = artist.uid.toString().hashCode() val uidSeed = artist.uid.toString().hashCode()
bindImpl( bindImpl(
{
SmatteringCoverCollection( SmatteringCoverCollection(
artist.covers, artist.covers,
coverCollectionCornerRatio(), coverCollectionCornerRatio(),
@@ -399,7 +400,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
coverCollectionTiltAngle(uidSeed), coverCollectionTiltAngle(uidSeed),
coverCollectionZOrder(uidSeed), coverCollectionZOrder(uidSeed),
coverCollectionBackgroundColor(), coverCollectionBackgroundColor(),
), )
},
context.getString(R.string.desc_artist_image, artist.name), context.getString(R.string.desc_artist_image, artist.name),
R.drawable.ic_artist_24, R.drawable.ic_artist_24,
useCircleCrop = true, useCircleCrop = true,
@@ -415,12 +417,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
// Genres are organized like a "gallery" of various covers that overlap eachother, // Genres are organized like a "gallery" of various covers that overlap eachother,
// as if they were framed on a wall. // as if they were framed on a wall.
bindImpl( bindImpl(
{
GalleryCoverCollection( GalleryCoverCollection(
genre.covers, genre.covers,
coverCollectionCornerRatio(), coverCollectionCornerRatio(),
coverCollectionZOrder(genre.uid.toString().hashCode()), coverCollectionZOrder(genre.uid.toString().hashCode()),
coverCollectionBackgroundColor(), coverCollectionBackgroundColor(),
), )
},
context.getString(R.string.desc_genre_image, genre.name), context.getString(R.string.desc_genre_image, genre.name),
R.drawable.ic_genre_24, R.drawable.ic_genre_24,
) )
@@ -434,12 +438,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
// Playlists are organized in a straight diagonal stack to give the appearance of an // Playlists are organized in a straight diagonal stack to give the appearance of an
// "orderly" pile of covers. // "orderly" pile of covers.
bindImpl( bindImpl(
{
StackCoverCollection( StackCoverCollection(
playlist.covers, playlist.covers,
coverCollectionCornerRatio(), coverCollectionCornerRatio(),
coverCollectionZOrder(playlist.uid.toString().hashCode()), coverCollectionZOrder(playlist.uid.toString().hashCode()),
coverCollectionBackgroundColor(), coverCollectionBackgroundColor(),
), )
},
context.getString(R.string.desc_playlist_image, playlist.name), context.getString(R.string.desc_playlist_image, playlist.name),
R.drawable.ic_playlist_24, R.drawable.ic_playlist_24,
) )
@@ -452,20 +458,35 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
* @param errorRes The resource of the error drawable to use if the cover cannot be loaded. * @param errorRes The resource of the error drawable to use if the cover cannot be loaded.
*/ */
fun bind(songs: List<Song>, desc: String, @DrawableRes errorRes: Int) = fun bind(songs: List<Song>, desc: String, @DrawableRes errorRes: Int) =
bindImpl(CoverCollection.from(songs.mapNotNull { it.cover }), desc, errorRes) bindImpl({ CoverCollection.from(songs.mapNotNull { it.cover }) }, desc, errorRes)
private fun bindImpl( private fun bindImpl(
cover: Any?, cover: () -> Any?,
desc: String, desc: String,
@DrawableRes errorRes: Int, @DrawableRes errorRes: Int,
useCircleCrop: Boolean = false, useCircleCrop: Boolean = false,
configure: (ImageRequest.Builder) -> ImageRequest.Builder = { it }, configure: (ImageRequest.Builder) -> ImageRequest.Builder = { it },
deferIfNeeded: Boolean = true,
) { ) {
updateShapeAppearance(useCircleCrop) updateShapeAppearance(useCircleCrop)
val cornerBounds = resolveCornerBounds()
if (deferIfNeeded && cornerBounds == null && (uiSettings.roundMode || useCircleCrop)) {
doOnLayout {
bindImpl(
cover = cover,
desc = desc,
errorRes = errorRes,
useCircleCrop = useCircleCrop,
configure = configure,
deferIfNeeded = false,
)
}
return
}
val request = val request =
configure( configure(
ImageRequest.Builder(context) ImageRequest.Builder(context)
.data(cover) .data(cover())
.error( .error(
StyledDrawable(context, context.getDrawableCompat(errorRes), iconSize) StyledDrawable(context, context.getDrawableCompat(errorRes), iconSize)
.asImage() .asImage()
@@ -473,7 +494,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
.target(image) .target(image)
) )
val cornerBounds = resolveCornerBounds()
val cornerRadius = val cornerRadius =
cornerBounds?.let { currentShapeAppearance.topLeftCornerSize.getCornerSize(it) } ?: 0f cornerBounds?.let { currentShapeAppearance.topLeftCornerSize.getCornerSize(it) } ?: 0f
val cornersTransformation = RoundedRectTransformation(cornerRadius) val cornersTransformation = RoundedRectTransformation(cornerRadius)