diff --git a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantsAdapter.java b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantsAdapter.java index 2275a7f7d..c6c49773d 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantsAdapter.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantsAdapter.java @@ -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()); diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt index e047be397..d08ff37a4 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt @@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import com.nextcloud.talk.R import com.nextcloud.talk.adapters.items.ConversationItem.ConversationItemViewHolder +import com.nextcloud.talk.adapters.messages.MessagePayload import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.chat.data.model.ChatMessage.MessageType import com.nextcloud.talk.data.database.mappers.asModel @@ -249,14 +250,15 @@ class ConversationItem( } else if (model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) { lastMessageDisplayText } else { - val authorDisplayName = - if (!TextUtils.isEmpty(chatMessage?.actorDisplayName)) { - chatMessage?.actorDisplayName - } else if ("guests" == chatMessage?.actorType) { - appContext.getString(R.string.nc_guest) - } else { - "" - } + val actorName = chatMessage?.actorDisplayName + val authorDisplayName = if (!actorName.isNullOrBlank()) { + actorName + } else if ("guests" == chatMessage?.actorType || "emails" == chatMessage?.actorType) { + appContext.getString(R.string.nc_guest) + } else { + "" + } + String.format( appContext.getString(R.string.nc_formatted_message), authorDisplayName, diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt index 3e3ba686f..721666982 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt @@ -16,6 +16,7 @@ import androidx.core.content.res.ResourcesCompat import com.nextcloud.talk.R import com.nextcloud.talk.adapters.items.ParticipantItem.ParticipantItemViewHolder import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.extensions.loadDefaultAvatar import com.nextcloud.talk.extensions.loadFederatedUserAvatar import com.nextcloud.talk.extensions.loadGuestAvatar import com.nextcloud.talk.extensions.loadUserAvatar @@ -56,7 +57,15 @@ class MentionAutocompleteItem( init { mentionId = mention.mentionId objectId = mention.id - displayName = mention.label + + displayName = if (!mention.label.isNullOrBlank()) { + mention.label + } else if ("guests" == mention.source || "emails" == mention.source) { + context.resources.getString(R.string.nc_guest) + } else { + "" + } + source = mention.source status = mention.status statusIcon = mention.statusIcon @@ -149,7 +158,11 @@ class MentionAutocompleteItem( SOURCE_GUESTS, SOURCE_EMAILS -> { avatarId = displayName - holder.binding.avatarView.loadGuestAvatar(currentUser, avatarId!!, false) + if (displayName.equals(context.resources.getString(R.string.nc_guest))) { + holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils) + } else { + holder.binding.avatarView.loadGuestAvatar(currentUser, avatarId!!, false) + } } else -> { diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.kt index 4b58041ab..e23df8409 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.kt @@ -85,6 +85,10 @@ class ParticipantItem( setOnlineStateColor(holder) holder.binding.nameText.text = model.displayName + if (model.type == Participant.ParticipantType.GUEST && model.displayName.isNullOrBlank()) { + holder.binding.nameText.text = sharedApplication!!.getString(R.string.nc_guest) + } + if (adapter!!.hasFilter()) { viewThemeUtils.talk.themeAndHighlightText( holder.binding.nameText, @@ -211,12 +215,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) } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt index 771001cca..17486dc82 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt @@ -157,10 +157,10 @@ class IncomingDeckCardViewHolder(incomingView: View, payload: Any) : MessageHold } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt index 53f6506a6..d450213b9 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt @@ -135,10 +135,10 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) : } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt index 69c6e6c29..e5ba4f2d8 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt @@ -35,6 +35,7 @@ import com.nextcloud.talk.extensions.loadChangelogBotAvatar import com.nextcloud.talk.extensions.loadFederatedUserAvatar import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.ChatMessageUtils import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.message.MessageUtils @@ -119,10 +120,10 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } @@ -131,16 +132,7 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : } if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) { - binding.messageUserAvatar.visibility = View.VISIBLE - if (message.actorType == "guests") { - // do nothing, avatar is set - } else if (message.actorType == "bots" && message.actorId == "changelog") { - binding.messageUserAvatar.loadChangelogBotAvatar() - } else if (message.actorType == "bots") { - binding.messageUserAvatar.loadBotsAvatar() - } else if (message.actorType == "federated_users") { - binding.messageUserAvatar.loadFederatedUserAvatar(message) - } + ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils) } else { if (message.isOneToOneConversation || message.isFormerOneToOneConversation) { binding.messageUserAvatar.visibility = View.GONE diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt index 59b626df8..56b0936bc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt @@ -142,10 +142,10 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt index b3565de23..2a587270c 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt @@ -144,10 +144,10 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) : } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt index 36155bf09..9413e1720 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt @@ -238,10 +238,10 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : } private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) { - val author: String = message.actorDisplayName!! - if (!TextUtils.isEmpty(author)) { + val actorName = message.actorDisplayName + if (!actorName.isNullOrBlank()) { binding.messageAuthor.visibility = View.VISIBLE - binding.messageAuthor.text = author + binding.messageAuthor.text = actorName binding.messageUserAvatar.setOnClickListener { (payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context) } diff --git a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt index 1d70a986c..9411756c0 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -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(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 diff --git a/app/src/main/java/com/nextcloud/talk/utils/ChatMessageUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/ChatMessageUtils.kt index 92a8827d8..1f0c5e13f 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ChatMessageUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ChatMessageUtils.kt @@ -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) }