don't use old emoji recents, broken

Fixes #1782
// FREEBIE
This commit is contained in:
Jake McGinty 2014-08-04 11:55:33 -07:00
parent dda4459e5a
commit eb4ac40051

View File

@ -20,11 +20,6 @@ import android.util.SparseArray;
import android.view.View; import android.view.View;
import com.google.thoughtcrimegson.Gson; 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 com.google.thoughtcrimegson.reflect.TypeToken;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
@ -299,7 +294,7 @@ public class Emoji {
private static class EmojiLRU { private static class EmojiLRU {
private static SharedPreferences prefs = null; private static SharedPreferences prefs = null;
private static LinkedHashSet<String> recentlyUsed = null; private static LinkedHashSet<String> recentlyUsed = null;
private static final String EMOJI_LRU_PREFERENCE = "pref_popular_emoji"; private static final String EMOJI_LRU_PREFERENCE = "pref_recent_emoji";
private static final int EMOJI_LRU_SIZE = 50; private static final int EMOJI_LRU_SIZE = 50;
private static void initializeCache(Context context) { private static void initializeCache(Context context) {
@ -310,16 +305,7 @@ public class Emoji {
String serialized = prefs.getString(EMOJI_LRU_PREFERENCE, "[]"); String serialized = prefs.getString(EMOJI_LRU_PREFERENCE, "[]");
Type type = new TypeToken<LinkedHashSet<String>>() { Type type = new TypeToken<LinkedHashSet<String>>() {
}.getType(); }.getType();
JsonDeserializer<String> backwardsDeserializer = new JsonDeserializer<String>() { recentlyUsed = new Gson().fromJson(serialized, type);
@Override
public String deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return jsonElement.getAsString().replace(".png", "");
}
};
recentlyUsed = new GsonBuilder().registerTypeAdapter(String.class, backwardsDeserializer)
.create().fromJson(serialized, type);
} }
public static String[] getRecentlyUsed(Context context) { public static String[] getRecentlyUsed(Context context) {