pull/605/head
jhengazuji 5 months ago
parent f35cea4100
commit 9830552927
  1. 2
      app/src/main/java/com/fongmi/android/tv/bean/Result.java
  2. 12
      app/src/main/java/com/fongmi/android/tv/gson/DanmakuAdapter.java

@ -232,7 +232,7 @@ public class Result implements Parcelable {
}
public List<Danmaku> getDanmaku() {
return !Setting.isDanmakuLoad() || danmaku == null ? new ArrayList<>() : new ArrayList<>(danmaku);
return !Setting.isDanmakuLoad() || danmaku == null ? new ArrayList<>() : danmaku;
}
public String getFormat() {

@ -9,15 +9,19 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class DanmakuAdapter implements JsonDeserializer<List<Danmaku>> {
@Override
public List<Danmaku> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonPrimitive()) return App.gson().fromJson(json, typeOfT);
String text = json.getAsString().trim();
if (Json.isArray(text)) return App.gson().fromJson(text, typeOfT);
else return List.of(Danmaku.from(text));
List<Danmaku> items = json.isJsonPrimitive() ? parsePrimitive(json.getAsString().trim(), typeOfT) : App.gson().fromJson(json, typeOfT);
return items.stream().filter(d -> !d.isEmpty()).collect(Collectors.toCollection(ArrayList::new));
}
private List<Danmaku> parsePrimitive(String text, Type type) {
return Json.isArray(text) ? App.gson().fromJson(text, type) : List.of(Danmaku.from(text));
}
}

Loading…
Cancel
Save