Create getBestName method for User

This commit is contained in:
Benoit Marty 2020-02-25 18:14:02 +01:00
parent ec0cba2b23
commit b95dfa4473
3 changed files with 8 additions and 3 deletions

View File

@ -24,4 +24,9 @@ data class User(
val userId: String,
val displayName: String? = null,
val avatarUrl: String? = null
)
) {
/**
* Return the display name or the user id
*/
fun getBestName() = displayName?.takeIf { it.isNotEmpty() } ?: userId
}

View File

@ -159,7 +159,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
val chip = Chip(requireContext())
chip.setChipBackgroundColorResource(android.R.color.transparent)
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
chip.text = if (user.displayName.isNullOrBlank()) user.userId else user.displayName
chip.text = user.getBestName()
chip.isClickable = true
chip.isCheckable = false
chip.isCloseIconVisible = true

View File

@ -203,7 +203,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
val user = session.getUser(session.myUserId)
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
val myUserDisplayName = user?.displayName?.takeIf { it.isNotBlank() } ?: session.myUserId
val myUserDisplayName = user?.getBestName() ?: session.myUserId
val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(user?.avatarUrl, avatarSize, avatarSize, ContentUrlResolver.ThumbnailMethod.SCALE)
synchronized(eventList) {
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER ")