|
|
|
@ -4,18 +4,24 @@ import android.content.Context
|
|
|
|
|
import android.graphics.Typeface
|
|
|
|
|
import android.text.Spannable
|
|
|
|
|
import android.text.SpannableString
|
|
|
|
|
import android.text.style.BackgroundColorSpan
|
|
|
|
|
import android.text.style.ForegroundColorSpan
|
|
|
|
|
import android.text.style.StyleSpan
|
|
|
|
|
import android.util.Range
|
|
|
|
|
import androidx.appcompat.widget.ThemeUtils
|
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
|
import nl.komponents.kovenant.combine.Tuple2
|
|
|
|
|
import org.session.libsession.messaging.contacts.Contact
|
|
|
|
|
import org.session.libsession.messaging.utilities.SodiumUtilities
|
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
|
|
|
|
import org.session.libsession.utilities.ThemeUtil
|
|
|
|
|
import org.session.libsignal.utilities.Log
|
|
|
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
|
|
|
|
import org.thoughtcrime.securesms.util.UiModeUtilities
|
|
|
|
|
import org.thoughtcrime.securesms.util.getAccentColor
|
|
|
|
|
import org.thoughtcrime.securesms.util.getColorResourceIdFromAttr
|
|
|
|
|
import org.thoughtcrime.securesms.util.getMessageTextColourAttr
|
|
|
|
|
import java.util.regex.Pattern
|
|
|
|
|
|
|
|
|
|
object MentionUtilities {
|
|
|
|
@ -58,15 +64,37 @@ object MentionUtilities {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val result = SpannableString(text)
|
|
|
|
|
val isLightMode = UiModeUtilities.isDayUiMode(context)
|
|
|
|
|
val color = if (isOutgoingMessage) {
|
|
|
|
|
ResourcesCompat.getColor(context.resources, if (isLightMode) R.color.white else R.color.black, context.theme)
|
|
|
|
|
} else {
|
|
|
|
|
context.getAccentColor()
|
|
|
|
|
|
|
|
|
|
var mentionTextColour: Int? = null
|
|
|
|
|
// In dark themes..
|
|
|
|
|
if (ThemeUtil.isDarkTheme(context)) {
|
|
|
|
|
// ..we use the standard outgoing message colour for outgoing messages..
|
|
|
|
|
if (isOutgoingMessage) {
|
|
|
|
|
val mentionTextColourAttributeId = getMessageTextColourAttr(true)
|
|
|
|
|
val mentionTextColourResourceId = getColorResourceIdFromAttr(context, mentionTextColourAttributeId)
|
|
|
|
|
mentionTextColour = ResourcesCompat.getColor(context.resources, mentionTextColourResourceId, context.theme)
|
|
|
|
|
}
|
|
|
|
|
else // ..but we use the accent colour for incoming messages (i.e., someone mentioning us)..
|
|
|
|
|
{
|
|
|
|
|
mentionTextColour = context.getAccentColor()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // ..while in light themes we always just use the incoming or outgoing message text colour for mentions.
|
|
|
|
|
{
|
|
|
|
|
val mentionTextColourAttributeId = getMessageTextColourAttr(isOutgoingMessage)
|
|
|
|
|
val mentionTextColourResourceId = getColorResourceIdFromAttr(context, mentionTextColourAttributeId)
|
|
|
|
|
mentionTextColour = ResourcesCompat.getColor(context.resources, mentionTextColourResourceId, context.theme)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (mention in mentions) {
|
|
|
|
|
result.setSpan(ForegroundColorSpan(color), mention.first.lower, mention.first.upper, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
|
|
|
result.setSpan(ForegroundColorSpan(mentionTextColour), 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)
|
|
|
|
|
|
|
|
|
|
// If we're using a light theme then we change the background colour of the mention to be the accent colour
|
|
|
|
|
if (ThemeUtil.isLightTheme(context)) {
|
|
|
|
|
val backgroundColour = context.getAccentColor();
|
|
|
|
|
result.setSpan(BackgroundColorSpan(backgroundColour), mention.first.lower, mention.first.upper, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|