From d5b4b0fe5400da99a0e9bbb4dae301884a8d7e5b Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Thu, 4 May 2017 14:58:45 +0200 Subject: [PATCH 1/2] fixed crash when media type is unknown --- .../keylesspalace/tusky/entity/Status.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java index 4e147358..20007190 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java @@ -17,6 +17,10 @@ package com.keylesspalace.tusky.entity; import android.text.Spanned; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; import com.google.gson.annotations.SerializedName; import java.util.Date; @@ -115,6 +119,7 @@ public class Status { } public static class MediaAttachment { + @com.google.gson.annotations.JsonAdapter(MediaTypeDeserializer.class) public enum Type { @SerializedName("image") IMAGE, @@ -122,7 +127,7 @@ public class Status { GIFV, @SerializedName("video") VIDEO, - UNKNOWN, + UNKNOWN } public String url; @@ -137,6 +142,23 @@ public class Status { public String remoteUrl; public Type type; + + static class MediaTypeDeserializer implements JsonDeserializer { + @Override + public Type deserialize(JsonElement json, java.lang.reflect.Type classOfT, JsonDeserializationContext context) + throws JsonParseException { + switch(json.toString()) { + case "image": + return Type.IMAGE; + case "gifv": + return Type.GIFV; + case "video": + return Type.VIDEO; + default: + return Type.UNKNOWN; + } + } + } } public static class Mention { @@ -150,4 +172,6 @@ public class Status { @SerializedName("username") public String localUsername; } + + } From 4e4c39e58e353a81e6906f549798817d1e0c26ca Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Thu, 4 May 2017 16:25:04 +0200 Subject: [PATCH 2/2] added missing quotation marks in MediaTypeDeserializer --- .../main/java/com/keylesspalace/tusky/entity/Status.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java index 20007190..c98ebfa5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java @@ -148,11 +148,11 @@ public class Status { public Type deserialize(JsonElement json, java.lang.reflect.Type classOfT, JsonDeserializationContext context) throws JsonParseException { switch(json.toString()) { - case "image": + case "\"image\"": return Type.IMAGE; - case "gifv": + case "\"gifv\"": return Type.GIFV; - case "video": + case "\"video\"": return Type.VIDEO; default: return Type.UNKNOWN;