fix to handle whitespaces for guest avatars

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-11-27 14:28:15 +01:00
parent 8162a73f7d
commit b3b525bbc2
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
4 changed files with 10 additions and 10 deletions

View file

@ -148,7 +148,7 @@ public class ParticipantsAdapter extends BaseAdapter {
participantDisplayItem.getActorType() == Participant.ActorType.EMAILS) { participantDisplayItem.getActorType() == Participant.ActorType.EMAILS) {
ImageViewExtensionsKt.loadFirstLetterAvatar( ImageViewExtensionsKt.loadFirstLetterAvatar(
imageView, imageView,
String.valueOf(participantDisplayItem.getNick().charAt(0)) String.valueOf(participantDisplayItem.getNick())
); );
} else { } else {
ImageViewExtensionsKt.loadAvatarWithUrl(imageView,null, participantDisplayItem.getUrlForAvatar()); ImageViewExtensionsKt.loadAvatarWithUrl(imageView,null, participantDisplayItem.getUrlForAvatar());

View file

@ -211,12 +211,11 @@ class ParticipantItem(
} }
Participant.ActorType.GUESTS, Participant.ActorType.EMAILS -> { Participant.ActorType.GUESTS, Participant.ActorType.EMAILS -> {
if (model.displayName.isNullOrEmpty()) { val actorName = model.displayName
holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils) if (!actorName.isNullOrBlank()) {
holder.binding.avatarView.loadFirstLetterAvatar(actorName)
} else { } else {
holder.binding.avatarView.loadFirstLetterAvatar( holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils)
model.displayName!!.first().toString()
)
} }
} }

View file

@ -305,10 +305,10 @@ fun ImageView.loadNoteToSelfAvatar(): io.reactivex.disposables.Disposable {
) )
} }
fun ImageView.loadFirstLetterAvatar(letter: String): io.reactivex.disposables.Disposable { fun ImageView.loadFirstLetterAvatar(name: String): io.reactivex.disposables.Disposable {
val layers = arrayOfNulls<Drawable>(2) val layers = arrayOfNulls<Drawable>(2)
layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)
layers[1] = createTextDrawable(context, letter.uppercase(Locale.ROOT)) layers[1] = createTextDrawable(context, name.trimStart().uppercase(Locale.ROOT))
val layerDrawable = LayerDrawable(layers) val layerDrawable = LayerDrawable(layers)
val data: Any = layerDrawable val data: Any = layerDrawable

View file

@ -21,8 +21,9 @@ class ChatMessageUtils {
fun setAvatarOnMessage(view: ImageView, message: ChatMessage, viewThemeUtils : ViewThemeUtils) { fun setAvatarOnMessage(view: ImageView, message: ChatMessage, viewThemeUtils : ViewThemeUtils) {
view.visibility = View.VISIBLE view.visibility = View.VISIBLE
if (message.actorType == "guests" || message.actorType == "emails") { if (message.actorType == "guests" || message.actorType == "emails") {
if (message.actorDisplayName?.isNotEmpty() == true) { val actorName = message.actorDisplayName
view.loadFirstLetterAvatar(message.actorDisplayName?.first().toString()) if (!actorName.isNullOrBlank()) {
view.loadFirstLetterAvatar(actorName)
} else { } else {
view.loadDefaultAvatar(viewThemeUtils) view.loadDefaultAvatar(viewThemeUtils)
} }