Refactored isMessageWithSingleEmoticonOnly in TextMatchers to use regex for single emoji check

Signed-off-by: Smarshal21 <lcb2021048@iiitl.ac.in>
This commit is contained in:
Smarshal21 2023-11-18 18:23:21 +05:30
parent ac030a22a8
commit f79db0b6b2
3 changed files with 31 additions and 2 deletions

View file

@ -45,6 +45,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
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.DateUtils import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.TextMatchers
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
import com.stfalcon.chatkit.messages.MessageHolders import com.stfalcon.chatkit.messages.MessageHolders
@ -102,7 +103,8 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) :
val messageParameters = message.messageParameters val messageParameters = message.messageParameters
if ( if (
(messageParameters == null || messageParameters.size <= 0) (messageParameters == null || messageParameters.size <= 0) &&
TextMatchers.isMessageWithSingleEmoticonOnly(message.text)
) { ) {
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat() textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
itemView.isSelected = true itemView.isSelected = true

View file

@ -41,6 +41,7 @@ import com.nextcloud.talk.models.json.chat.ReadStatus
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.DateUtils import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.TextMatchers
import com.nextcloud.talk.utils.message.MessageUtils import com.nextcloud.talk.utils.message.MessageUtils
import com.stfalcon.chatkit.messages.MessageHolders.OutcomingTextMessageViewHolder import com.stfalcon.chatkit.messages.MessageHolders.OutcomingTextMessageViewHolder
import javax.inject.Inject import javax.inject.Inject
@ -88,7 +89,8 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH
val messageParameters = message.messageParameters val messageParameters = message.messageParameters
if ( if (
(messageParameters == null || messageParameters.size <= 0) (messageParameters == null || messageParameters.size <= 0) &&
TextMatchers.isMessageWithSingleEmoticonOnly(message.text)
) { ) {
textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat() textSize = (textSize * TEXT_SIZE_MULTIPLIER).toFloat()
layoutParams.isWrapBefore = true layoutParams.isWrapBefore = true

View file

@ -0,0 +1,25 @@
package com.nextcloud.talk.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.Nullable;
public final class TextMatchers {
public static boolean isMessageWithSingleEmoticonOnly(@Nullable final String text) {
if (text == null || text.isEmpty()) {
return false;
}
String emojiRegex = "([\\p{So}\\p{Sk}])";
Pattern pattern = Pattern.compile(emojiRegex);
Matcher matcher = pattern.matcher(text);
int emojiCount = 0;
while (matcher.find()) {
emojiCount++;
}
return emojiCount == 1;
}
}