Fix to display chips with emojis

Chips with emojis were not shown correctly.

The message with the emoji was not correctly replaced, that's why now the key itself is passed and replaced with the chip instead to replace a text with emoji with a chip.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-16 12:41:41 +01:00
parent f698bb159b
commit 5688c10978
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 63 additions and 58 deletions

View File

@ -85,9 +85,9 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) : MessageHolde
itemView.isSelected = false
var messageString: Spannable = SpannableString(message.text)
var messageString: Spannable = SpannableString(message.message)
var textSize = context?.resources!!.getDimension(R.dimen.chat_text_size)
var textSize = context.resources!!.getDimension(R.dimen.chat_text_size)
val messageParameters = message.messageParameters
if (messageParameters != null && messageParameters.size > 0) {
@ -226,38 +226,30 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) : MessageHolde
for (key in messageParameters.keys) {
val individualHashMap = message.messageParameters!![key]
if (individualHashMap != null) {
if (
individualHashMap["type"] == "user" ||
individualHashMap["type"] == "guest" ||
individualHashMap["type"] == "call"
) {
if (individualHashMap["id"] == message.activeUser!!.userId) {
when (individualHashMap["type"]) {
"user", "guest", "call" -> {
val chip = if (individualHashMap["id"] == message.activeUser!!.userId) {
R.xml.chip_you
} else {
R.xml.chip_others
}
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
key,
binding.messageText.context,
messageStringInternal,
individualHashMap["id"]!!,
individualHashMap["name"]!!,
individualHashMap["type"]!!,
message.activeUser!!,
R.xml.chip_you,
viewThemeUtils
)
} else {
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
binding.messageText.context,
messageStringInternal,
individualHashMap["id"]!!,
individualHashMap["name"]!!,
individualHashMap["type"]!!,
message.activeUser!!,
R.xml.chip_others,
chip,
viewThemeUtils
)
}
} else if (individualHashMap["type"] == "file") {
itemView.setOnClickListener { v ->
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
context!!.startActivity(browserIntent)
"file" -> {
itemView.setOnClickListener { v ->
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
context.startActivity(browserIntent)
}
}
}
}

View File

@ -46,7 +46,7 @@ import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.DisplayUtils.searchAndReplaceWithMentionSpan
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.TextMatchers
import com.stfalcon.chatkit.messages.MessageHolders.OutcomingTextMessageViewHolder
import javax.inject.Inject
@ -71,7 +71,7 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH
super.onBind(message)
sharedApplication!!.componentApplication.inject(this)
val messageParameters: HashMap<String?, HashMap<String?, String?>>? = message.messageParameters
var messageString: Spannable = SpannableString(message.text)
var messageString: Spannable = SpannableString(message.message)
realView.isSelected = false
val layoutParams = binding.messageTime.layoutParams as FlexboxLayout.LayoutParams
layoutParams.isWrapBefore = false
@ -186,33 +186,39 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH
message: ChatMessage,
messageString: Spannable
): Spannable {
var messageString1 = messageString
var messageStringInternal = messageString
for (key in messageParameters.keys) {
val individualHashMap: HashMap<String?, String?>? = message.messageParameters!![key]
if (individualHashMap != null) {
if (individualHashMap["type"] == "user" ||
individualHashMap["type"] == "guest" ||
individualHashMap["type"] == "call"
) {
messageString1 = searchAndReplaceWithMentionSpan(
binding.messageText.context,
messageString1,
individualHashMap["id"]!!,
individualHashMap["name"]!!,
individualHashMap["type"]!!,
message.activeUser,
R.xml.chip_others,
viewThemeUtils
)
} else if (individualHashMap["type"] == "file") {
realView.setOnClickListener { v: View? ->
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
context!!.startActivity(browserIntent)
when (individualHashMap["type"]) {
"user", "guest", "call" -> {
val chip = if (individualHashMap["id"] == message.activeUser!!.userId) {
R.xml.chip_you
} else {
R.xml.chip_others
}
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
key,
binding.messageText.context,
messageStringInternal,
individualHashMap["id"]!!,
individualHashMap["name"]!!,
individualHashMap["type"]!!,
message.activeUser!!,
chip,
viewThemeUtils
)
}
"file" -> {
itemView.setOnClickListener { v ->
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap["link"]))
context.startActivity(browserIntent)
}
}
}
}
}
return messageString1
return messageStringInternal
}
fun assignCommonMessageInterface(commonMessageInterface: CommonMessageInterface) {

View File

@ -98,6 +98,7 @@ import static com.nextcloud.talk.utils.FileSortOrder.sort_z_to_a_id;
public class DisplayUtils {
private static final String TAG = "DisplayUtils";
private static final int INDEX_LUMINATION = 2;
private static final double MAX_LIGHTNESS = 0.92;
@ -240,7 +241,7 @@ public class DisplayUtils {
return chip;
}
public static Spannable searchAndReplaceWithMentionSpan(Context context, Spannable text,
public static Spannable searchAndReplaceWithMentionSpan(String key, Context context, Spannable text,
String id, String label, String type,
User conversationUser,
@XmlRes int chipXmlRes,
@ -249,8 +250,8 @@ public class DisplayUtils {
Spannable spannableString = new SpannableString(text);
String stringText = text.toString();
Matcher m = Pattern.compile("@" + label,
Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
String keyWithBrackets = "{" + key + "}";
Matcher m = Pattern.compile(keyWithBrackets, Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
.matcher(spannableString);
ClickableSpan clickableSpan = new ClickableSpan() {
@ -266,17 +267,23 @@ public class DisplayUtils {
int start = stringText.indexOf(m.group(), lastStartIndex);
int end = start + m.group().length();
lastStartIndex = end;
mentionChipSpan = new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
id,
label,
conversationUser,
type,
chipXmlRes,
null,
viewThemeUtils),
BetterImageSpan.ALIGN_CENTER, id,
Drawable drawableForChip = DisplayUtils.getDrawableForMentionChipSpan(context,
id,
label,
conversationUser,
type,
chipXmlRes,
null,
viewThemeUtils);
mentionChipSpan = new Spans.MentionChipSpan(drawableForChip,
BetterImageSpan.ALIGN_CENTER,
id,
label);
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (chipXmlRes == R.xml.chip_you) {
spannableString.setSpan(
new ForegroundColorSpan(viewThemeUtils.getScheme(context).getOnPrimary()),