diff --git a/settings.gradle b/settings.gradle index 6b9249062..08d6fbebb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,6 @@ include ':twidere.component.twitter4j' include ':twidere.component.twitter4j.streaming' include ':twidere.component.common' include ':twidere.library.extension' -include ':twidere.component.jsonserializer' include ':twidere.component.querybuilder' include ':twidere.wear' include ':twidere.donate.nyanwp' diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java index 35ceb45b1..d58e0a69d 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java @@ -82,6 +82,7 @@ public class ParcelableAccount implements Parcelable { @JsonField(name = "is_dummy") public boolean is_dummy; + public ParcelableAccount(final Cursor cursor, final Indices indices) { is_dummy = false; screen_name = indices.screen_name != -1 ? cursor.getString(indices.screen_name) : null; @@ -104,15 +105,7 @@ public class ParcelableAccount implements Parcelable { color = source.readInt(); } - private ParcelableAccount() { - is_dummy = true; - screen_name = null; - name = null; - account_id = -1; - profile_image_url = null; - profile_banner_url = null; - color = 0; - is_activated = false; + public ParcelableAccount() { } @Override @@ -334,6 +327,9 @@ public class ParcelableAccount implements Parcelable { @JsonField(name = "no_version_suffix") public boolean no_version_suffix; + public ParcelableCredentials() { + } + public ParcelableCredentials(final Cursor cursor, final Indices indices) { super(cursor, indices); auth_type = cursor.getInt(indices.auth_type); diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java index 39031f37f..71255179e 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java @@ -106,6 +106,9 @@ public class ParcelableDirectMessage implements Parcelable, Comparable TIMESTAMP_COMPARATOR = new Comparator() { - - @Override - public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { - final long diff = object2.timestamp - object1.timestamp; - if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; - if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; - return (int) diff; - } - }; + @JsonField(name = "id") + public long id; public static final Comparator REVERSE_ID_COMPARATOR = new Comparator() { @Override @@ -85,120 +80,127 @@ public class ParcelableStatus implements Parcelable, Comparable TIMESTAMP_COMPARATOR = new Comparator() { + + @Override + public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { + final long diff = object2.timestamp - object1.timestamp; + if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; + if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; + return (int) diff; + } + }; @JsonField(name = "user_id") - public long user_id; + public long user_id; @JsonField(name = "retweet_id") - public long retweet_id; + public long retweet_id; @JsonField(name = "retweeted_by_id") - public long retweeted_by_id; + public long retweeted_by_id; @JsonField(name = "retweet_timestamp") - public long retweet_timestamp; + public long retweet_timestamp; @JsonField(name = "retweet_count") - public long retweet_count; + public long retweet_count; @JsonField(name = "favorite_count") - public long favorite_count; + public long favorite_count; @JsonField(name = "reply_count") - public long reply_count; + public long reply_count; @JsonField(name = "descendent_reply_count") - public long descendent_reply_count; + public long descendent_reply_count; @JsonField(name = "in_reply_to_status_id") - public long in_reply_to_status_id; + public long in_reply_to_status_id; @JsonField(name = "in_reply_to_user_id") - public long in_reply_to_user_id; + public long in_reply_to_user_id; @JsonField(name = "my_retweet_id") - public long my_retweet_id; + public long my_retweet_id; @JsonField(name = "quote_id") - public long quote_id; + public long quote_id; @JsonField(name = "quote_timestamp") - public long quote_timestamp; + public long quote_timestamp; @JsonField(name = "quoted_by_user_id") - public long quoted_by_user_id; + public long quoted_by_user_id; @JsonField(name = "is_gap") - public boolean is_gap; + public boolean is_gap; @JsonField(name = "is_retweet") - public boolean is_retweet; + public boolean is_retweet; @JsonField(name = "is_favorite") - public boolean is_favorite; + public boolean is_favorite; @JsonField(name = "is_possibly_sensitive") - public boolean is_possibly_sensitive; + public boolean is_possibly_sensitive; @JsonField(name = "user_is_following") - public boolean user_is_following; + public boolean user_is_following; @JsonField(name = "user_is_protected") - public boolean user_is_protected; + public boolean user_is_protected; @JsonField(name = "user_is_verified") - public boolean user_is_verified; + public boolean user_is_verified; @JsonField(name = "is_quote") - public boolean is_quote; + public boolean is_quote; @JsonField(name = "quoted_by_user_is_protected") - public boolean quoted_by_user_is_protected; + public boolean quoted_by_user_is_protected; @JsonField(name = "quoted_by_user_is_verified") - public boolean quoted_by_user_is_verified; + public boolean quoted_by_user_is_verified; @JsonField(name = "retweeted_by_name") - public String retweeted_by_name; + public String retweeted_by_name; @JsonField(name = "retweeted_by_screen_name") - public String retweeted_by_screen_name; + public String retweeted_by_screen_name; @JsonField(name = "retweeted_by_profile_image") - public String retweeted_by_profile_image; + public String retweeted_by_profile_image; @JsonField(name = "text_html") - public String text_html; + public String text_html; @JsonField(name = "text_plain") - public String text_plain; + public String text_plain; @JsonField(name = "user_name") - public String user_name; + public String user_name; @JsonField(name = "user_screen_name") - public String user_screen_name; + public String user_screen_name; @JsonField(name = "in_reply_to_name") - public String in_reply_to_name; + public String in_reply_to_name; @JsonField(name = "in_reply_to_screen_name") - public String in_reply_to_screen_name; + public String in_reply_to_screen_name; @JsonField(name = "source") - public String source; + public String source; @JsonField(name = "user_profile_image_url") - public String user_profile_image_url; + public String user_profile_image_url; @JsonField(name = "text_unescaped") - public String text_unescaped; + public String text_unescaped; @JsonField(name = "card_name") - public String card_name; + public String card_name; @JsonField(name = "quote_text_html") - public String quote_text_html; + public String quote_text_html; @JsonField(name = "quote_text_plain") - public String quote_text_plain; + public String quote_text_plain; @JsonField(name = "quote_text_unescaped") - public String quote_text_unescaped; + public String quote_text_unescaped; @JsonField(name = "quote_source") - public String quote_source; + public String quote_source; @JsonField(name = "quoted_by_user_name") - public String quoted_by_user_name; + public String quoted_by_user_name; @JsonField(name = "quoted_by_user_screen_name") - public String quoted_by_user_screen_name; + public String quoted_by_user_screen_name; @JsonField(name = "quoted_by_user_profile_image") - public String quoted_by_user_profile_image; + public String quoted_by_user_profile_image; @JsonField(name = "location") - public ParcelableLocation location; + public ParcelableLocation location; @JsonField(name = "place_full_name") - public String place_full_name; + public String place_full_name; @JsonField(name = "mentions") - public ParcelableUserMention[] mentions; + public ParcelableUserMention[] mentions; @JsonField(name = "media") - public ParcelableMedia[] media; + public ParcelableMedia[] media; @JsonField(name = "quote_media") - public ParcelableMedia[] quote_media; + public ParcelableMedia[] quote_media; @JsonField(name = "card") - public ParcelableCardEntity card; + public ParcelableCardEntity card; public ParcelableStatus(final Cursor c, final CursorIndices idx) { id = idx.status_id != -1 ? c.getLong(idx.status_id) : -1; @@ -703,12 +705,19 @@ public class ParcelableStatus implements Parcelable, Comparable values; public ParcelableCardEntity(Parcel src) { name = src.readString(); - values = src.createTypedArray(ParcelableValueItem.CREATOR); users = src.createTypedArray(ParcelableUser.CREATOR); + final Bundle bundle = src.readBundle(ParcelableBindingValue.class.getClassLoader()); + for (String key : bundle.keySet()) { + if (values == null) { + values = new HashMap<>(); + } + final ParcelableBindingValue value = bundle.getParcelable(key); + values.put(key, value); + } } public ParcelableCardEntity() { @@ -718,15 +727,7 @@ public class ParcelableStatus implements Parcelable, Comparable CREATOR = new Parcelable.Creator() { - @Override - public ParcelableUserValue createFromParcel(final Parcel in) { - return new ParcelableUserValue(in); - } - - @Override - public ParcelableUserValue[] newArray(final int size) { - return new ParcelableUserValue[size]; - } - }; - - @JsonField(name = "id") - public long id; - - public ParcelableUserValue() { - - } - - public ParcelableUserValue(Parcel in) { - this.id = in.readLong(); - } - - public ParcelableUserValue(UserValue value) { - this.id = value.getUserId(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(id); - } - - } - - - @Override - public int describeContents() { - return 0; - } - - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(name); - dest.writeTypedArray(values, flags); - dest.writeTypedArray(users, flags); - } - - - @JsonObject - public static final class ParcelableValueItem implements Parcelable { - - public static final Creator CREATOR = new Creator() { - @Override - public ParcelableValueItem createFromParcel(final Parcel in) { - return new ParcelableValueItem(in); - } - - @Override - public ParcelableValueItem[] newArray(final int size) { - return new ParcelableValueItem[size]; - } - }; - - - @JsonField(name = "name") - public String name; @JsonField(name = "type") public String type; @JsonField(name = "value") - public Object value; + public String value; - public ParcelableValueItem() { + public ParcelableBindingValue() { } - public ParcelableValueItem(Parcel in) { - this.name = in.readString(); + public ParcelableBindingValue(Parcel in) { this.type = in.readString(); - this.value = in.readValue(ParcelableValueItem.class.getClassLoader()); + this.value = in.readString(); } - public ParcelableValueItem(BindingValue bindingValue) { - name = bindingValue.getName(); - type = bindingValue.getType(); - switch (type) { - case BindingValue.TYPE_STRING: - value = ((StringValue) bindingValue).getValue(); - break; - case BindingValue.TYPE_BOOLEAN: - value = ((BooleanValue) bindingValue).getValue(); - break; - case BindingValue.TYPE_IMAGE: - value = new ParcelableImageValue((ImageValue) bindingValue); - break; - case BindingValue.TYPE_USER: - value = new ParcelableUserValue((UserValue) bindingValue); - break; - default: - value = null; - break; + public ParcelableBindingValue(BindingValue value) { + this.type = value.getType(); + if (BindingValue.TYPE_IMAGE.equals(type)) { + this.value = ((ImageValue) value).getUrl(); + } else if (BindingValue.TYPE_STRING.equals(type)) { + this.value = ((StringValue) value).getValue(); + } else if (BindingValue.TYPE_BOOLEAN.equals(type)) { + this.value = String.valueOf(((BooleanValue) value).getValue()); + } else if (BindingValue.TYPE_USER.equals(type)) { + this.value = String.valueOf(((UserValue) value).getUserId()); } } @@ -927,23 +822,24 @@ public class ParcelableStatus implements Parcelable, ComparableParcelableStatusUpdate.Builder instead. diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java index 2e79a4a09..0325e6b1f 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java @@ -120,6 +120,9 @@ public class ParcelableUser implements Parcelable, Comparable { @JsonField(name = "is_basic") public boolean is_basic; + public ParcelableUser() { + } + public ParcelableUser(final long account_id, final long id, final String name, final String screen_name, final String profile_image_url) { this.account_id = account_id; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java index bf0177ca2..4be001fe2 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java @@ -74,6 +74,8 @@ public class ParcelableUserList implements Parcelable, Comparable - * - * 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 . - */ - -apply plugin: 'com.android.library' -apply from: rootProject.file('global.gradle') - -android { - defaultConfig { - minSdkVersion 14 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) -} diff --git a/twidere.component.jsonserializer/proguard-rules.pro b/twidere.component.jsonserializer/proguard-rules.pro deleted file mode 100644 index ee5b46f04..000000000 --- a/twidere.component.jsonserializer/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/mariotaku/Tools/android-sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/twidere.component.jsonserializer/src/androidTest/java/org/mariotaku/jsonserializer/ApplicationTest.java b/twidere.component.jsonserializer/src/androidTest/java/org/mariotaku/jsonserializer/ApplicationTest.java deleted file mode 100644 index 47e06a963..000000000 --- a/twidere.component.jsonserializer/src/androidTest/java/org/mariotaku/jsonserializer/ApplicationTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.jsonserializer; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/twidere.component.jsonserializer/src/main/AndroidManifest.xml b/twidere.component.jsonserializer/src/main/AndroidManifest.xml deleted file mode 100644 index f4a7ccc54..000000000 --- a/twidere.component.jsonserializer/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - \ No newline at end of file diff --git a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONArrayParcel.java b/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONArrayParcel.java deleted file mode 100644 index bce0eb28f..000000000 --- a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONArrayParcel.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.jsonserializer; - -import org.json.JSONArray; -import org.mariotaku.jsonserializer.JSONParcelable.Creator; - -/** - * Created by mariotaku on 15/1/1. - */ -public final class JSONArrayParcel { - - private final JSONArray jsonArray; - - JSONArrayParcel(JSONArray json) { - if (json == null) throw new NullPointerException(); - jsonArray = json; - } - - public String readString(int index) { - return jsonArray.optString(index); - } - - public T readParcelable(int index, Creator creator) { - final JSONParcel parcel = new JSONParcel(jsonArray.optJSONObject(index)); - return creator.createFromParcel(parcel); - } - - - public int size() { - return jsonArray.length(); - } -} diff --git a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcel.java b/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcel.java deleted file mode 100644 index a2eec4f44..000000000 --- a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcel.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.jsonserializer; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - -public final class JSONParcel { - - private final JSONObject jsonObject; - - JSONParcel() { - this(new JSONObject()); - } - - JSONParcel(final JSONObject json) { - if (json == null) throw new NullPointerException(); - jsonObject = json; - } - - public boolean contains(final String key) { - return jsonObject.has(key); - } - - public JSONObject getJSON() { - return jsonObject; - } - - public boolean isNull(String key) { - return jsonObject.isNull(key); - } - - public boolean readBoolean(final String key) { - return jsonObject.optBoolean(key); - } - - public boolean readBoolean(final String key, final boolean def) { - return jsonObject.optBoolean(key, def); - } - - public double readDouble(final String key) { - return jsonObject.optDouble(key); - } - - public double readDouble(final String key, final double def) { - return jsonObject.optDouble(key, def); - } - - public float readFloat(final String key, final float def) { - return (float) readDouble(key, def); - } - - public int readInt(final String key) { - return jsonObject.optInt(key); - } - - public int readInt(final String key, final int def) { - return jsonObject.optInt(key, def); - } - - public JSONObject readJSONObject(final String key) { - return jsonObject.optJSONObject(key); - } - - public JSONArray readJSONArray(final String key) { - return jsonObject.optJSONArray(key); - } - - public JSONArrayParcel readJSONArrayParcel(final String key) { - if (jsonObject.isNull(key)) return null; - return new JSONArrayParcel(readJSONArray(key)); - } - - public String[] readStringArray(final String key) { - if (jsonObject.isNull(key)) return null; - final JSONArray array = jsonObject.optJSONArray(key); - final String[] stringArray = new String[array.length()]; - for (int i = 0, j = array.length(); i < j; i++) { - try { - stringArray[i] = array.getString(i); - } catch (JSONException e) { - return null; - } - } - return stringArray; - } - - public long readLong(final String key) { - return jsonObject.optLong(key); - } - - public long readLong(final String key, final long def) { - return jsonObject.optLong(key, def); - } - - public Object readObject(final String key) { - return jsonObject.opt(key); - } - - public T readParcelable(final String key, final JSONParcelable.Creator creator) { - return JSONSerializer.createObject(creator, jsonObject.optJSONObject(key)); - } - - public T[] readParcelableArray(final String key, final JSONParcelable.Creator creator) { - return JSONSerializer.createArray(creator, jsonObject.optJSONArray(key)); - } - - public String readString(final String key) { - return readString(key, null); - } - - public String readString(final String key, final String def) { - return jsonObject.optString(key, def); - } - - public void writeBoolean(final String key, final boolean value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeBooleanArray(final String key, final boolean[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final boolean item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeDouble(final String key, final double value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeDoubleArray(final String key, final double[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final double item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeFloat(final String key, final float value) { - writeDouble(key, value); - } - - public void writeFloatArray(final String key, final float[] value) { - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final float item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeInt(final String key, final int value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeIntArray(final String key, final int[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final int item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeJSONArray(final String key, final JSONArray value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeJSONObject(final String key, final JSONObject value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeLong(final String key, final long value) { - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeLongArray(final String key, final long[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final long item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeObject(final String key, final Object value) { - if (value instanceof JSONParcelable) { - writeParcelable(key, (JSONParcelable) value); - return; - } - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeObjectArray(final String key, final Object[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final Object item : value) { - if (item instanceof JSONParcelable) { - final JSONObject json = JSONSerializer.toJSONObject((JSONParcelable) item); - array.put(json); - } else { - array.put(item); - } - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeObjectList(final String key, final List value) { - if (key == null) return; - writeObjectArray(key, value.toArray()); - } - - public void writeParcelable(final String key, final T value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONObject json = JSONSerializer.toJSONObject(value); - jsonObject.put(key, json); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeParcelableArray(final String key, final T[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final T item : value) { - final JSONObject json = JSONSerializer.toJSONObject(item); - array.put(json != null ? json : JSONObject.NULL); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeString(final String key, final String value) { - if (key == null) return; - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeStringArray(final String key, final String[] value) { - if (key == null) return; - try { - if (value == null) { - jsonObject.put(key, JSONObject.NULL); - return; - } - final JSONArray array = new JSONArray(); - for (final String item : value) { - array.put(item); - } - jsonObject.put(key, array); - } catch (final JSONException e) { - e.printStackTrace(); - } - } - - public void writeValue(final String key, final Object value) { - if (key == null) return; - try { - jsonObject.put(key, value); - } catch (final JSONException e) { - e.printStackTrace(); - } - } -} diff --git a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcelable.java b/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcelable.java deleted file mode 100644 index 9d563d5ff..000000000 --- a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONParcelable.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to - */ - -package org.mariotaku.jsonserializer; - -public interface JSONParcelable { - - public void writeToParcel(JSONParcel out); - - public interface Creator { - - public T createFromParcel(JSONParcel in); - - public T[] newArray(int size); - } -} diff --git a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONSerializer.java b/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONSerializer.java deleted file mode 100644 index 88f2120ba..000000000 --- a/twidere.component.jsonserializer/src/main/java/org/mariotaku/jsonserializer/JSONSerializer.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.jsonserializer; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; - -public class JSONSerializer { - private static boolean debugMode = false; - - public static T[] createArray(final JSONParcelable.Creator creator, - final JSONArray json) { - if (creator == null) throw new NullPointerException("JSON_CREATOR must not be null!"); - if (json == null) return null; - final int size = json.length(); - final T[] array = creator.newArray(size); - for (int i = 0; i < size; i++) { - array[i] = creator.createFromParcel(new JSONParcel(json.optJSONObject(i))); - } - return array; - } - - public static ArrayList createArrayList(final JSONParcelable.Creator creator, - final JSONArray json) { - if (creator == null) throw new NullPointerException("JSON_CREATOR must not be null!"); - if (json == null) return null; - final int size = json.length(); - final ArrayList list = new ArrayList(size); - for (int i = 0; i < size; i++) { - list.add(creator.createFromParcel(new JSONParcel(json.optJSONObject(i)))); - } - return list; - } - - public static T createObject(final JSONParcelable.Creator creator, - final JSONObject json) { - if (creator == null) throw new NullPointerException("JSON_CREATOR must not be null!"); - if (json == null) return null; - return creator.createFromParcel(new JSONParcel(json)); - } - - public static byte[] getByteArray(final T parcelable) { - final JSONObject json = toJSONObject(parcelable); - final String string = jsonToString(json); - if (string == null) return null; - return string.getBytes(Charset.defaultCharset()); - } - - public static byte[] getByteArray(final T[] array) { - final JSONArray json = toJSONArray(array); - final String string = jsonToString(json); - if (string == null) return null; - return string.getBytes(Charset.defaultCharset()); - } - - public static boolean isDebugMode() { - return debugMode; - } - - public static void setIsDebugMode(final boolean debug) { - debugMode = debug; - } - - public static byte[] toByteArray(final T parcelable) throws IOException { - final String jsonString = jsonToString(toJSONObject(parcelable)); - if (jsonString == null) return null; - return jsonString.getBytes(Charset.defaultCharset()); - } - - public static byte[] toByteArray(final T[] array) throws IOException { - final String jsonString = jsonToString(toJSONArray(array)); - if (jsonString == null) return null; - return jsonString.getBytes(Charset.defaultCharset()); - } - - public static JSONArray toJSONArray(final T[] array) { - if (array == null) return null; - final JSONArray json = new JSONArray(); - for (final T parcelable : array) { - json.put(toJSONObject(parcelable)); - } - return json; - } - - public static String toJSONArrayString(final T[] array) { - return jsonToString(toJSONArray(array)); - } - - public static JSONObject toJSONObject(final T parcelable) { - if (parcelable == null) return null; - final JSONObject json = new JSONObject(); - parcelable.writeToParcel(new JSONParcel(json)); - return json; - } - - public static String toJSONObjectString(final T parcelable) { - return jsonToString(toJSONObject(parcelable)); - } - - static String jsonToString(final JSONArray json) { - if (json == null) return null; - if (debugMode) { - try { - return json.toString(4); - } catch (final JSONException e) { - e.printStackTrace(); - } - return json.toString(); - } else - return json.toString(); - } - - static String jsonToString(final JSONObject json) { - if (json == null) return null; - if (debugMode) { - try { - return json.toString(4); - } catch (final JSONException e) { - e.printStackTrace(); - } - return json.toString(); - } else - return json.toString(); - } - -} diff --git a/twidere.component.twitter4j/src/main/java/twitter4j/CardEntity.java b/twidere.component.twitter4j/src/main/java/twitter4j/CardEntity.java index 3c9332cac..d3370ff73 100644 --- a/twidere.component.twitter4j/src/main/java/twitter4j/CardEntity.java +++ b/twidere.component.twitter4j/src/main/java/twitter4j/CardEntity.java @@ -34,7 +34,7 @@ public interface CardEntity extends Serializable { BindingValue getBindingValue(String key); - BindingValue[] getBindingValues(); + java.util.Map getBindingValues(); public interface BindingValue extends Serializable { diff --git a/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java b/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java index d2e45d29f..b21d89059 100644 --- a/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java +++ b/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java @@ -24,6 +24,7 @@ import org.json.JSONObject; import org.mariotaku.twidere.library.twitter4j.BuildConfig; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -52,7 +53,7 @@ public class CardEntityJSONImpl implements CardEntity { public CardEntityJSONImpl(JSONObject json) throws JSONException, TwitterException { this.name = json.getString("name"); this.url = json.optString("url"); - this.bindingValues = BindingValueImpl.valuesOf(json.getJSONObject("binding_values")); + this.bindingValues = Collections.unmodifiableMap(BindingValueImpl.valuesOf(json.getJSONObject("binding_values"))); if (!json.isNull("users")) { final JSONObject usersJSON = json.getJSONObject("users"); final Iterator keys = usersJSON.keys(); @@ -82,8 +83,8 @@ public class CardEntityJSONImpl implements CardEntity { } @Override - public BindingValue[] getBindingValues() { - return bindingValues.values().toArray(new BindingValue[bindingValues.size()]); + public Map getBindingValues() { + return bindingValues; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java index cc19cef2d..75940e8af 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java +++ b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java @@ -33,6 +33,7 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.multidex.MultiDexApplication; +import com.bluelinelabs.logansquare.LoganSquare; import com.nostra13.universalimageloader.cache.disc.DiskCache; import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache; import com.nostra13.universalimageloader.core.ImageLoader; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardFragmentFactory.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardFragmentFactory.java index 1cedaf0ef..24cc474ff 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardFragmentFactory.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardFragmentFactory.java @@ -23,7 +23,9 @@ import android.support.v4.app.Fragment; import org.mariotaku.twidere.fragment.support.CardBrowserFragment; import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity; -import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity.ParcelableValueItem; +import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity.ParcelableBindingValue; + +import twitter4j.CardEntity.BindingValue; /** * Created by mariotaku on 15/1/1. @@ -41,8 +43,8 @@ public abstract class TwitterCardFragmentFactory { } public static Fragment createGenericPlayerFragment(ParcelableCardEntity card) { - final ParcelableValueItem player_url = ParcelableCardEntity.getValue(card, "player_url"); - if (player_url == null) return null; - return CardBrowserFragment.show((String) player_url.value); + final ParcelableBindingValue player_url = ParcelableCardEntity.getValue(card, "player_url"); + if (player_url == null || !BindingValue.TYPE_STRING.equals(player_url.type)) return null; + return CardBrowserFragment.show(player_url.value); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardUtils.java index f8eada1c0..e4b48ede3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterCardUtils.java @@ -24,7 +24,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity; -import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity.ParcelableValueItem; +import org.mariotaku.twidere.model.ParcelableStatus.ParcelableCardEntity.ParcelableBindingValue; /** * Created by mariotaku on 15/1/1. @@ -57,8 +57,8 @@ public class TwitterCardUtils { public static Point getCardSize(ParcelableCardEntity card) { - final ParcelableValueItem player_width = ParcelableCardEntity.getValue(card, "player_width"); - final ParcelableValueItem player_height = ParcelableCardEntity.getValue(card, "player_height"); + final ParcelableBindingValue player_width = ParcelableCardEntity.getValue(card, "player_width"); + final ParcelableBindingValue player_height = ParcelableCardEntity.getValue(card, "player_height"); if (player_width != null && player_height != null) { final int width = ParseUtils.parseInt(String.valueOf(player_width.value)); final int height = ParseUtils.parseInt(String.valueOf(player_height.value));