srctree

Roee Hershberg parent d52cb499 34114699
Move the default avatar size to dimens.xml

inlinesplit
atox/src/main/kotlin/ui/AvatarFactory.kt added: 10, removed: 8, total 2
@@ -20,10 +20,6 @@ import ltd.evilcorp.core.vo.Contact
// Class for creating an avatar for contact and assigning it into an ImageView
internal class AvatarFactory(contact: Contact) {
 
companion object {
const val DEFAULT_AVATAR_SIZE_DP = 50f
}
 
private val name: String = contact.name
private val publicKey: String = contact.publicKey
private val avatarUri: String = contact.avatarUri
@@ -39,12 +35,16 @@ internal class AvatarFactory(contact: Contact) {
* then it will be set to the image view, otherwise a new avatar image will be created based
* on the initials of the name and the public key for the background color.
*/
fun assignInto(imageView: ImageView, size: Size = Dp(DEFAULT_AVATAR_SIZE_DP)) =
fun assignInto(
imageView: ImageView,
size: Size = Px(imageView.resources.getDimension(R.dimen.default_avatar_size).toInt())
) =
if (avatarUri.isNotEmpty()) {
imageView.setImageURI(Uri.parse(avatarUri))
} else {
val defaultAvatarSize = imageView.resources.getDimension(R.dimen.default_avatar_size).toInt()
val side = size.asPx(imageView.resources).px
val textScale = side.toFloat() / Dp(DEFAULT_AVATAR_SIZE_DP).asPx(imageView.resources).px
val textScale = side / defaultAvatarSize
 
val bitmap = Bitmap.createBitmap(side, side, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
 
atox/src/main/res/values/dimens.xml added: 10, removed: 8, total 2
@@ -8,4 +8,6 @@
<dimen name="message_margin">50dp</dimen>
 
<dimen name="contact_avatar_placeholder_text">32dp</dimen>
 
<dimen name="default_avatar_size">50dp</dimen>
</resources>