image: revert back to dynamic corner radii
This commit is contained in:
@@ -52,6 +52,7 @@ import com.google.android.material.shape.RelativeCornerSize
|
||||
import com.google.android.material.shape.ShapeAppearanceModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
import kotlin.random.Random
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.image.coil.GalleryCoverCollection
|
||||
@@ -393,7 +394,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
bindImpl(
|
||||
SmatteringCoverCollection(
|
||||
artist.covers,
|
||||
uiSettings.roundMode,
|
||||
coverCollectionCornerRatio(),
|
||||
coverCollectionFanAngle(uidSeed),
|
||||
coverCollectionTiltAngle(uidSeed),
|
||||
coverCollectionZOrder(uidSeed),
|
||||
@@ -415,7 +416,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
bindImpl(
|
||||
GalleryCoverCollection(
|
||||
genre.covers,
|
||||
uiSettings.roundMode,
|
||||
coverCollectionCornerRatio(),
|
||||
coverCollectionZOrder(genre.uid.hashCode()),
|
||||
),
|
||||
context.getString(R.string.desc_genre_image, genre.name),
|
||||
@@ -433,7 +434,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
bindImpl(
|
||||
StackCoverCollection(
|
||||
playlist.covers,
|
||||
uiSettings.roundMode,
|
||||
coverCollectionCornerRatio(),
|
||||
coverCollectionZOrder(playlist.uid.hashCode()),
|
||||
),
|
||||
context.getString(R.string.desc_playlist_image, playlist.name),
|
||||
@@ -485,6 +486,22 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
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> {
|
||||
val order = mutableListOf(0, 1, 2, 3)
|
||||
order.shuffle(Random(uidSeed.toLong()))
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.oxycblt.auxio.image.coil
|
||||
internal object ComposeCoverDefaults {
|
||||
const val CARD_SIZE_PERCENT = 0.60f
|
||||
const val GAP_RATIO = 0.04f
|
||||
const val CORNER_RATIO = 0.08f
|
||||
const val MIN_GAP_CORNER_RATIO = 0.35f
|
||||
const val MAX_CORNER_RATIO = 0.15f
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import org.oxycblt.musikr.covers.CoverCollection
|
||||
|
||||
data class GalleryCoverCollection(
|
||||
val covers: CoverCollection,
|
||||
val useRoundedCorners: Boolean,
|
||||
val cornerRadiusRatio: Float,
|
||||
val zOrder: List<Int>,
|
||||
)
|
||||
|
||||
@@ -101,8 +101,7 @@ private constructor(
|
||||
if (bitmaps.size != streams.size) {
|
||||
return null
|
||||
}
|
||||
val cornerRadiusPx =
|
||||
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
|
||||
val cornerRadiusPx = outputSize * data.cornerRadiusRatio
|
||||
val collageBitmap =
|
||||
CollageGenerator.generate(
|
||||
bitmaps,
|
||||
@@ -320,8 +319,7 @@ private constructor(
|
||||
|
||||
class Keyer @Inject constructor() : CoilKeyer<GalleryCoverCollection> {
|
||||
override fun key(data: GalleryCoverCollection, options: Options): String {
|
||||
val config =
|
||||
"${if (data.useRoundedCorners) "r" else "s"}.${data.zOrder.joinToString(".")}"
|
||||
val config = "${data.cornerRadiusRatio}.${data.zOrder.joinToString(".")}"
|
||||
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(
|
||||
val covers: CoverCollection,
|
||||
val useRoundedCorners: Boolean,
|
||||
val cornerRadiusRatio: Float,
|
||||
val fanAngleDeg: Float,
|
||||
val tiltAngleDeg: Float,
|
||||
val zOrder: List<Int>,
|
||||
@@ -106,8 +106,7 @@ private constructor(
|
||||
if (bitmaps.size != streams.size) {
|
||||
return null
|
||||
}
|
||||
val cornerRadiusPx =
|
||||
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
|
||||
val cornerRadiusPx = outputSize * data.cornerRadiusRatio
|
||||
val collageBitmap =
|
||||
StackCollageGenerator.generate(
|
||||
bitmaps,
|
||||
@@ -325,7 +324,7 @@ private constructor(
|
||||
class Keyer @Inject constructor() : CoilKeyer<SmatteringCoverCollection> {
|
||||
override fun key(data: SmatteringCoverCollection, options: Options): String {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import org.oxycblt.musikr.covers.CoverCollection
|
||||
|
||||
data class StackCoverCollection(
|
||||
val covers: CoverCollection,
|
||||
val useRoundedCorners: Boolean,
|
||||
val cornerRadiusRatio: Float,
|
||||
val zOrder: List<Int>,
|
||||
)
|
||||
|
||||
@@ -101,8 +101,7 @@ private constructor(
|
||||
if (bitmaps.size != streams.size) {
|
||||
return null
|
||||
}
|
||||
val cornerRadiusPx =
|
||||
if (data.useRoundedCorners) outputSize * ComposeCoverDefaults.CORNER_RATIO else 0f
|
||||
val cornerRadiusPx = outputSize * data.cornerRadiusRatio
|
||||
val stackBitmap =
|
||||
StackGenerator.generate(
|
||||
bitmaps,
|
||||
@@ -303,8 +302,7 @@ private constructor(
|
||||
|
||||
class Keyer @Inject constructor() : CoilKeyer<StackCoverCollection> {
|
||||
override fun key(data: StackCoverCollection, options: Options): String {
|
||||
val config =
|
||||
"${if (data.useRoundedCorners) "r" else "s"}.${data.zOrder.joinToString(".")}"
|
||||
val config = "${data.cornerRadiusRatio}.${data.zOrder.joinToString(".")}"
|
||||
return "s:${data.covers.hashCode()}.${options.size.width}.${options.size.height}.$config"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user