srctree

Robin Linden parent 005e1986 2728ac64
Don't allow converting Px to Px

inlinesplit
atox/src/main/kotlin/ui/AvatarFactory.kt added: 17, removed: 13, total 4
@@ -31,7 +31,10 @@ internal object AvatarFactory {
size: Size = Px(resources.getDimension(R.dimen.default_avatar_size).toInt())
): Bitmap {
val defaultAvatarSize = resources.getDimension(R.dimen.default_avatar_size)
val sizePx = size.asPx(resources).px
val sizePx = when (size) {
is Px -> size.px
is Dp -> size.asPx(resources).px
}
val textScale = sizePx / defaultAvatarSize
 
val bitmap = Bitmap.createBitmap(sizePx, sizePx, Bitmap.Config.ARGB_8888)
 
atox/src/main/kotlin/ui/Util.kt added: 17, removed: 13, total 4
@@ -20,16 +20,12 @@ internal fun colorFromStatus(context: Context, status: UserStatus) = when (statu
internal fun dpToPx(dp: Float, res: Resources): Int =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.displayMetrics).toInt()
 
internal sealed interface Size {
fun asPx(res: Resources): Px
}
internal sealed interface Size
 
@JvmInline
internal value class Px(val px: Int) : Size {
override fun asPx(res: Resources) = this
}
internal value class Px(val px: Int) : Size
 
@JvmInline
internal value class Dp(val dp: Float) : Size {
override fun asPx(res: Resources): Px = Px(dpToPx(dp, res))
fun asPx(res: Resources): Px = Px(dpToPx(dp, res))
}
 
atox/src/main/kotlin/ui/user_profile/UserProfileFragment.kt added: 17, removed: 13, total 4
@@ -217,10 +217,15 @@ class UserProfileFragment : BaseFragment<FragmentUserProfileBinding>(FragmentUse
}
}
 
val qrSizePx = qrSize.asPx(resources).px
fun getPx(size: Size) = when (size) {
is Px -> size.px
is Dp -> size.asPx(resources).px
}
 
val qrSizePx = getPx(qrSize)
bmpQr = bmpQr.scale(qrSizePx, qrSizePx, false)
 
val paddingPx = padding.asPx(resources).px
val paddingPx = getPx(padding)
val bmpQrWithPadding =
Bitmap.createBitmap(
bmpQr.width + 2 * paddingPx,