AvatarAndNameView.kt 1022 B

12345678910111213141516171819202122232425262728293031
  1. package com.mrozon.teamviewexample
  2. import android.annotation.SuppressLint
  3. import android.content.Context
  4. import android.view.LayoutInflater
  5. import android.widget.LinearLayout
  6. import coil.load
  7. import coil.transform.CircleCropTransformation
  8. import com.mrozon.teamviewexample.databinding.AvatarAndNameViewBinding
  9. @SuppressLint("ViewConstructor")
  10. class AvatarAndNameView(context: Context, member: Member) : LinearLayout(context) {
  11. init {
  12. orientation = VERTICAL
  13. val binding = AvatarAndNameViewBinding
  14. .inflate(LayoutInflater.from(context), this, true)
  15. binding.username.text = member.name
  16. if (member.picture != null) {
  17. binding.userAvatar
  18. .load(member.picture) {
  19. transformations(CircleCropTransformation())
  20. }
  21. } else {
  22. binding.userAvatar
  23. .load(R.drawable.ic_avatar_placeholder) {
  24. transformations(CircleCropTransformation())
  25. }
  26. }
  27. }
  28. }