aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM. Dietrich <mdt@emdete.de>2014-09-01 23:48:42 +0200
committerM. Dietrich <mdt@emdete.de>2014-09-01 23:48:42 +0200
commit546082147ae161aa7568277db653655483cd745e (patch)
tree78e23229fb9d58ebd84d116a1dde93c6d4059a13
parent3558fa5f5bcbf73ecb5c8174b208ac0c36e708b1 (diff)
transform ascii to emoticons (on display only)
-rw-r--r--src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java2
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java2
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java23
3 files changed, 25 insertions, 2 deletions
diff --git a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index fcc576018..ecae62318 100644
--- a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -59,7 +59,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|| latestMessage.getType() == Message.TYPE_PRIVATE) {
if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- convLastMsg.setText(conv.getLatestMessage().getBody());
+ convLastMsg.setText(UIHelper.transformAsciiEmoticons(conv.getLatestMessage().getBody()));
} else {
convLastMsg.setText(activity
.getText(R.string.encrypted_message_received));
diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 637711aba..553584cd7 100644
--- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -215,7 +215,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
if (message.getType() != Message.TYPE_PRIVATE) {
- viewHolder.messageBody.setText(message.getMergedBody());
+ viewHolder.messageBody.setText(UIHelper.transformAsciiEmoticons(message.getMergedBody()));
} else {
String privateMarker;
if (message.getStatus() <= Message.STATUS_RECEIVED) {
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 1f584fe57..69f833f2a 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -545,4 +545,27 @@ public class UIHelper {
return getContactPicture(account.getJid(), size, context, false);
}
}
+ public static String transformAsciiEmoticons(String body) {
+ if (body != null) {
+ for (String[] r: new String[][]{ // see https://de.wikipedia.org/wiki/Unicodeblock_Smileys
+ {":-?\\)", " 😀 ", },
+ {";-?\\)", " 😉 ", },
+ {":-?D", " 😃 ", },
+ {":-?[Ppb]", " 😋 ", },
+ {"8-?\\)", " 😎 ", },
+ {":-?\\|", " 😐 ", },
+ {":-?[/\\\\]", " 😕 ", },
+ {":-?\\*", " 😗 ", },
+ {":-?[0Oo]", " 😮 ", },
+ {":-?\\(", " 😞 ", },
+ {"\\^\\^", " 😁 ", },
+ }) {
+ String p = r[0];
+ p = "(^" + p + "$|^" + p + " +| +" + p + " +| +" + p + "$)";
+ body = body.replaceAll(p, r[1]);
+ }
+ body = body.trim();
+ }
+ return body;
+ }
}