fixed crash when media type is unknown

This commit is contained in:
Conny Duck 2017-05-04 14:58:45 +02:00
parent bdca1d1c94
commit d5b4b0fe54
1 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,10 @@ package com.keylesspalace.tusky.entity;
import android.text.Spanned; 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 com.google.gson.annotations.SerializedName;
import java.util.Date; import java.util.Date;
@ -115,6 +119,7 @@ public class Status {
} }
public static class MediaAttachment { public static class MediaAttachment {
@com.google.gson.annotations.JsonAdapter(MediaTypeDeserializer.class)
public enum Type { public enum Type {
@SerializedName("image") @SerializedName("image")
IMAGE, IMAGE,
@ -122,7 +127,7 @@ public class Status {
GIFV, GIFV,
@SerializedName("video") @SerializedName("video")
VIDEO, VIDEO,
UNKNOWN, UNKNOWN
} }
public String url; public String url;
@ -137,6 +142,23 @@ public class Status {
public String remoteUrl; public String remoteUrl;
public Type type; public Type type;
static class MediaTypeDeserializer implements JsonDeserializer<Type> {
@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 { public static class Mention {
@ -150,4 +172,6 @@ public class Status {
@SerializedName("username") @SerializedName("username")
public String localUsername; public String localUsername;
} }
} }