mirror of https://github.com/tuskyapp/Tusky.git
7 changed files with 48 additions and 12 deletions
@ -0,0 +1,16 @@
|
||||
package com.keylesspalace.tusky; |
||||
|
||||
/** |
||||
* This is just a wrapper class for a String. |
||||
* |
||||
* It was designed to get around the limitation of a Json deserializer which only allows custom |
||||
* deserializing based on types, when special handling for a specific field was what was actually |
||||
* desired (in this case, display names). So, it was most expedient to just make up a type. |
||||
*/ |
||||
public class StringWithEmoji { |
||||
public String value; |
||||
|
||||
public StringWithEmoji(String value) { |
||||
this.value = value; |
||||
} |
||||
} |
||||
@ -0,0 +1,23 @@
|
||||
package com.keylesspalace.tusky; |
||||
|
||||
import com.emojione.Emojione; |
||||
import com.google.gson.JsonDeserializationContext; |
||||
import com.google.gson.JsonDeserializer; |
||||
import com.google.gson.JsonElement; |
||||
import com.google.gson.JsonParseException; |
||||
|
||||
import java.lang.reflect.Type; |
||||
|
||||
/** This is a type-based workaround to allow for shortcode conversion when loading display names. */ |
||||
class StringWithEmojiTypeAdapter implements JsonDeserializer<StringWithEmoji> { |
||||
@Override |
||||
public StringWithEmoji deserialize(JsonElement json, Type typeOfT, |
||||
JsonDeserializationContext context) throws JsonParseException { |
||||
String value = json.getAsString(); |
||||
if (value != null) { |
||||
return new StringWithEmoji(Emojione.shortnameToUnicode(value, false)); |
||||
} else { |
||||
return new StringWithEmoji(""); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue