mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
logansqaure 1.3.4
This commit is contained in:
parent
c03b90f99d
commit
f8bededf33
@ -21,8 +21,7 @@ package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.ExtendedProfile;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/7/8.
|
||||
@ -52,9 +51,9 @@ public class ExtendedProfile {
|
||||
int month;
|
||||
@JsonField(name = "year")
|
||||
int year;
|
||||
@JsonField(name = "visibility")
|
||||
@JsonField(name = "visibility", typeConverter = Visibility.Converter.class)
|
||||
Visibility visibility;
|
||||
@JsonField(name = "year_visibility")
|
||||
@JsonField(name = "year_visibility", typeConverter = Visibility.Converter.class)
|
||||
Visibility yearVisibility;
|
||||
|
||||
public int getDay() {
|
||||
@ -78,13 +77,32 @@ public class ExtendedProfile {
|
||||
}
|
||||
|
||||
public enum Visibility {
|
||||
MUTUALFOLLOW, PUBLIC, UNKNOWN;
|
||||
MUTUALFOLLOW("mutualfollow"), PUBLIC("public"), UNKNOWN(null);
|
||||
|
||||
private final String literal;
|
||||
|
||||
Visibility(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static Visibility parse(String s) {
|
||||
if ("mutualfollow".equals(s)) return MUTUALFOLLOW;
|
||||
if ("public".equals(s)) return PUBLIC;
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<Visibility> {
|
||||
|
||||
@Override
|
||||
public Visibility getFromString(String string) {
|
||||
return Visibility.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Visibility object) {
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class PageableResponseList$$JsonObjectMapper<T> extends JsonMapper<PageableResponseList<T>> {
|
||||
private final JsonMapper<T> m84ClassJsonMapper;
|
||||
|
||||
public PageableResponseList$$JsonObjectMapper(ParameterizedType type, ParameterizedType TType, SimpleArrayMap<ParameterizedType, JsonMapper> partialMappers) {
|
||||
partialMappers.put(type, this);
|
||||
//noinspection unchecked
|
||||
m84ClassJsonMapper = LoganSquare.mapperFor(TType, partialMappers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageableResponseList<T> parse(JsonParser jsonParser) throws IOException {
|
||||
if (jsonParser.getCurrentToken() == null) {
|
||||
jsonParser.nextToken();
|
||||
}
|
||||
PageableResponseList<T> instance = new PageableResponseList<>();
|
||||
final JsonToken currentToken = jsonParser.getCurrentToken();
|
||||
if (currentToken == JsonToken.START_OBJECT) {
|
||||
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
|
||||
String fieldName = jsonParser.getCurrentName();
|
||||
jsonParser.nextToken();
|
||||
parseField(instance, fieldName, jsonParser);
|
||||
jsonParser.skipChildren();
|
||||
}
|
||||
} else if (currentToken == JsonToken.START_ARRAY) {
|
||||
instance.addAll(m84ClassJsonMapper.parseList(jsonParser));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseField(PageableResponseList<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
|
||||
switch (fieldName) {
|
||||
case "users":
|
||||
case "statuses":
|
||||
case "lists": {
|
||||
instance.addAll(m84ClassJsonMapper.parseList(jsonParser));
|
||||
break;
|
||||
}
|
||||
case "previous_cursor": {
|
||||
instance.previousCursor = jsonParser.getValueAsLong();
|
||||
}
|
||||
case "next_cursor": {
|
||||
instance.nextCursor = jsonParser.getValueAsLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PageableResponseList<T> object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
|
||||
|
||||
}
|
||||
}
|
@ -19,8 +19,6 @@
|
||||
|
||||
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;
|
||||
|
||||
@ -29,11 +27,12 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Created by mariotaku on 15/5/7.
|
||||
*/
|
||||
@JsonObject
|
||||
public class PageableResponseList<T> extends ArrayList<T> implements TwitterResponse, CursorSupport {
|
||||
|
||||
private int accessLevel;
|
||||
private RateLimitStatus rateLimitStatus;
|
||||
long previousCursor;
|
||||
long nextCursor;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -24,14 +24,6 @@ import android.support.annotation.Nullable;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.Entities;
|
||||
import org.mariotaku.twidere.api.twitter.model.EntitySupport;
|
||||
import org.mariotaku.twidere.api.twitter.model.HashtagEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.MediaEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.UrlEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
import org.mariotaku.twidere.api.twitter.model.UserMentionEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -224,7 +216,13 @@ public class PrivateDirectMessages {
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
ONE_TO_ONE, GROUP_DM
|
||||
ONE_TO_ONE("one_to_one"), GROUP_DM("group_dm");
|
||||
|
||||
private final String literal;
|
||||
|
||||
Type(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonObject
|
||||
|
@ -43,15 +43,30 @@ public final class ResponseList$$JsonObjectMapper<T> extends JsonMapper<Response
|
||||
if (jsonParser.getCurrentToken() == null) {
|
||||
jsonParser.nextToken();
|
||||
}
|
||||
if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
|
||||
if (m84ClassJsonMapper instanceof ScheduledStatus$$JsonObjectMapper) {
|
||||
ResponseList<T> instance = new ResponseList<>();
|
||||
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
|
||||
String fieldName = jsonParser.getCurrentName();
|
||||
jsonParser.nextToken();
|
||||
parseField(instance, fieldName, jsonParser);
|
||||
jsonParser.skipChildren();
|
||||
}
|
||||
return instance;
|
||||
} else if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
|
||||
jsonParser.skipChildren();
|
||||
return null;
|
||||
}
|
||||
return new ResponseList<T>(m84ClassJsonMapper.parseList(jsonParser));
|
||||
return new ResponseList<>(m84ClassJsonMapper.parseList(jsonParser));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseField(ResponseList<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
|
||||
switch (fieldName) {
|
||||
case "results": {
|
||||
instance.addAll(m84ClassJsonMapper.parseList(jsonParser));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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 org.mariotaku.twidere.api.twitter.util.TwitterDateConverter;
|
||||
|
||||
@ -48,7 +49,7 @@ public class ScheduledStatus {
|
||||
boolean possiblySensitive;
|
||||
@JsonField(name = "user_id")
|
||||
long userId;
|
||||
@JsonField(name = "state")
|
||||
@JsonField(name = "state", typeConverter = State.Converter.class)
|
||||
State state;
|
||||
|
||||
public long getUserId() {
|
||||
@ -90,18 +91,18 @@ public class ScheduledStatus {
|
||||
public enum State {
|
||||
SCHEDULED("scheduled"), FAILED("failed"), CANCELED("canceled");
|
||||
|
||||
private final String value;
|
||||
private final String literal;
|
||||
|
||||
State(String value) {
|
||||
this.value = value;
|
||||
State(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static State parse(String value) {
|
||||
if (SCHEDULED.value.equalsIgnoreCase(value)) {
|
||||
if (SCHEDULED.literal.equalsIgnoreCase(value)) {
|
||||
return SCHEDULED;
|
||||
} else if (FAILED.value.equalsIgnoreCase(value)) {
|
||||
} else if (FAILED.literal.equalsIgnoreCase(value)) {
|
||||
return FAILED;
|
||||
} else if (CANCELED.value.equalsIgnoreCase(value)) {
|
||||
} else if (CANCELED.literal.equalsIgnoreCase(value)) {
|
||||
return CANCELED;
|
||||
}
|
||||
return null;
|
||||
@ -109,7 +110,20 @@ public class ScheduledStatus {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
return literal;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<State> {
|
||||
|
||||
@Override
|
||||
public State getFromString(String string) {
|
||||
return State.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(State object) {
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.ScheduledStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponseObject;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/7/9.
|
||||
*/
|
||||
@JsonObject
|
||||
public class ScheduledStatusesList extends AbstractList<ScheduledStatus> implements TwitterResponse {
|
||||
|
||||
@JsonField(name = "results")
|
||||
List<ScheduledStatus> list;
|
||||
|
||||
TwitterResponseObject response = new TwitterResponseObject();
|
||||
|
||||
@Override
|
||||
public void processResponseHeader(RestHttpResponse resp) {
|
||||
response.processResponseHeader(resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledStatus get(int location) {
|
||||
return list.get(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccessLevel() {
|
||||
return response.getAccessLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RateLimitStatus getRateLimitStatus() {
|
||||
return response.getRateLimitStatus();
|
||||
}
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ public class UserList extends TwitterResponseObject implements Comparable<UserLi
|
||||
@JsonField(name = "member_count")
|
||||
long memberCount;
|
||||
|
||||
@JsonField(name = "mode")
|
||||
@JsonField(name = "mode", typeConverter = Mode.Converter.class)
|
||||
Mode mode;
|
||||
|
||||
@JsonField(name = "description")
|
||||
|
@ -43,10 +43,10 @@ public class MediaEvent extends BaseEvent implements Parcelable {
|
||||
@JsonField(name = "user_id")
|
||||
long userId;
|
||||
|
||||
@JsonField(name = "tweet_type", typeConverter = TweetType.TweetTypeConverter.class)
|
||||
@JsonField(name = "tweet_type", typeConverter = TweetType.Converter.class)
|
||||
TweetType tweetType;
|
||||
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.Converter.class)
|
||||
TimelineType timelineType;
|
||||
|
||||
@JsonField(name = "preview_url")
|
||||
|
@ -52,7 +52,7 @@ public class NotificationEvent extends BaseEvent implements Parcelable {
|
||||
@JsonField(name = "type")
|
||||
String type;
|
||||
|
||||
@JsonField(name = "action", typeConverter = Action.NotificationActionConverter.class)
|
||||
@JsonField(name = "action", typeConverter = Action.Converter.class)
|
||||
Action action;
|
||||
|
||||
@JsonField(name = "ringer_mode")
|
||||
@ -183,7 +183,7 @@ public class NotificationEvent extends BaseEvent implements Parcelable {
|
||||
}
|
||||
|
||||
|
||||
public static class NotificationActionConverter extends StringBasedTypeConverter<Action> {
|
||||
public static class Converter extends StringBasedTypeConverter<Action> {
|
||||
|
||||
@Override
|
||||
public Action getFromString(String string) {
|
||||
|
@ -40,7 +40,7 @@ public class RefreshEvent extends BaseEvent implements Parcelable {
|
||||
@ParcelableThisPlease
|
||||
long[] ids;
|
||||
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.Converter.class)
|
||||
@ParcelableThisPlease
|
||||
TimelineType timelineType;
|
||||
|
||||
|
@ -31,7 +31,7 @@ import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
@JsonObject
|
||||
public class ScreenEvent extends BaseEvent {
|
||||
|
||||
@JsonField(name = "action", typeConverter = Action.ScreenActionConverter.class)
|
||||
@JsonField(name = "action", typeConverter = Action.Conveter.class)
|
||||
Action action;
|
||||
@JsonField(name = "present_duration")
|
||||
long presentDuration;
|
||||
@ -88,7 +88,7 @@ public class ScreenEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
|
||||
public static class ScreenActionConverter extends StringBasedTypeConverter<Action> {
|
||||
public static class Conveter extends StringBasedTypeConverter<Action> {
|
||||
|
||||
@Override
|
||||
public Action getFromString(String string) {
|
||||
|
@ -42,7 +42,7 @@ public enum TimelineType {
|
||||
return OTHER;
|
||||
}
|
||||
|
||||
public static class TimelineTypeConverter extends StringBasedTypeConverter<TimelineType> {
|
||||
public static class Converter extends StringBasedTypeConverter<TimelineType> {
|
||||
|
||||
@Override
|
||||
public TimelineType getFromString(String string) {
|
||||
|
@ -48,13 +48,13 @@ public class TweetEvent extends BaseEvent implements Parcelable {
|
||||
@JsonField(name = "user_id")
|
||||
long userId;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "tweet_type", typeConverter = TweetType.TweetTypeConverter.class)
|
||||
@JsonField(name = "tweet_type", typeConverter = TweetType.Converter.class)
|
||||
TweetType tweetType;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.TimelineTypeConverter.class)
|
||||
@JsonField(name = "timeline_type", typeConverter = TimelineType.Converter.class)
|
||||
TimelineType timelineType;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "action", typeConverter = Action.TweetActionConverter.class)
|
||||
@JsonField(name = "action", typeConverter = Action.Converter.class)
|
||||
Action action;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "following")
|
||||
@ -140,7 +140,7 @@ public class TweetEvent extends BaseEvent implements Parcelable {
|
||||
}
|
||||
|
||||
|
||||
public static class TweetActionConverter extends StringBasedTypeConverter<Action> {
|
||||
public static class Converter extends StringBasedTypeConverter<Action> {
|
||||
|
||||
@Override
|
||||
public Action getFromString(String string) {
|
||||
|
@ -73,7 +73,7 @@ public enum TweetType {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static class TweetTypeConverter extends StringBasedTypeConverter<TweetType> {
|
||||
public static class Converter extends StringBasedTypeConverter<TweetType> {
|
||||
|
||||
@Override
|
||||
public TweetType getFromString(String string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user