Skip to content

Commit

Permalink
Check if we have valid initials before determining avatar icon visibi…
Browse files Browse the repository at this point in the history
…lity

Credit to @salehsagharchi in #1622
  • Loading branch information
moezbhatti committed Jan 2, 2021
1 parent 0472535 commit 9369c81
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ class AvatarView @JvmOverloads constructor(
binding.initial.setTextColor(theme.textPrimary)
binding.icon.setTint(theme.textPrimary)

if (fullName?.isNotEmpty() == true) {
val initials = fullName
?.substringBefore(',')
?.split(" ").orEmpty()
.filter { name -> name.isNotEmpty() }
.map { name -> name[0] }
.filter { initial -> initial.isLetterOrDigit() }
.map { initial -> initial.toString() }
val initials = fullName
?.substringBefore(',')
?.split(" ").orEmpty()
.filter { name -> name.isNotEmpty() }
.map { name -> name[0] }
.filter { initial -> initial.isLetterOrDigit() }
.map { initial -> initial.toString() }

if (initials.isNotEmpty()) {
binding.initial.text = if (initials.size > 1) initials.first() + initials.last() else initials.first()
binding.icon.visibility = GONE
} else {
Expand Down

0 comments on commit 9369c81

Please sign in to comment.