diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index 2a14a51ce1..589b493af6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -15,6 +15,7 @@ import androidx.annotation.DrawableRes import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat +import androidx.core.text.toSpannable import kotlinx.android.synthetic.main.view_visible_message_content.view.* import network.loki.messenger.R import org.session.libsession.messaging.utilities.UpdateMessageData @@ -25,10 +26,8 @@ import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.components.emoji.EmojiTextView import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MmsMessageRecord -import org.thoughtcrime.securesms.loki.utilities.UiMode -import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities -import org.thoughtcrime.securesms.loki.utilities.getColorWithID -import org.thoughtcrime.securesms.loki.utilities.toPx +import org.thoughtcrime.securesms.loki.utilities.* +import org.thoughtcrime.securesms.loki.utilities.MentionUtilities.highlightMentions import org.thoughtcrime.securesms.mms.GlideRequests import kotlin.math.roundToInt @@ -129,12 +128,14 @@ class VisibleMessageContentView : LinearLayout { val vPadding = context.resources.getDimension(R.dimen.small_spacing).toInt() val hPadding = toPx(12, context.resources) result.setPadding(hPadding, vPadding, hPadding, vPadding) - result.text = message.body result.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(R.dimen.small_font_size)) val color = getTextColor(context, message) result.setTextColor(color) result.setLinkTextColor(color) - Linkify.addLinks(result, Linkify.WEB_URLS) + var body = message.body.toSpannable() + Linkify.addLinks(body, Linkify.WEB_URLS) + body = MentionUtilities.highlightMentions(body, message.isOutgoing, message.threadId, context); + result.text = body return result } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionUtilities.kt index 45fda301d8..d54d19f0ee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionUtilities.kt @@ -7,6 +7,7 @@ import android.text.SpannableString import android.text.style.ForegroundColorSpan import android.text.style.StyleSpan import android.util.Range +import androidx.core.content.res.ResourcesCompat import network.loki.messenger.R import nl.komponents.kovenant.combine.Tuple2 import org.session.libsession.messaging.contacts.Contact @@ -23,7 +24,7 @@ object MentionUtilities { @JvmStatic fun highlightMentions(text: CharSequence, isOutgoingMessage: Boolean, threadID: Long, context: Context): SpannableString { - var text = text + @Suppress("NAME_SHADOWING") var text = text val threadDB = DatabaseFactory.getThreadDatabase(context) val isOpenGroup = threadDB.getRecipientForThreadId(threadID)?.isOpenGroupRecipient ?: false val pattern = Pattern.compile("@[0-9a-fA-F]*") @@ -38,7 +39,7 @@ object MentionUtilities { TextSecurePreferences.getProfileName(context) } else { val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey) - val context = if (isOpenGroup) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR + @Suppress("NAME_SHADOWING") val context = if (isOpenGroup) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR contact?.displayName(context) } if (userDisplayName != null) { @@ -54,10 +55,15 @@ object MentionUtilities { } } val result = SpannableString(text) + val isLightMode = UiModeUtilities.isDayUiMode(context) for (mention in mentions) { - val isLightMode = UiModeUtilities.isDayUiMode(context) - val colorID = if (isLightMode && isOutgoingMessage) R.color.black else R.color.accent - result.setSpan(ForegroundColorSpan(context.resources.getColorWithID(colorID, context.theme)), mention.first.lower, mention.first.upper, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + val colorID = if (isOutgoingMessage) { + if (isLightMode) R.color.white else R.color.black + } else { + R.color.accent + } + val color = ResourcesCompat.getColor(context.resources, colorID, context.theme) + result.setSpan(ForegroundColorSpan(color), mention.first.lower, mention.first.upper, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) result.setSpan(StyleSpan(Typeface.BOLD), mention.first.lower, mention.first.upper, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } return result