From 40ce0cebe0a3762c2336e34b0770e7e2f80ee8c3 Mon Sep 17 00:00:00 2001 From: Veeti Paananen Date: Thu, 31 Jul 2014 02:49:36 +0300 Subject: [PATCH] Fix emoji backwards compatibility recents crash The old emoji drawer stored emoji with a .png suffix. Replace it during list deserialization. --- src/org/thoughtcrime/securesms/util/Emoji.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/util/Emoji.java b/src/org/thoughtcrime/securesms/util/Emoji.java index 895d640af0..904821817e 100644 --- a/src/org/thoughtcrime/securesms/util/Emoji.java +++ b/src/org/thoughtcrime/securesms/util/Emoji.java @@ -20,6 +20,11 @@ import android.util.SparseArray; import android.view.View; import com.google.thoughtcrimegson.Gson; +import com.google.thoughtcrimegson.GsonBuilder; +import com.google.thoughtcrimegson.JsonDeserializationContext; +import com.google.thoughtcrimegson.JsonDeserializer; +import com.google.thoughtcrimegson.JsonElement; +import com.google.thoughtcrimegson.JsonParseException; import com.google.thoughtcrimegson.reflect.TypeToken; import org.thoughtcrime.securesms.R; @@ -305,8 +310,16 @@ public class Emoji { String serialized = prefs.getString(EMOJI_LRU_PREFERENCE, "[]"); Type type = new TypeToken>() { }.getType(); + JsonDeserializer backwardsDeserializer = new JsonDeserializer() { + @Override + public String deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + return jsonElement.getAsString().replace(".png", ""); + } + }; - recentlyUsed = new Gson().fromJson(serialized, type); + recentlyUsed = new GsonBuilder().registerTypeAdapter(String.class, backwardsDeserializer) + .create().fromJson(serialized, type); } public static String[] getRecentlyUsed(Context context) {