Skip to content

Commit 6e55e14

Browse files
committed
[lib-patch] Added EmojiCompat library.
1 parent 619fe02 commit 6e55e14

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

interactive-chat/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies {
4949
api 'com.chattylabs.sdk.android:conversational-flow-core:+'
5050
implementation 'com.chattylabs.sdk.android:common:+'
5151
implementation 'com.eyalbira.loadingdots:loading-dots:1.0.2'
52+
implementation 'com.android.support:support-emoji-bundled:27.1.1'
5253
// Testing
5354
testImplementation 'junit:junit:4.12'
5455
testImplementation 'org.mockito:mockito-core:2.19.1'

interactive-chat/src/main/java/com/chattylabs/android/user/interaction/ChatInteractionAdapter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.res.ColorStateList;
44
import android.os.Build;
55
import android.support.annotation.NonNull;
6+
import android.support.text.emoji.EmojiCompat;
67
import android.support.v7.widget.RecyclerView;
78
import android.text.Html;
89
import android.text.Spanned;
@@ -54,7 +55,6 @@ public int getLastPositionOf(Class type) {
5455
public void removeItem(int position) {
5556
items.remove(position);
5657
notifyItemRemoved(position);
57-
//notifyDataSetChanged();
5858
}
5959

6060
public ChatNode getItem(int position) {
@@ -146,11 +146,12 @@ private void configureActionViewHolder(ChatActionViewHolder viewHolder, int posi
146146
((Button) button).setTextSize(TypedValue.COMPLEX_UNIT_SP, action.textSize);
147147
}
148148
Spanned span;
149+
String text = (String) EmojiCompat.get().process(action.text);
149150
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
150-
span = Html.fromHtml(action.text, Html.FROM_HTML_MODE_COMPACT);
151+
span = Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT);
151152
}
152153
else {
153-
span = Html.fromHtml(action.text);
154+
span = Html.fromHtml(text);
154155
}
155156
((Button) button).setText(span);
156157
}
@@ -178,11 +179,12 @@ private void configureMessageViewHolder(ChatMessageViewHolder viewHolder, int po
178179
viewHolder.text.setTextSize(TypedValue.COMPLEX_UNIT_SP, message.textSize);
179180
}
180181
Spanned span;
182+
String text = (String) EmojiCompat.get().process(message.text);
181183
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
182-
span = Html.fromHtml(message.text, Html.FROM_HTML_MODE_COMPACT);
184+
span = Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT);
183185
}
184186
else {
185-
span = Html.fromHtml(message.text);
187+
span = Html.fromHtml(text);
186188
}
187189
viewHolder.text.setTag(message.id);
188190
viewHolder.text.setText(span);

interactive-chat/src/main/java/com/chattylabs/android/user/interaction/ChatInteractionComponentImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.support.annotation.NonNull;
1010
import android.support.annotation.Nullable;
1111
import android.support.annotation.VisibleForTesting;
12+
import android.support.text.emoji.EmojiCompat;
13+
import android.support.text.emoji.bundled.BundledEmojiCompatConfig;
1214
import android.support.v4.util.Pools;
1315
import android.support.v4.util.SimpleArrayMap;
1416
import android.support.v7.widget.LinearLayoutManager;
@@ -75,7 +77,6 @@ final class ChatInteractionComponentImpl extends ChatFlow.Edge implements ChatIn
7577
VerticalSpaceItemDecoration spaceItemDecoration = new VerticalSpaceItemDecoration(space);
7678
uiThreadHandler.post(() -> {
7779
recyclerView.addItemDecoration(spaceItemDecoration);
78-
recyclerView.setItemAnimator(null);
7980
});
8081
}
8182
timer = new Timer();
@@ -85,7 +86,12 @@ final class ChatInteractionComponentImpl extends ChatFlow.Edge implements ChatIn
8586
layoutManager = ((LinearLayoutManager) recyclerView.getLayoutManager());
8687
layoutManager.setSmoothScrollbarEnabled(false);
8788
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(recyclerView.getContext());
88-
uiThreadHandler.post(() -> recyclerView.setAdapter(adapter));
89+
uiThreadHandler.post(() -> {
90+
recyclerView.setItemAnimator(null);
91+
recyclerView.setAdapter(adapter);
92+
EmojiCompat.Config config = new BundledEmojiCompatConfig(recyclerView.getContext());
93+
EmojiCompat.init(config);
94+
});
8995
}
9096

9197
@Override

0 commit comments

Comments
 (0)