From 82c592443468d3e113c4e439b0d293cb02b8e89f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 30 Jul 2017 22:04:58 +0200 Subject: [PATCH] display messages that only contain emoji slightly larger --- build.gradle | 3 +++ .../eu/siacs/conversations/entities/Message.java | 10 ++++++---- .../conversations/ui/adapter/MessageAdapter.java | 12 +++++++----- .../java/eu/siacs/conversations/utils/UIHelper.java | 6 ------ src/main/res/values/strings.xml | 1 + 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 1a01c1d51..bebe99fca 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,9 @@ dependencies { compile 'com.makeramen:roundedimageview:2.2.0' compile "com.wefika:flowlayout:0.4.1" compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0' + compile ('com.vdurmont:emoji-java:3.3.0') { + exclude group: 'org.json', module: 'json' + } } ext { diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 77b54d328..aba5c6004 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -4,6 +4,8 @@ import android.content.ContentValues; import android.database.Cursor; import android.text.SpannableStringBuilder; +import com.vdurmont.emoji.EmojiManager; + import java.net.MalformedURLException; import java.net.URL; @@ -500,8 +502,8 @@ public class Message extends AbstractEntity { !this.treatAsDownloadable() && !message.getBody().startsWith(ME_COMMAND) && !this.getBody().startsWith(ME_COMMAND) && - !this.bodyIsHeart() && - !message.bodyIsHeart() && + !this.bodyIsOnlyEmojis() && + !message.bodyIsOnlyEmojis() && ((this.axolotlFingerprint == null && message.axolotlFingerprint == null) || this.axolotlFingerprint.equals(message.getFingerprint())) && UIHelper.sameDay(message.getTimeSent(),this.getTimeSent()) ); @@ -666,8 +668,8 @@ public class Message extends AbstractEntity { } } - public boolean bodyIsHeart() { - return body != null && UIHelper.HEARTS.contains(body.trim()); + public boolean bodyIsOnlyEmojis() { + return EmojiManager.isOnlyEmojis(body.trim()); } public FileParams getFileParams() { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index adaa31174..a954b11cc 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -36,6 +36,8 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import com.vdurmont.emoji.EmojiManager; + import java.lang.ref.WeakReference; import java.net.URL; import java.util.List; @@ -321,7 +323,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.messageBody.setTextIsSelectable(false); } - private void displayHeartMessage(final ViewHolder viewHolder, final String body) { + private void displayEmojiMessage(final ViewHolder viewHolder, final String body) { if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -329,8 +331,8 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.messageBody.setVisibility(View.VISIBLE); viewHolder.messageBody.setIncludeFontPadding(false); Spannable span = new SpannableString(body); - span.setSpan(new RelativeSizeSpan(4.0f), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - span.setSpan(new ForegroundColorSpan(activity.getWarningTextColor()), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + float size = EmojiManager.isEmoji(body) ? 3.0f : 2.0f; + span.setSpan(new RelativeSizeSpan(size), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); viewHolder.messageBody.setText(span); } @@ -790,8 +792,8 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } else { if (GeoHelper.isGeoUri(message.getBody())) { displayLocationMessage(viewHolder,message); - } else if (message.bodyIsHeart()) { - displayHeartMessage(viewHolder, message.getBody().trim()); + } else if (message.bodyIsOnlyEmojis()) { + displayEmojiMessage(viewHolder, message.getBody().trim()); } else if (message.treatAsDownloadable()) { try { URL url = new URL(message.getBody()); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index af0f5b6c6..69eeb58da 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -28,12 +28,6 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class UIHelper { - private static String BLACK_HEART_SUIT = "\u2665"; - private static String HEAVY_BLACK_HEART_SUIT = "\u2764"; - private static String WHITE_HEART_SUIT = "\u2661"; - - public static final List HEARTS = Arrays.asList(BLACK_HEART_SUIT,HEAVY_BLACK_HEART_SUIT,WHITE_HEART_SUIT); - private static final List LOCATION_QUESTIONS = Arrays.asList( "where are you", //en "where are you now", //en diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index ff650c6ff..8644c20b8 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -336,6 +336,7 @@ \n\nhttps://github.com/WhisperSystems/libaxolotl-java\n(GPLv3) \n\nhttps://github.com/vinc3m1/RoundedImageView\n(Apache License, Version 2.0) \n\nhttps://github.com/jdamcd/android-crop\n(Apache License, Version 2.0) + \n\nhttps://github.com/vdurmont/emoji-java\n(The MIT License) Quiet Hours Start time