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) {
ImageViewExtensionsKt.loadFirstLetterAvatar(
imageView,
String.valueOf(participantDisplayItem.getNick().charAt(0))
String.valueOf(participantDisplayItem.getNick())
);
} else {
ImageViewExtensionsKt.loadAvatarWithUrl(imageView,null, participantDisplayItem.getUrlForAvatar());

View file

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

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)
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 data: Any = layerDrawable

View file

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