mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-18 22:52:04 +03:00
Refactored isMessageWithSingleEmoticonOnly in TextMatchers to use regex for single emoji check
Signed-off-by: Smarshal21 <lcb2021048@iiitl.ac.in>
This commit is contained in:
parent
ac030a22a8
commit
f79db0b6b2
3 changed files with 31 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
25
app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java
Normal file
25
app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue