From 4b7fa7415ca45a3c56806b1bdccea8d1b32310df Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Sun, 5 Dec 2021 20:30:35 -0700 Subject: [PATCH] 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. --- .../java/org/oxycblt/auxio/coil/CoilUtils.kt | 25 +++++++++++-------- .../oxycblt/auxio/widgets/WidgetProvider.kt | 8 +++--- .../main/res/drawable/ui_rounded_cutout.xml | 5 ++++ 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable/ui_rounded_cutout.xml diff --git a/app/src/main/java/org/oxycblt/auxio/coil/CoilUtils.kt b/app/src/main/java/org/oxycblt/auxio/coil/CoilUtils.kt index eab96984b..3e06426e3 100644 --- a/app/src/main/java/org/oxycblt/auxio/coil/CoilUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/coil/CoilUtils.kt @@ -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 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) } } diff --git a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt index 5e490b398..43f72c41b 100644 --- a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt +++ b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetProvider.kt @@ -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( diff --git a/app/src/main/res/drawable/ui_rounded_cutout.xml b/app/src/main/res/drawable/ui_rounded_cutout.xml new file mode 100644 index 000000000..00d969fd3 --- /dev/null +++ b/app/src/main/res/drawable/ui_rounded_cutout.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file