logansqaure 1.3.4

This commit is contained in:
Mariotaku Lee 2015-12-13 22:12:08 +08:00
parent 77e8793e67
commit c03b90f99d
5 changed files with 156 additions and 6 deletions

View File

@ -21,6 +21,8 @@ package org.mariotaku.twidere.api.twitter.model;
import android.support.annotation.NonNull;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import org.mariotaku.twidere.util.AbsLogger;
import java.text.SimpleDateFormat;
@ -235,5 +237,19 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
public int getActionId() {
return actionId;
}
public static class Converter extends StringBasedTypeConverter<Action> {
@Override
public Action getFromString(String string) {
return Action.parse(string);
}
@Override
public String convertToString(Action object) {
//TODO use better literal
return object.name().toLowerCase(Locale.US);
}
}
}
}

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.api.twitter.model;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import java.util.Arrays;
import java.util.HashMap;
@ -48,7 +49,7 @@ public class MediaEntity extends UrlEntity {
String displayUrl;
@JsonField(name = "expanded_url")
String expandedUrl;
@JsonField(name = "type")
@JsonField(name = "type", typeConverter = Type.Converter.class)
Type type;
@JsonField(name = "sizes")
HashMap<String, Size> sizes;
@ -129,7 +130,13 @@ public class MediaEntity extends UrlEntity {
}
public enum Type {
PHOTO, VIDEO, ANIMATED_GIF, UNKNOWN;
PHOTO("photo"), VIDEO("video"), ANIMATED_GIF("animated_gif"), UNKNOWN(null);
private final String literal;
Type(String literal) {
this.literal = literal;
}
public static Type parse(String typeString) {
if ("photo".equalsIgnoreCase(typeString)) {
@ -141,6 +148,19 @@ public class MediaEntity extends UrlEntity {
}
return UNKNOWN;
}
public static class Converter extends StringBasedTypeConverter<Type> {
@Override
public Type getFromString(String string) {
return Type.parse(string);
}
@Override
public String convertToString(Type object) {
return object.literal;
}
}
}

View File

@ -0,0 +1,73 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model;
import com.bluelinelabs.logansquare.JsonMapper;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.ParameterizedType;
import com.bluelinelabs.logansquare.util.SimpleArrayMap;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;
public final class ResponseList$$JsonObjectMapper<T> extends JsonMapper<ResponseList<T>> {
private final JsonMapper<T> m84ClassJsonMapper;
public ResponseList$$JsonObjectMapper(ParameterizedType type, ParameterizedType TType, SimpleArrayMap<ParameterizedType, JsonMapper> partialMappers) {
partialMappers.put(type, this);
//noinspection unchecked
m84ClassJsonMapper = LoganSquare.mapperFor(TType, partialMappers);
}
@Override
public ResponseList<T> parse(JsonParser jsonParser) throws IOException {
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
jsonParser.skipChildren();
return null;
}
return new ResponseList<T>(m84ClassJsonMapper.parseList(jsonParser));
}
@Override
public void parseField(ResponseList<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
}
@Override
public void serialize(ResponseList<T> object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
if (object == null) {
jsonGenerator.writeNull();
return;
}
if (writeStartAndEnd) {
jsonGenerator.writeStartArray();
}
for (T t : object) {
m84ClassJsonMapper.serialize(t, jsonGenerator, true);
}
if (writeStartAndEnd) {
jsonGenerator.writeEndArray();
}
}
}

View File

@ -19,22 +19,49 @@
package org.mariotaku.twidere.api.twitter.model;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.twidere.api.twitter.util.InternalParseUtil;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class ResponseList<T> extends ArrayList<T> implements TwitterResponse {
public class ResponseList<T> extends AbstractList<T> implements TwitterResponse {
private List<T> list;
private int accessLevel;
private RateLimitStatus rateLimitStatus;
public ResponseList(List<T> list) {
this.list = list;
}
@Override
public void add(int location, T object) {
list.add(location, object);
}
@Override
public T set(int location, T object) {
return list.set(location, object);
}
@Override
public T get(int location) {
return list.get(location);
}
@Override
public int size() {
return list.size();
}
public ResponseList() {
this(new ArrayList<T>());
}
@Override
public final void processResponseHeader(RestHttpResponse resp) {

View File

@ -23,6 +23,7 @@ import android.support.annotation.NonNull;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import org.mariotaku.twidere.api.twitter.util.TwitterDateConverter;
@ -163,5 +164,18 @@ public class UserList extends TwitterResponseObject implements Comparable<UserLi
public String getMode() {
return mode;
}
public static class Converter extends StringBasedTypeConverter<Mode> {
@Override
public Mode getFromString(String string) {
return Mode.parse(string);
}
@Override
public String convertToString(Mode object) {
return object.mode;
}
}
}
}