image: revert back to dynamic corner radii

This commit is contained in:
Alexander Capehart
2026-01-24 15:03:18 -07:00
parent 022244f94e
commit 7da1fe465d
5 changed files with 29 additions and 18 deletions
@@ -52,6 +52,7 @@ import com.google.android.material.shape.RelativeCornerSize
import com.google.android.material.shape.ShapeAppearanceModel import com.google.android.material.shape.ShapeAppearanceModel
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.min
import kotlin.random.Random import kotlin.random.Random
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.image.coil.GalleryCoverCollection import org.oxycblt.auxio.image.coil.GalleryCoverCollection
@@ -393,7 +394,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
bindImpl( bindImpl(
SmatteringCoverCollection( SmatteringCoverCollection(
artist.covers, artist.covers,
uiSettings.roundMode, coverCollectionCornerRatio(),
coverCollectionFanAngle(uidSeed), coverCollectionFanAngle(uidSeed),
coverCollectionTiltAngle(uidSeed), coverCollectionTiltAngle(uidSeed),
coverCollectionZOrder(uidSeed), coverCollectionZOrder(uidSeed),
@@ -415,7 +416,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
bindImpl( bindImpl(
GalleryCoverCollection( GalleryCoverCollection(
genre.covers, genre.covers,
uiSettings.roundMode, coverCollectionCornerRatio(),
coverCollectionZOrder(genre.uid.hashCode()), coverCollectionZOrder(genre.uid.hashCode()),
), ),
context.getString(R.string.desc_genre_image, genre.name), context.getString(R.string.desc_genre_image, genre.name),
@@ -433,7 +434,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
bindImpl( bindImpl(
StackCoverCollection( StackCoverCollection(
playlist.covers, playlist.covers,
uiSettings.roundMode, coverCollectionCornerRatio(),
coverCollectionZOrder(playlist.uid.hashCode()), coverCollectionZOrder(playlist.uid.hashCode()),
), ),
context.getString(R.string.desc_playlist_image, playlist.name), context.getString(R.string.desc_playlist_image, playlist.name),
@@ -485,6 +486,22 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
contentDescription = desc contentDescription = desc
} }
private fun coverCollectionCornerRatio(): Float {
if (!uiSettings.roundMode) {
return 0f
}
val bounds = resolveCornerBounds() ?: return 0f
val cornerRadiusPx = shapeAppearance.topLeftCornerSize.getCornerSize(bounds)
if (cornerRadiusPx <= 0f) {
return 0f
}
val minSize = min(bounds.width(), bounds.height())
if (minSize <= 0f) {
return 0f
}
return cornerRadiusPx / minSize
}
private fun coverCollectionZOrder(uidSeed: Int): List<Int> { private fun coverCollectionZOrder(uidSeed: Int): List<Int> {
val order = mutableListOf(0, 1, 2, 3) val order = mutableListOf(0, 1, 2, 3)
order.shuffle(Random(uidSeed.toLong())) order.shuffle(Random(uidSeed.toLong()))
@@ -21,7 +21,6 @@ package org.oxycblt.auxio.image.coil
internal object ComposeCoverDefaults { internal object ComposeCoverDefaults {
const val CARD_SIZE_PERCENT = 0.60f const val CARD_SIZE_PERCENT = 0.60f
const val GAP_RATIO = 0.04f const val GAP_RATIO = 0.04f
const val CORNER_RATIO = 0.08f
const val MIN_GAP_CORNER_RATIO = 0.35f const val MIN_GAP_CORNER_RATIO = 0.35f
const val MAX_CORNER_RATIO = 0.15f const val MAX_CORNER_RATIO = 0.15f
} }
@@ -62,7 +62,7 @@ import org.oxycblt.musikr.covers.CoverCollection
data class GalleryCoverCollection( data class GalleryCoverCollection(
val covers: CoverCollection, val covers: CoverCollection,
val useRoundedCorners: Boolean, val cornerRadiusRatio: Float,
val zOrder: List<Int>, val zOrder: List<Int>,
) )
@@ -101,8 +101,7 @@ private constructor(
if (bitmaps.size != streams.size) { if (bitmaps.size != streams.size) {
return null return null
} }
val cornerRadiusPx = val cornerRadiusPx = outputSize * data.cornerRadiusRatio
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
val collageBitmap = val collageBitmap =
CollageGenerator.generate( CollageGenerator.generate(
bitmaps, bitmaps,
@@ -320,8 +319,7 @@ private constructor(
class Keyer @Inject constructor() : CoilKeyer<GalleryCoverCollection> { class Keyer @Inject constructor() : CoilKeyer<GalleryCoverCollection> {
override fun key(data: GalleryCoverCollection, options: Options): String { override fun key(data: GalleryCoverCollection, options: Options): String {
val config = val config = "${data.cornerRadiusRatio}.${data.zOrder.joinToString(".")}"
"${if (data.useRoundedCorners) "r" else "s"}.${data.zOrder.joinToString(".")}"
return "g:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config" return "g:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config"
} }
} }
@@ -65,7 +65,7 @@ private const val OUTSET_PERCENT = 0.08f
data class SmatteringCoverCollection( data class SmatteringCoverCollection(
val covers: CoverCollection, val covers: CoverCollection,
val useRoundedCorners: Boolean, val cornerRadiusRatio: Float,
val fanAngleDeg: Float, val fanAngleDeg: Float,
val tiltAngleDeg: Float, val tiltAngleDeg: Float,
val zOrder: List<Int>, val zOrder: List<Int>,
@@ -106,8 +106,7 @@ private constructor(
if (bitmaps.size != streams.size) { if (bitmaps.size != streams.size) {
return null return null
} }
val cornerRadiusPx = val cornerRadiusPx = outputSize * data.cornerRadiusRatio
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
val collageBitmap = val collageBitmap =
StackCollageGenerator.generate( StackCollageGenerator.generate(
bitmaps, bitmaps,
@@ -325,7 +324,7 @@ private constructor(
class Keyer @Inject constructor() : CoilKeyer<SmatteringCoverCollection> { class Keyer @Inject constructor() : CoilKeyer<SmatteringCoverCollection> {
override fun key(data: SmatteringCoverCollection, options: Options): String { override fun key(data: SmatteringCoverCollection, options: Options): String {
val config = val config =
"${if (data.useRoundedCorners) "r" else "s"}.${data.fanAngleDeg}.${data.tiltAngleDeg}.${data.zOrder.joinToString(".")}" "${data.cornerRadiusRatio}.${data.fanAngleDeg}.${data.tiltAngleDeg}.${data.zOrder.joinToString(".")}"
return "m:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config" return "m:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config"
} }
} }
@@ -62,7 +62,7 @@ import org.oxycblt.musikr.covers.CoverCollection
data class StackCoverCollection( data class StackCoverCollection(
val covers: CoverCollection, val covers: CoverCollection,
val useRoundedCorners: Boolean, val cornerRadiusRatio: Float,
val zOrder: List<Int>, val zOrder: List<Int>,
) )
@@ -101,8 +101,7 @@ private constructor(
if (bitmaps.size != streams.size) { if (bitmaps.size != streams.size) {
return null return null
} }
val cornerRadiusPx = val cornerRadiusPx = outputSize * data.cornerRadiusRatio
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
val stackBitmap = val stackBitmap =
StackGenerator.generate( StackGenerator.generate(
bitmaps, bitmaps,
@@ -303,8 +302,7 @@ private constructor(
class Keyer @Inject constructor() : CoilKeyer<StackCoverCollection> { class Keyer @Inject constructor() : CoilKeyer<StackCoverCollection> {
override fun key(data: StackCoverCollection, options: Options): String { override fun key(data: StackCoverCollection, options: Options): String {
val config = val config = "${data.cornerRadiusRatio}.${data.zOrder.joinToString(".")}"
"${if (data.useRoundedCorners) "r" else "s"}.${data.zOrder.joinToString(".")}"
return "s:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config" return "s:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config"
} }
} }