coil: change album cover rounding method

Forgot that coil's RoundedCornerTransformation is dependent on the
resolution of the image, resulting in inconsistent rounded corners.
Fix this by just doing the plain clipToOutline to round album covers.
This commit is contained in:
OxygenCobalt 2021-12-05 20:30:35 -07:00
parent 637bcccd51
commit 4b7fa7415c
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 24 additions and 14 deletions

View file

@ -29,7 +29,6 @@ import coil.imageLoader
import coil.load
import coil.request.ImageRequest
import coil.size.OriginalSize
import coil.transform.RoundedCornersTransformation
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.Album
import org.oxycblt.auxio.music.Artist
@ -67,16 +66,22 @@ fun ImageView.bindGenreImage(genre: Genre?) = load(genre, R.drawable.ic_genre)
fun <T : Music> ImageView.load(music: T?, @DrawableRes error: Int) {
dispose()
// We don't round album covers by default as it descecrates album artwork, but we do provide
// an option if one wants it.
// As for why we use clipToOutline instead of coil's RoundedCornersTransformation, the transform
// uses the dimensions of the image to create the corners, which results in inconsistent corners
// across loaded cover art.
val settingsManager = SettingsManager.getInstance()
if (settingsManager.roundCovers && background == null) {
setBackgroundResource(R.drawable.ui_rounded_cutout)
clipToOutline = true
} else if (!settingsManager.roundCovers && background != null) {
background = null
clipToOutline = false
}
load(music) {
// Round out the corners if enabled
// We don't do this by default because it's ugly and desecrates album artwork.
val settingsManager = SettingsManager.getInstance()
if (settingsManager.roundCovers) {
val radius = resources.getDimension(R.dimen.spacing_small)
transformations(RoundedCornersTransformation(radius))
}
error(error)
}
}

View file

@ -89,8 +89,6 @@ class WidgetProvider : AppWidgetProvider() {
// Load our image so that it takes up the phone screen. This allows
// us to get stable rounded corners for every single widget image. This probably
// sacrifices quality in some way, but it's really the only good option.
// Hey google, maybe allow us to use our own views in widgets next time. That would
// be nice.
val metrics = context.resources.displayMetrics
val imageSize = min(metrics.widthPixels, metrics.heightPixels)
@ -102,8 +100,10 @@ class WidgetProvider : AppWidgetProvider() {
onSuccess = { onDone(it.toBitmap()) }
)
// If we are on Android 12 or higher, round out the album cover so that the widget is
// cohesive. I really don't like this, but whatever.
// If we are on Android 12 or higher, round out the album cover.
// This is simply to maintain stylistic cohesion with other widgets.
// Here, we actually have to use RoundedCornersTransformation since the way
// we get a 1:1 aspect ratio image results in clipToOutline not working well.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val transform = RoundedCornersTransformation(
context.resources.getDimensionPixelSize(

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/spacing_small" />
</shape>