this version is for extensions

This commit is contained in:
Mariotaku Lee 2016-04-28 09:03:10 +08:00
parent 20db4a554d
commit 9f601c86d0
5 changed files with 104 additions and 19 deletions

View File

@ -25,9 +25,12 @@ import android.os.Parcelable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.annotation.OnJsonParseComplete;
import com.hannesdorfmann.parcelableplease.annotation.Bagger;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableNoThanks;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import org.mariotaku.twidere.api.twitter.model.util.ParcelMapBagger;
import java.util.HashMap;
import java.util.Map;
@ -45,8 +48,9 @@ public class CardEntity implements Parcelable {
String url;
@JsonField(name = "binding_values")
HashMap<String, RawBindingValue> rawBindingValues;
@ParcelableNoThanks
Map<String, RawBindingValue> rawBindingValues;
@Bagger(BindingValueMapBagger.class)
Map<String, BindingValue> bindingValues;
public String getName() {
@ -88,7 +92,7 @@ public class CardEntity implements Parcelable {
'}';
}
public interface BindingValue {
public interface BindingValue extends Parcelable {
String TYPE_STRING = "STRING";
String TYPE_IMAGE = "IMAGE";
@ -387,4 +391,10 @@ public class CardEntity implements Parcelable {
return new CardEntity[size];
}
};
public static class BindingValueMapBagger extends ParcelMapBagger<BindingValue> {
public BindingValueMapBagger() {
super(BindingValue.class);
}
}
}

View File

@ -6,11 +6,13 @@ import android.support.annotation.StringDef;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.Bagger;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import org.mariotaku.twidere.api.twitter.model.util.ParcelMapBagger;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashMap;
import java.util.Map;
/**
@ -36,10 +38,12 @@ public class DMResponse implements Parcelable {
long lastSeenEvent;
@JsonField(name = "users")
HashMap<String, User> users;
@Bagger(UserMapBagger.class)
Map<String, User> users;
@JsonField(name = "conversations")
HashMap<String, Conversation> conversations;
@Bagger(ConversationMapBagger.class)
Map<String, Conversation> conversations;
@JsonField(name = "entries")
Entry[] entries;
@ -278,7 +282,8 @@ public class DMResponse implements Parcelable {
@Status
String status;
@JsonField(name = "type")
Type type;
@Type
String type;
public Participant[] getParticipants() {
return participants;
@ -304,14 +309,9 @@ public class DMResponse implements Parcelable {
return notificationsDisabled;
}
public enum Type {
ONE_TO_ONE("one_to_one"), GROUP_DM("group_dm");
private final String literal;
Type(String literal) {
this.literal = literal;
}
@StringDef({Type.ONE_TO_ONE, Type.GROUP_DM})
public @interface Type {
String ONE_TO_ONE = "one_to_one", GROUP_DM = "group_dm";
}
@ParcelablePlease
@ -398,4 +398,16 @@ public class DMResponse implements Parcelable {
return new DMResponse[size];
}
};
public static class UserMapBagger extends ParcelMapBagger<User> {
public UserMapBagger() {
super(User.class);
}
}
public static class ConversationMapBagger extends ParcelMapBagger<Conversation> {
public ConversationMapBagger() {
super(Conversation.class);
}
}
}

View File

@ -26,12 +26,14 @@ import android.support.annotation.StringDef;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.Bagger;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import org.mariotaku.twidere.api.twitter.model.util.ParcelMapBagger;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
@ -61,7 +63,8 @@ public class MediaEntity extends UrlEntity implements Parcelable {
@Type
String type;
@JsonField(name = "sizes")
HashMap<String, Size> sizes;
@Bagger(SizeMapBagger.class)
Map<String, Size> sizes;
@JsonField(name = "source_status_id")
long sourceStatusId;
@JsonField(name = "source_user_id")
@ -69,7 +72,8 @@ public class MediaEntity extends UrlEntity implements Parcelable {
@JsonField(name = "video_info")
VideoInfo videoInfo;
@JsonField(name = "features")
HashMap<String, Feature> features;
@Bagger(FeaturesMapBagger.class)
Map<String, Feature> features;
@JsonField(name = "ext_alt_text")
String altText;
@ -470,4 +474,16 @@ public class MediaEntity extends UrlEntity implements Parcelable {
return new MediaEntity[size];
}
};
public static class SizeMapBagger extends ParcelMapBagger<Size> {
public SizeMapBagger() {
super(Size.class);
}
}
public static class FeaturesMapBagger extends ParcelMapBagger<Feature> {
public FeaturesMapBagger() {
super(Feature.class);
}
}
}

View File

@ -0,0 +1,47 @@
package org.mariotaku.twidere.api.twitter.model.util;
import android.os.Parcel;
import android.os.Parcelable;
import com.hannesdorfmann.parcelableplease.ParcelBagger;
import java.util.HashMap;
import java.util.Map;
/**
* Created by mariotaku on 16/4/28.
*/
public abstract class ParcelMapBagger<T extends Parcelable> implements ParcelBagger<Map<String, T>> {
private final Class<T> cls;
protected ParcelMapBagger(Class<T> cls) {
this.cls = cls;
}
@Override
public final void write(Map<String, T> value, Parcel out, int flags) {
if (value == null) {
out.writeInt(-1);
} else {
int size = value.size();
out.writeInt(size);
for (Map.Entry<String, T> entry : value.entrySet()) {
out.writeString(entry.getKey());
out.writeParcelable(entry.getValue(), flags);
}
}
}
@Override
public final Map<String, T> read(Parcel in) {
int size = in.readInt();
if (size < 0) return null;
HashMap<String, T> map = new HashMap<>();
for (int i = 0; i < size; i++) {
final String key = in.readString();
final T value = in.readParcelable(cls.getClassLoader());
map.put(key, value);
}
return map;
}
}

View File

@ -21,8 +21,8 @@ android {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 23
versionCode 194
versionName "3.1.6.1"
versionCode 195
versionName "3.1.6.2"
multiDexEnabled true
generatedDensities = []