Prevent a crash caused by empty emoji

The crash happens because the serialization of recently used emoji uses
';' to separate the emojis.
One of the ASCII emojis however has a ';' in the beginning.
When this one is used by the user,
it causes an empty string to be returned when deserializing.

This commit prevents the crash by changing the separator to a tab.
It uses a different settings string to store the emoji,
so users will lose the list of recently used emoji when they update to
this version.

PS. That wasn't my idea ;)
This commit is contained in:
Torsten Grote
2017-07-28 10:17:38 -03:00
parent 6dbec3a864
commit db842bd7e4
2 changed files with 5 additions and 4 deletions

View File

@@ -104,8 +104,9 @@ public class EmojiPageView extends FrameLayout {
emojiSize + 2 * pad)); emojiSize + 2 * pad));
view = emojiView; view = emojiView;
} }
String emoji = model.getEmoji()[position];
view.setEmoji(emoji);
view.setEmoji(model.getEmoji()[position]);
return view; return view;
} }
} }

View File

@@ -32,7 +32,7 @@ public class RecentEmojiPageModel implements EmojiPageModel {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(RecentEmojiPageModel.class.getName()); Logger.getLogger(RecentEmojiPageModel.class.getName());
private static final String EMOJI_LRU_PREFERENCE = "pref_emoji_recent"; private static final String EMOJI_LRU_PREFERENCE = "pref_emoji_recent2";
private static final int EMOJI_LRU_SIZE = 50; private static final int EMOJI_LRU_SIZE = 50;
private final LinkedHashSet<String> recentlyUsed; // UI thread private final LinkedHashSet<String> recentlyUsed; // UI thread
@@ -98,12 +98,12 @@ public class RecentEmojiPageModel implements EmojiPageModel {
} }
private String serialize(LinkedHashSet<String> emojis) { private String serialize(LinkedHashSet<String> emojis) {
return StringUtils.join(emojis, ";"); return StringUtils.join(emojis, "\t");
} }
private LinkedHashSet<String> deserialize(@Nullable String serialized) { private LinkedHashSet<String> deserialize(@Nullable String serialized) {
if (serialized == null) return new LinkedHashSet<>(); if (serialized == null) return new LinkedHashSet<>();
String[] list = serialized.split(";"); String[] list = serialized.split("\t");
LinkedHashSet<String> result = new LinkedHashSet<>(list.length); LinkedHashSet<String> result = new LinkedHashSet<>(list.length);
Collections.addAll(result, list); Collections.addAll(result, list);
return result; return result;