mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-15 05:01:45 +03:00
show guest "first letter" avatars in chat
also: create ChatMessageUtils as helper for the ViewHolders in this case. Could help to avoid duplicated code until there is a clear inheritance solution. Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
199ba4be34
commit
16d03a69ff
6 changed files with 49 additions and 70 deletions
|
@ -31,6 +31,7 @@ import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||||
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.ChatMessageUtils
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.message.MessageUtils
|
import com.nextcloud.talk.utils.message.MessageUtils
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
|
@ -168,7 +169,7 @@ class IncomingDeckCardViewHolder(incomingView: View, payload: Any) : MessageHold
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
||||||
setAvatarOnMessage(message)
|
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
|
||||||
} else {
|
} else {
|
||||||
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
@ -179,19 +180,6 @@ class IncomingDeckCardViewHolder(incomingView: View, payload: Any) : MessageHold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAvatarOnMessage(message: ChatMessage) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||||
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.ChatMessageUtils
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.message.MessageUtils
|
import com.nextcloud.talk.utils.message.MessageUtils
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
|
@ -146,7 +147,7 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
||||||
setAvatarOnMessage(message)
|
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
|
||||||
} else {
|
} else {
|
||||||
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
@ -157,19 +158,6 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAvatarOnMessage(message: ChatMessage) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
import com.nextcloud.talk.polls.ui.PollMainDialogFragment
|
import com.nextcloud.talk.polls.ui.PollMainDialogFragment
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.ChatMessageUtils
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.message.MessageUtils
|
import com.nextcloud.talk.utils.message.MessageUtils
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
|
@ -153,7 +154,7 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
||||||
setAvatarOnMessage(message)
|
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
|
||||||
} else {
|
} else {
|
||||||
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
@ -164,19 +165,6 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAvatarOnMessage(message: ChatMessage) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,12 @@ import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||||
import com.nextcloud.talk.databinding.ItemCustomIncomingTextMessageBinding
|
import com.nextcloud.talk.databinding.ItemCustomIncomingTextMessageBinding
|
||||||
import com.nextcloud.talk.extensions.loadBotsAvatar
|
import com.nextcloud.talk.extensions.loadBotsAvatar
|
||||||
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadDefaultAvatar
|
||||||
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadFirstLetterAvatar
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.ChatMessageUtils
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.TextMatchers
|
import com.nextcloud.talk.utils.TextMatchers
|
||||||
import com.nextcloud.talk.utils.message.MessageUtils
|
import com.nextcloud.talk.utils.message.MessageUtils
|
||||||
|
@ -153,7 +156,7 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
||||||
setAvatarOnMessage(message)
|
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
|
||||||
} else {
|
} else {
|
||||||
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
@ -164,19 +167,6 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAvatarOnMessage(message: ChatMessage) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||||
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
|
import com.nextcloud.talk.utils.ChatMessageUtils
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.message.MessageUtils
|
import com.nextcloud.talk.utils.message.MessageUtils
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||||
|
@ -249,7 +250,7 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
|
||||||
setAvatarOnMessage(message)
|
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
|
||||||
} else {
|
} else {
|
||||||
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
|
||||||
binding.messageUserAvatar.visibility = View.GONE
|
binding.messageUserAvatar.visibility = View.GONE
|
||||||
|
@ -260,19 +261,6 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAvatarOnMessage(message: ChatMessage) {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun colorizeMessageBubble(message: ChatMessage) {
|
private fun colorizeMessageBubble(message: ChatMessage) {
|
||||||
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, message.isDeleted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Nextcloud Talk - Android Client
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2024 Marcel Hibbe <dev@mhibbe.de>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package com.nextcloud.talk.utils
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
|
import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||||
|
import com.nextcloud.talk.extensions.loadBotsAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadDefaultAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadFirstLetterAvatar
|
||||||
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
|
|
||||||
|
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())
|
||||||
|
} else {
|
||||||
|
view.loadDefaultAvatar(viewThemeUtils)
|
||||||
|
}
|
||||||
|
} else if (message.actorType == "bots" && message.actorId == "changelog") {
|
||||||
|
view.loadChangelogBotAvatar()
|
||||||
|
} else if (message.actorType == "bots") {
|
||||||
|
view.loadBotsAvatar()
|
||||||
|
} else if (message.actorType == "federated_users") {
|
||||||
|
view.loadFederatedUserAvatar(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue