forked from upstream-mirrors/quik
Filter non-alphanumeric initials
This commit is contained in:
@@ -44,7 +44,7 @@ class AvatarView @JvmOverloads constructor(
|
|||||||
private val binding = viewBinding(AvatarViewBinding::inflate)
|
private val binding = viewBinding(AvatarViewBinding::inflate)
|
||||||
|
|
||||||
private var lookupKey: String? = null
|
private var lookupKey: String? = null
|
||||||
private var name: String? = null
|
private var fullName: String? = null
|
||||||
private var photoUri: String? = null
|
private var photoUri: String? = null
|
||||||
private var lastUpdated: Long? = null
|
private var lastUpdated: Long? = null
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ class AvatarView @JvmOverloads constructor(
|
|||||||
*/
|
*/
|
||||||
fun setRecipient(recipient: Recipient?) {
|
fun setRecipient(recipient: Recipient?) {
|
||||||
lookupKey = recipient?.contact?.lookupKey
|
lookupKey = recipient?.contact?.lookupKey
|
||||||
name = recipient?.contact?.name
|
fullName = recipient?.contact?.name
|
||||||
photoUri = recipient?.contact?.photoUri
|
photoUri = recipient?.contact?.photoUri
|
||||||
lastUpdated = recipient?.contact?.lastUpdate
|
lastUpdated = recipient?.contact?.lastUpdate
|
||||||
theme = colors.theme(recipient)
|
theme = colors.theme(recipient)
|
||||||
@@ -84,12 +84,14 @@ class AvatarView @JvmOverloads constructor(
|
|||||||
binding.initial.setTextColor(theme.textPrimary)
|
binding.initial.setTextColor(theme.textPrimary)
|
||||||
binding.icon.setTint(theme.textPrimary)
|
binding.icon.setTint(theme.textPrimary)
|
||||||
|
|
||||||
if (name?.isNotEmpty() == true) {
|
if (fullName?.isNotEmpty() == true) {
|
||||||
val initials = name
|
val initials = fullName
|
||||||
?.substringBefore(',')
|
?.substringBefore(',')
|
||||||
?.split(" ").orEmpty()
|
?.split(" ").orEmpty()
|
||||||
.filter { subname -> subname.isNotEmpty() }
|
.filter { name -> name.isNotEmpty() }
|
||||||
.map { subname -> subname[0].toString() }
|
.map { name -> name[0] }
|
||||||
|
.filter { initial -> initial.isLetterOrDigit() }
|
||||||
|
.map { initial -> initial.toString() }
|
||||||
|
|
||||||
binding.initial.text = if (initials.size > 1) initials.first() + initials.last() else initials.first()
|
binding.initial.text = if (initials.size > 1) initials.first() + initials.last() else initials.first()
|
||||||
binding.icon.visibility = GONE
|
binding.icon.visibility = GONE
|
||||||
|
|||||||
Reference in New Issue
Block a user