updated json classes

This commit is contained in:
Mariotaku Lee 2015-10-21 21:53:46 +08:00
parent b22fdcfe72
commit a73cc68259
68 changed files with 877 additions and 562 deletions

View File

@ -39,6 +39,7 @@ android {
dependencies {
apt 'com.bluelinelabs:logansquare-compiler:1.1.0'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.1'
apt 'com.github.mariotaku.LoganSquareExtension:processor:b6f53c9a4d'
compile 'com.android.support:support-annotations:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.bluelinelabs:logansquare:1.1.0'
@ -46,5 +47,6 @@ dependencies {
compile 'com.github.mariotaku:RestFu:0.9.2'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.github.mariotaku:SQLiteQB:901dd5e72f'
compile 'com.github.mariotaku.LoganSquareExtension:core:b6f53c9a4d'
compile fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@ -133,7 +133,7 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String QUERY_PARAM_READ_POSITION = "param_read_position";
String QUERY_PARAM_READ_POSITIONS = "param_read_positions";
String QUERY_PARAM_LIMIT = "limit";
String QUERY_PARAM_EXTRA_ID = "extra_id";
String QUERY_PARAM_EXTRA = "extra";
String QUERY_PARAM_TIMESTAMP = "timestamp";
String QUERY_PARAM_FROM_NOTIFICATION = "from_notification";
String QUERY_PARAM_NOTIFICATION_TYPE = "notification_type";

View File

@ -0,0 +1,35 @@
/*
* 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.api;
import org.mariotaku.restfu.annotation.method.GET;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.PrivateSearchQuery;
import org.mariotaku.twidere.api.twitter.model.PrivateSearchResult;
/**
* Created by mariotaku on 15/10/21.
*/
public interface PrivateSearchResources {
@GET("/search/universal.json")
PrivateSearchResult searchTweets(PrivateSearchQuery query) throws TwitterException;
}

View File

@ -19,10 +19,14 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.AccountSettingsImpl;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
@Implementation(AccountSettingsImpl.class)
public interface AccountSettings extends TwitterResponse {
/**
* Returns the language used to render Twitter's UII for this user.

View File

@ -19,10 +19,14 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.EnumClass;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.ActivityImpl;
import org.mariotaku.twidere.util.AbsLogger;
import java.util.Date;
@Implementation(ActivityImpl.class)
public interface Activity extends TwitterResponse, Comparable<Activity> {
int ACTION_UNKNOWN = 0x00;
@ -72,6 +76,7 @@ public interface Activity extends TwitterResponse, Comparable<Activity> {
User[] getTargetObjectUsers();
@EnumClass
enum Action {
FAVORITE(ACTION_FAVORITE), FOLLOW(ACTION_FOLLOW), MENTION(ACTION_MENTION), REPLY(ACTION_REPLY),
RETWEET(ACTION_RETWEET), LIST_MEMBER_ADDED(ACTION_LIST_MEMBER_ADDED), LIST_CREATED(ACTION_LIST_CREATED),

View File

@ -19,11 +19,16 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.library.logansquare.extension.annotation.Wrapper;
import org.mariotaku.twidere.api.twitter.model.impl.CardEntityImpl;
import java.util.Map;
/**
* Created by mariotaku on 14/12/31.
*/
@Implementation(CardEntityImpl.class)
public interface CardEntity {
String getName();
@ -36,6 +41,7 @@ public interface CardEntity {
Map<String, BindingValue> getBindingValues();
@Wrapper(CardEntityImpl.BindingValueWrapper.class)
interface BindingValue {
String TYPE_STRING = "STRING";

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.DirectMessageImpl;
import java.util.Date;
/**
@ -26,6 +29,7 @@ import java.util.Date;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Implementation(DirectMessageImpl.class)
public interface DirectMessage extends TwitterResponse, EntitySupport {
/**

View File

@ -19,12 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.ErrorInfoImpl;
/**
* Created by mariotaku on 15/5/7.
*/
@Implementation(ErrorInfoImpl.class)
public interface ErrorInfo {
int getCode();

View File

@ -19,9 +19,14 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.EnumClass;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.ExtendedProfileImpl;
/**
* Created by mariotaku on 15/7/8.
*/
@Implementation(ExtendedProfileImpl.class)
public interface ExtendedProfile {
long getId();
@ -39,6 +44,7 @@ public interface ExtendedProfile {
Visibility getYearVisibility();
@EnumClass
enum Visibility {
MUTUALFOLLOW, PUBLIC, UNKNOWN;

View File

@ -19,37 +19,17 @@
package org.mariotaku.twidere.api.twitter.model;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.library.logansquare.extension.annotation.Mapper;
import org.mariotaku.restfu.http.ValueMap;
import org.mariotaku.twidere.api.twitter.model.impl.GeoPoint;
import java.io.IOException;
/**
* A data class representing geo location.
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Mapper(GeoLocationMapper.class)
public class GeoLocation implements ValueMap {
public static final TypeConverter<GeoLocation> CONVERTER = new TypeConverter<GeoLocation>() {
@Override
public GeoLocation parse(JsonParser jsonParser) throws IOException {
final GeoPoint geoPoint = LoganSquare.mapperFor(GeoPoint.class).parse(jsonParser);
if (geoPoint == null) return null;
return geoPoint.getGeoLocation();
}
@Override
public void serialize(GeoLocation object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
throw new UnsupportedOperationException();
}
};
double latitude;
double longitude;

View File

@ -0,0 +1,46 @@
/*
* 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.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.twidere.api.twitter.model.impl.GeoPoint;
import java.io.IOException;
/**
* Created by mariotaku on 15/10/21.
*/
public class GeoLocationMapper extends JsonMapper<GeoLocation> {
@Override
public GeoLocation parse(JsonParser jsonParser) throws IOException {
final GeoPoint geoPoint = LoganSquare.mapperFor(GeoPoint.class).parse(jsonParser);
if (geoPoint == null) return null;
return geoPoint.getGeoLocation();
}
@Override
public void serialize(GeoLocation object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
throw new UnsupportedOperationException();
}
}

View File

@ -19,7 +19,8 @@
package org.mariotaku.twidere.api.twitter.model;
import java.io.Serializable;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.HashtagEntityImpl;
/**
* A data interface representing one single Hashtag entity.
@ -27,6 +28,7 @@ import java.io.Serializable;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
@Implementation(HashtagEntityImpl.class)
public interface HashtagEntity {
/**
* Returns the index of the end character of the hashtag.

View File

@ -19,13 +19,17 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.IDsImpl;
/**
* A data interface representing array of numeric IDs.
*
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Implementation(IDsImpl.class)
public interface IDs extends TwitterResponse, CursorSupport {
long[] getIDs();
long[] getIDs();
}

View File

@ -19,9 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.LanguageImpl;
/**
* Created by mariotaku on 15/5/10.
*/
@Implementation(LanguageImpl.class)
public interface Language {
String getCode();

View File

@ -19,9 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.LocationImpl;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Implementation(LocationImpl.class)
public interface Location {
String getCountryCode();
@ -35,6 +39,7 @@ public interface Location {
PlaceType getPlaceType();
@Implementation(LocationImpl.PlaceTypeImpl.class)
interface PlaceType {
int getCode();

View File

@ -21,9 +21,14 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.EnumClass;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.MediaEntityImpl;
import java.util.Map;
@Implementation(MediaEntityImpl.class)
public interface MediaEntity extends UrlEntity {
long getId();
@ -42,6 +47,7 @@ public interface MediaEntity extends UrlEntity {
Type getType();
@EnumClass
enum Type {
PHOTO, VIDEO, ANIMATED_GIF, UNKNOWN;
@ -59,6 +65,7 @@ public interface MediaEntity extends UrlEntity {
VideoInfo getVideoInfo();
@Implementation(MediaEntityImpl.VideoInfoImpl.class)
interface VideoInfo {
Variant[] getVariants();
@ -67,6 +74,7 @@ public interface MediaEntity extends UrlEntity {
long getDuration();
@Implementation(MediaEntityImpl.VideoInfoImpl.VariantImpl.class)
interface Variant {
String getContentType();
@ -78,6 +86,7 @@ public interface MediaEntity extends UrlEntity {
}
@Implementation(MediaEntityImpl.SizeImpl.class)
interface Size {
String THUMB = "thumb";
String SMALL = "small";
@ -96,8 +105,10 @@ public interface MediaEntity extends UrlEntity {
/**
* Created by mariotaku on 15/3/31.
*/
@Implementation(MediaEntityImpl.FeatureImpl.class)
interface Feature {
@Implementation(MediaEntityImpl.FeatureImpl.FaceImpl.class)
interface Face {
int getX();

View File

@ -19,6 +19,10 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.MediaUploadResponseImpl;
@Implementation(MediaUploadResponseImpl.class)
public interface MediaUploadResponse extends TwitterResponse {
long getId();
@ -27,6 +31,7 @@ public interface MediaUploadResponse extends TwitterResponse {
long getSize();
@Implementation(MediaUploadResponseImpl.ImageImpl.class)
interface Image {
int getHeight();

View File

@ -19,11 +19,15 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Wrapper;
import org.mariotaku.twidere.api.twitter.model.impl.PageableResponseListWrapper;
/**
* ResponseList with cursor support.
*
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public interface PageableResponseList<T > extends ResponseList<T>, CursorSupport {
@Wrapper(PageableResponseListWrapper.class)
public interface PageableResponseList<T> extends ResponseList<T>, CursorSupport {
}

View File

@ -19,10 +19,14 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.PlaceImpl;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.1
*/
@Implementation(PlaceImpl.class)
public interface Place extends TwitterResponse, Comparable<Place> {
GeoLocation[][] getBoundingBoxCoordinates();

View File

@ -19,6 +19,8 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.EnumClass;
/**
* Created by mariotaku on 15/7/5.
*/
@ -37,6 +39,7 @@ public interface PrivateDirectMessages {
interface UserEvents {
String getCursor();
long getLastSeenEventId();
}
@ -78,11 +81,13 @@ public interface PrivateDirectMessages {
long getUserId();
}
@EnumClass
enum Type {
ONE_TO_ONE, GROUP_DM
}
}
@EnumClass
enum Status {
HAS_MORE, AT_END
}

View File

@ -0,0 +1,31 @@
/*
* 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 org.mariotaku.restfu.http.SimpleValueMap;
/**
* Created by mariotaku on 15/10/21.
*/
public class PrivateSearchQuery extends SimpleValueMap {
public void setQuery(String query) {
put("q", query);
}
}

View File

@ -0,0 +1,26 @@
/*
* 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;
/**
* Created by mariotaku on 15/10/21.
*/
public interface PrivateSearchResult {
}

View File

@ -19,11 +19,15 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Wrapper;
import org.mariotaku.twidere.api.twitter.model.impl.QueryResultWrapper;
/**
* A data interface representing search API response
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Wrapper(QueryResultWrapper.class)
public interface QueryResult extends ResponseList<Status> {
double getCompletedIn();

View File

@ -19,6 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.library.logansquare.extension.annotation.Wrapper;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipImpl;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipWrapper;
@Wrapper(RelationshipWrapper.class)
@Implementation(RelationshipImpl.class)
public interface Relationship extends TwitterResponse {
boolean canSourceDMTarget();

View File

@ -32,6 +32,6 @@ public interface ResponseList<T> extends TwitterResponse, List<T> {
* {@inheritDoc}
*/
@Override
public RateLimitStatus getRateLimitStatus();
RateLimitStatus getRateLimitStatus();
}

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.SavedSearchImpl;
import java.util.Date;
/**
@ -27,6 +30,7 @@ import java.util.Date;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.0.8
*/
@Implementation(SavedSearchImpl.class)
public interface SavedSearch extends Comparable<SavedSearch>, TwitterResponse {
Date getCreatedAt();

View File

@ -19,11 +19,16 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.EnumClass;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.ScheduledStatusImpl;
import java.util.Date;
/**
* Created by mariotaku on 15/7/6.
*/
@Implementation(ScheduledStatusImpl.class)
public interface ScheduledStatus {
long getUserId();
@ -44,6 +49,7 @@ public interface ScheduledStatus {
State getState();
@EnumClass
enum State {
SCHEDULED("scheduled"), FAILED("failed"), CANCELED("canceled");

View File

@ -19,8 +19,12 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Wrapper;
import org.mariotaku.twidere.api.twitter.model.impl.ScheduledStatusesListWrapper;
/**
* Created by mariotaku on 15/7/9.
*/
@Wrapper(ScheduledStatusesListWrapper.class)
public interface ScheduledStatusesList extends ResponseList<ScheduledStatus> {
}

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.StatusImpl;
import java.util.Date;
/**
@ -26,6 +29,7 @@ import java.util.Date;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Implementation(StatusImpl.class)
public interface Status extends Comparable<Status>, TwitterResponse, ExtendedEntitySupport {
/**

View File

@ -19,6 +19,10 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.StatusActivitySummaryImpl;
@Implementation(StatusActivitySummaryImpl.class)
public interface StatusActivitySummary extends TwitterResponse {
long getDescendentReplyCount();

View File

@ -19,9 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.StatusDeletionNoticeImpl;
/**
* Created by mariotaku on 15/5/26.
*/
@Implementation(StatusDeletionNoticeImpl.class)
public interface StatusDeletionNotice {
long getStatusId();
}

View File

@ -19,9 +19,13 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.TimeZoneImpl;
/**
* @author Alessandro Bahgat - ale.bahgat at gmail.com
*/
@Implementation(TimeZoneImpl.class)
public interface TimeZone {
String getName();

View File

@ -19,8 +19,10 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.TranslationResultImpl;
@Implementation(TranslationResultImpl.class)
public interface TranslationResult extends TwitterResponse {
public long getId();

View File

@ -19,12 +19,16 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.TrendImpl;
/**
* A data interface representing Trend.
*
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.0.2
*/
@Implementation(TrendImpl.class)
public interface Trend {
String getName();

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.TrendsImpl;
import java.io.Serializable;
import java.util.Date;
@ -28,7 +31,7 @@ import java.util.Date;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.0.2
*/
@Implementation(TrendsImpl.class)
public interface Trends extends TwitterResponse, Comparable<Trends>, Serializable {
Date getAsOf();

View File

@ -19,8 +19,8 @@
package org.mariotaku.twidere.api.twitter.model;
import java.io.Serializable;
import java.net.URL;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.UrlEntityImpl;
/**
* A data interface representing one single URL entity.
@ -28,6 +28,7 @@ import java.net.URL;
* @author Mocel - mocel at guma.jp
* @since Twitter4J 2.1.9
*/
@Implementation(UrlEntityImpl.class)
public interface UrlEntity {
/**

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.UserImpl;
import java.util.Date;
/**
@ -26,6 +29,7 @@ import java.util.Date;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
@Implementation(UserImpl.class)
public interface User extends Comparable<User>, TwitterResponse {
Date getCreatedAt();

View File

@ -19,8 +19,12 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.UserListImpl;
import java.util.Date;
@Implementation(UserListImpl.class)
public interface UserList extends Comparable<UserList>, TwitterResponse {
Mode getMode();

View File

@ -19,12 +19,16 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.UserMentionEntityImpl;
/**
* A data interface representing one single user mention entity.
*
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
@Implementation(UserMentionEntityImpl.class)
public interface UserMentionEntity {
/**
* Returns the index of the end character of the user mention.

View File

@ -19,8 +19,12 @@
package org.mariotaku.twidere.api.twitter.model;
import org.mariotaku.library.logansquare.extension.annotation.Implementation;
import org.mariotaku.twidere.api.twitter.model.impl.WarningImpl;
/**
* Created by mariotaku on 15/5/26.
*/
@Implementation(WarningImpl.class)
public interface Warning {
}

View File

@ -21,144 +21,32 @@ package org.mariotaku.twidere.api.twitter.model.impl;
import android.support.annotation.NonNull;
import com.bluelinelabs.logansquare.JsonMapper;
import com.bluelinelabs.logansquare.LoganSquare;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.mariotaku.library.logansquare.extension.annotation.Mapper;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.User;
import org.mariotaku.twidere.api.twitter.model.UserList;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
@Mapper(ActivityImplMapper.class)
public class ActivityImpl extends TwitterResponseImpl implements Activity {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
private Action action;
static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
Action action;
private Date createdAt;
Date createdAt;
private User[] sources;
private User[] targetUsers;
private User[] targetObjectUsers;
private Status[] targetObjectStatuses, targetStatuses;
private UserList[] targetUserLists, targetObjectUserLists;
private long maxPosition, minPosition;
private int targetObjectsSize, targetsSize, sourcesSize;
public static final JsonMapper<Activity> MAPPER = new JsonMapper<Activity>() {
@SuppressWarnings("TryWithIdenticalCatches")
@Override
public Activity parse(JsonParser jsonParser) throws IOException {
ActivityImpl instance = new ActivityImpl();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
@Override
public void serialize(Activity activity, JsonGenerator jsonGenerator, boolean writeStartAndEnd) {
throw new UnsupportedOperationException();
}
public void parseField(ActivityImpl instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("action".equals(fieldName)) {
instance.action = Action.parse(jsonParser.getValueAsString());
} else if ("created_at".equals(fieldName)) {
try {
instance.createdAt = DATE_FORMAT.parse(jsonParser.getValueAsString());
} catch (ParseException e) {
throw new IOException(e);
}
} else if ("min_position".equals(fieldName)) {
instance.minPosition = jsonParser.getValueAsLong();
} else if ("max_position".equals(fieldName)) {
instance.maxPosition = jsonParser.getValueAsLong();
} else if ("sources_size".equals(fieldName)) {
instance.sourcesSize = jsonParser.getValueAsInt();
} else if ("targets_size".equals(fieldName)) {
instance.targetsSize = jsonParser.getValueAsInt();
} else if ("target_objects_size".equals(fieldName)) {
instance.targetObjectsSize = jsonParser.getValueAsInt();
} else if ("sources".equals(fieldName)) {
instance.sources = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.sourcesSize]);
} else if ("targets".equals(fieldName)) {
if (instance.action == null) throw new IOException();
switch (instance.action) {
case FAVORITE:
case REPLY:
case RETWEET:
case QUOTE:
case FAVORITED_RETWEET:
case RETWEETED_RETWEET:
case RETWEETED_MENTION:
case FAVORITED_MENTION:
case MEDIA_TAGGED:
case FAVORITED_MEDIA_TAGGED:
case RETWEETED_MEDIA_TAGGED: {
instance.targetStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetsSize]);
break;
}
case FOLLOW:
case MENTION:
case LIST_MEMBER_ADDED: {
instance.targetUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetsSize]);
break;
}
case LIST_CREATED: {
instance.targetUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetsSize]);
break;
}
}
} else if ("target_objects".equals(fieldName)) {
if (instance.action == null) throw new IOException();
switch (instance.action) {
case FAVORITE:
case FOLLOW:
case MENTION:
case REPLY:
case RETWEET:
case LIST_CREATED:
case QUOTE: {
instance.targetObjectStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetObjectsSize]);
break;
}
case LIST_MEMBER_ADDED: {
instance.targetObjectUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetObjectsSize]);
break;
}
case FAVORITED_RETWEET:
case RETWEETED_RETWEET:
case RETWEETED_MENTION:
case FAVORITED_MENTION:
case MEDIA_TAGGED:
case FAVORITED_MEDIA_TAGGED:
case RETWEETED_MEDIA_TAGGED: {
instance.targetObjectUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetObjectsSize]);
break;
}
}
}
}
};
User[] sources;
User[] targetUsers;
User[] targetObjectUsers;
Status[] targetObjectStatuses, targetStatuses;
UserList[] targetUserLists, targetObjectUserLists;
long maxPosition, minPosition;
int targetObjectsSize, targetsSize, sourcesSize;
ActivityImpl() {
}

View File

@ -0,0 +1,144 @@
/*
* 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.impl;
import com.bluelinelabs.logansquare.JsonMapper;
import com.bluelinelabs.logansquare.LoganSquare;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.User;
import org.mariotaku.twidere.api.twitter.model.UserList;
import java.io.IOException;
import java.text.ParseException;
/**
* Created by mariotaku on 15/10/21.
*/
public class ActivityImplMapper extends JsonMapper<ActivityImpl> {
@SuppressWarnings("TryWithIdenticalCatches")
@Override
public ActivityImpl parse(JsonParser jsonParser) throws IOException {
ActivityImpl instance = new ActivityImpl();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
@Override
public void serialize(ActivityImpl activity, JsonGenerator jsonGenerator, boolean writeStartAndEnd) {
throw new UnsupportedOperationException();
}
public void parseField(ActivityImpl instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("action".equals(fieldName)) {
instance.action = Activity.Action.parse(jsonParser.getValueAsString());
} else if ("created_at".equals(fieldName)) {
try {
instance.createdAt = ActivityImpl.DATE_FORMAT.parse(jsonParser.getValueAsString());
} catch (ParseException e) {
throw new IOException(e);
}
} else if ("min_position".equals(fieldName)) {
instance.minPosition = jsonParser.getValueAsLong();
} else if ("max_position".equals(fieldName)) {
instance.maxPosition = jsonParser.getValueAsLong();
} else if ("sources_size".equals(fieldName)) {
instance.sourcesSize = jsonParser.getValueAsInt();
} else if ("targets_size".equals(fieldName)) {
instance.targetsSize = jsonParser.getValueAsInt();
} else if ("target_objects_size".equals(fieldName)) {
instance.targetObjectsSize = jsonParser.getValueAsInt();
} else if ("sources".equals(fieldName)) {
instance.sources = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.sourcesSize]);
} else if ("targets".equals(fieldName)) {
if (instance.action == null) throw new IOException();
switch (instance.action) {
case FAVORITE:
case REPLY:
case RETWEET:
case QUOTE:
case FAVORITED_RETWEET:
case RETWEETED_RETWEET:
case RETWEETED_MENTION:
case FAVORITED_MENTION:
case MEDIA_TAGGED:
case FAVORITED_MEDIA_TAGGED:
case RETWEETED_MEDIA_TAGGED: {
instance.targetStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetsSize]);
break;
}
case FOLLOW:
case MENTION:
case LIST_MEMBER_ADDED: {
instance.targetUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetsSize]);
break;
}
case LIST_CREATED: {
instance.targetUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetsSize]);
break;
}
}
} else if ("target_objects".equals(fieldName)) {
if (instance.action == null) throw new IOException();
switch (instance.action) {
case FAVORITE:
case FOLLOW:
case MENTION:
case REPLY:
case RETWEET:
case LIST_CREATED:
case QUOTE: {
instance.targetObjectStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetObjectsSize]);
break;
}
case LIST_MEMBER_ADDED: {
instance.targetObjectUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetObjectsSize]);
break;
}
case FAVORITED_RETWEET:
case RETWEETED_RETWEET:
case RETWEETED_MENTION:
case FAVORITED_MENTION:
case MEDIA_TAGGED:
case FAVORITED_MEDIA_TAGGED:
case RETWEETED_MEDIA_TAGGED: {
instance.targetObjectUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetObjectsSize]);
break;
}
}
}
}
}

View File

@ -19,19 +19,14 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.twidere.api.twitter.model.CardEntity;
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
import org.mariotaku.twidere.api.twitter.model.User;
import java.io.IOException;
import java.util.Map;
/**
@ -141,21 +136,7 @@ public class CardEntityImpl implements CardEntity {
}
@JsonObject
public static class BindingValueWrapper implements Wrapper<BindingValue> {
public static final TypeConverter<BindingValue> CONVERTER = new TypeConverter<BindingValue>() {
@Override
public BindingValue parse(JsonParser jsonParser) throws IOException {
final BindingValueWrapper wrapper = LoganSquare.mapperFor(BindingValueWrapper.class).parse(jsonParser);
if (wrapper == null) return null;
return wrapper.getWrapped(null);
}
@Override
public void serialize(BindingValue object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
throw new UnsupportedOperationException();
}
};
public static class BindingValueWrapper implements TwitterModelWrapper<BindingValue> {
@JsonField(name = "type")
String type;

View File

@ -22,29 +22,29 @@ package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.util.Arrays;
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.UserMentionEntity;
import java.util.Arrays;
/**
* Created by mariotaku on 15/3/31.
*/
@JsonObject
public class EntitiesImpl {
@JsonField(name = "hashtags")
HashtagEntity[] hashtags;
HashtagEntityImpl[] hashtags;
@JsonField(name = "user_mentions")
UserMentionEntity[] userMentions;
UserMentionEntityImpl[] userMentions;
@JsonField(name = "urls")
UrlEntity[] urls;
UrlEntityImpl[] urls;
@JsonField(name = "media")
MediaEntity[] media;
MediaEntityImpl[] media;
public HashtagEntity[] getHashtags() {
return hashtags;

View File

@ -19,89 +19,22 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.JsonMapper;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.mariotaku.library.logansquare.extension.LoganSquareWrapper;
import org.mariotaku.twidere.api.twitter.model.IDs;
import org.mariotaku.library.logansquare.extension.annotation.Mapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mariotaku on 15/5/10.
*/
@Mapper(IDsImplMapper.class)
public class IDsImpl extends TwitterResponseImpl implements IDs {
public static final TypeConverter<IDs> CONVERTER = new TypeConverter<IDs>() {
@Override
public IDs parse(JsonParser jsonParser) throws IOException {
return MAPPER.parse(jsonParser);
}
@Override
public void serialize(IDs object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) {
throw new UnsupportedOperationException();
}
};
public static final JsonMapper<IDs> MAPPER = new JsonMapper<IDs>() {
@SuppressWarnings("TryWithIdenticalCatches")
@Override
public IDs parse(JsonParser jsonParser) throws IOException {
IDsImpl instance = new IDsImpl();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
parseIDsArray(instance, jsonParser);
} else if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
} else {
jsonParser.skipChildren();
return null;
}
return instance;
}
@Override
public void serialize(IDs activity, JsonGenerator jsonGenerator, boolean writeStartAndEnd) {
throw new UnsupportedOperationException();
}
public void parseField(IDsImpl instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("ids".equals(fieldName)) {
parseIDsArray(instance, jsonParser);
} else if ("previous_cursor".equals(fieldName)) {
instance.previousCursor = jsonParser.getValueAsLong();
} else if ("next_cursor".equals(fieldName)) {
instance.nextCursor = jsonParser.getValueAsLong();
}
}
private void parseIDsArray(IDsImpl instance, JsonParser jsonParser) throws IOException {
List<Long> collection1 = new ArrayList<>();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
collection1.add(jsonParser.getValueAsLong());
}
long[] array = new long[collection1.size()];
int i = 0;
for (long value : collection1) {
array[i++] = value;
}
instance.ids = array;
}
};
long previousCursor;
long nextCursor;
long[] ids;
@ -130,4 +63,5 @@ public class IDsImpl extends TwitterResponseImpl implements IDs {
public long[] getIDs() {
return ids;
}
}

View File

@ -0,0 +1,88 @@
/*
* 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.impl;
import com.bluelinelabs.logansquare.JsonMapper;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.mariotaku.twidere.api.twitter.model.IDs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mariotaku on 15/10/21.
*/
public class IDsImplMapper extends JsonMapper<IDsImpl> {
@SuppressWarnings("TryWithIdenticalCatches")
@Override
public IDsImpl parse(JsonParser jsonParser) throws IOException {
IDsImpl instance = new IDsImpl();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
parseIDsArray(instance, jsonParser);
} else if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
} else {
jsonParser.skipChildren();
return null;
}
return instance;
}
@Override
public void serialize(IDsImpl activity, JsonGenerator jsonGenerator, boolean writeStartAndEnd) {
throw new UnsupportedOperationException();
}
public void parseField(IDsImpl instance, String fieldName, JsonParser jsonParser) throws IOException {
if ("ids".equals(fieldName)) {
parseIDsArray(instance, jsonParser);
} else if ("previous_cursor".equals(fieldName)) {
instance.previousCursor = jsonParser.getValueAsLong();
} else if ("next_cursor".equals(fieldName)) {
instance.nextCursor = jsonParser.getValueAsLong();
}
}
private void parseIDsArray(IDsImpl instance, JsonParser jsonParser) throws IOException {
List<Long> collection1 = new ArrayList<>();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
collection1.add(jsonParser.getValueAsLong());
}
long[] array = new long[collection1.size()];
int i = 0;
for (long value : collection1) {
array[i++] = value;
}
instance.ids = array;
}
}

View File

@ -19,16 +19,12 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;
import org.mariotaku.library.logansquare.extension.annotation.Mapper;
/**
* Created by mariotaku on 15/3/31.
*/
@Mapper(IndicesMapper.class)
public class Indices {
private int start, end;
@ -41,14 +37,11 @@ public class Indices {
return start;
}
public Indices(JsonParser reader) throws IOException {
if (!reader.isExpectedStartArrayToken()) throw new IOException("Malformed indices");
start = reader.nextIntValue(-1);
end = reader.nextIntValue(-1);
if (reader.nextToken() != JsonToken.END_ARRAY) throw new IOException("Malformed indices");
public Indices(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public String toString() {
return "Index{" +
@ -57,15 +50,4 @@ public class Indices {
'}';
}
public static final TypeConverter<Indices> CONVERTER = new TypeConverter<Indices>() {
@Override
public Indices parse(JsonParser jsonParser) throws IOException {
return new Indices(jsonParser);
}
@Override
public void serialize(Indices object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
throw new UnsupportedOperationException();
}
};
}

View File

@ -0,0 +1,48 @@
/*
* 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.impl;
import com.bluelinelabs.logansquare.JsonMapper;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;
/**
* Created by mariotaku on 15/10/21.
*/
public class IndicesMapper extends JsonMapper<Indices> {
@Override
public Indices parse(JsonParser jsonParser) throws IOException {
final int start, end;
if (!jsonParser.isExpectedStartArrayToken()) throw new IOException("Malformed indices");
start = jsonParser.nextIntValue(-1);
end = jsonParser.nextIntValue(-1);
if (jsonParser.nextToken() != JsonToken.END_ARRAY)
throw new IOException("Malformed indices");
return new Indices(start, end);
}
@Override
public void serialize(Indices object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
throw new UnsupportedOperationException();
}
}

View File

@ -35,7 +35,7 @@ import java.util.ArrayList;
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class PageableResponseListWrapper extends TwitterResponseImpl implements Wrapper<PageableResponseList<?>> {
public class PageableResponseListWrapper extends TwitterResponseImpl implements TwitterModelWrapper<PageableResponseList<?>> {
@JsonField(name = "previous_cursor")
long previousCursor;

View File

@ -0,0 +1,28 @@
/*
* 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.impl;
import org.mariotaku.twidere.api.twitter.model.PrivateSearchResult;
/**
* Created by mariotaku on 15/10/21.
*/
public class PrivateSearchResultImpl implements PrivateSearchResult {
}

View File

@ -31,7 +31,7 @@ import org.mariotaku.twidere.api.twitter.model.Status;
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class QueryResultWrapper extends TwitterResponseImpl implements Wrapper<QueryResult> {
public class QueryResultWrapper extends TwitterResponseImpl implements TwitterModelWrapper<QueryResult> {
@JsonField(name = "previous_cursor")
long previousCursor;

View File

@ -28,7 +28,7 @@ import org.mariotaku.twidere.api.twitter.model.Relationship;
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class RelationshipWrapper extends TwitterResponseImpl implements Wrapper<Relationship> {
public class RelationshipWrapper extends TwitterResponseImpl implements TwitterModelWrapper<Relationship> {
@JsonField(name = "relationship")
RelationshipImpl relationship;

View File

@ -34,7 +34,7 @@ import java.util.ArrayList;
* Created by mariotaku on 15/7/9.
*/
@JsonObject
public class ScheduledStatusesListWrapper implements Wrapper<ScheduledStatusesList> {
public class ScheduledStatusesListWrapper implements TwitterModelWrapper<ScheduledStatusesList> {
@JsonField(name = "results")
ArrayList<ScheduledStatus> list;

View File

@ -19,12 +19,13 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import org.mariotaku.library.logansquare.extension.ModelWrapper;
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
/**
* Created by mariotaku on 15/5/7.
*/
public interface Wrapper<T> extends TwitterResponse {
public interface TwitterModelWrapper<T> extends ModelWrapper<T>, TwitterResponse {
T getWrapped(Object extra);

View File

@ -19,12 +19,12 @@
package org.mariotaku.twidere.api.twitter.util;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.library.logansquare.extension.LoganSquareWrapper;
import org.mariotaku.restfu.Converter;
import org.mariotaku.restfu.Utils;
import org.mariotaku.restfu.http.ContentType;
@ -32,77 +32,12 @@ import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.restfu.http.mime.TypedData;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.api.twitter.model.AccountSettings;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.api.twitter.model.CardEntity;
import org.mariotaku.twidere.api.twitter.model.DirectMessage;
import org.mariotaku.twidere.api.twitter.model.ErrorInfo;
import org.mariotaku.twidere.api.twitter.model.ExtendedProfile;
import org.mariotaku.twidere.api.twitter.model.GeoLocation;
import org.mariotaku.twidere.api.twitter.model.HashtagEntity;
import org.mariotaku.twidere.api.twitter.model.IDs;
import org.mariotaku.twidere.api.twitter.model.Language;
import org.mariotaku.twidere.api.twitter.model.Location;
import org.mariotaku.twidere.api.twitter.model.MediaEntity;
import org.mariotaku.twidere.api.twitter.model.MediaUploadResponse;
import org.mariotaku.twidere.api.twitter.model.PageableResponseList;
import org.mariotaku.twidere.api.twitter.model.Place;
import org.mariotaku.twidere.api.twitter.model.QueryResult;
import org.mariotaku.twidere.api.twitter.model.Relationship;
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
import org.mariotaku.twidere.api.twitter.model.ResponseList;
import org.mariotaku.twidere.api.twitter.model.SavedSearch;
import org.mariotaku.twidere.api.twitter.model.ScheduledStatus;
import org.mariotaku.twidere.api.twitter.model.ScheduledStatusesList;
import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.StatusActivitySummary;
import org.mariotaku.twidere.api.twitter.model.StatusDeletionNotice;
import org.mariotaku.twidere.api.twitter.model.TimeZone;
import org.mariotaku.twidere.api.twitter.model.TranslationResult;
import org.mariotaku.twidere.api.twitter.model.Trend;
import org.mariotaku.twidere.api.twitter.model.Trends;
import org.mariotaku.twidere.api.twitter.model.UrlEntity;
import org.mariotaku.twidere.api.twitter.model.User;
import org.mariotaku.twidere.api.twitter.model.UserList;
import org.mariotaku.twidere.api.twitter.model.UserMentionEntity;
import org.mariotaku.twidere.api.twitter.model.Warning;
import org.mariotaku.twidere.api.twitter.model.impl.AccountSettingsImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ActivityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.CardEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.DirectMessageImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ErrorInfoImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ExtendedProfileImpl;
import org.mariotaku.twidere.api.twitter.model.impl.HashtagEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.IDsImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Indices;
import org.mariotaku.twidere.api.twitter.model.impl.LanguageImpl;
import org.mariotaku.twidere.api.twitter.model.impl.LocationImpl;
import org.mariotaku.twidere.api.twitter.model.impl.MediaEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.MediaUploadResponseImpl;
import org.mariotaku.twidere.api.twitter.model.impl.PageableResponseListWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.PlaceImpl;
import org.mariotaku.twidere.api.twitter.model.impl.QueryResultWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipImpl;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.ResponseListImpl;
import org.mariotaku.twidere.api.twitter.model.impl.SavedSearchImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ScheduledStatusImpl;
import org.mariotaku.twidere.api.twitter.model.impl.ScheduledStatusesListWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.StatusActivitySummaryImpl;
import org.mariotaku.twidere.api.twitter.model.impl.StatusDeletionNoticeImpl;
import org.mariotaku.twidere.api.twitter.model.impl.StatusImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TimeZoneImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TranslationResultImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TrendImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TrendsImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TwitterModelWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.TwitterResponseImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TypeConverterMapper;
import org.mariotaku.twidere.api.twitter.model.impl.UrlEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserListImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserMentionEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.WarningImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Wrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -113,75 +48,18 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mariotaku on 15/5/5.
*/
public class TwitterConverter implements Converter {
private static final Map<Class<?>, Class<? extends Wrapper<?>>> wrapperMap = new HashMap<>();
static {
TypeConverterMapper.register(Status.class, StatusImpl.class);
TypeConverterMapper.register(User.class, UserImpl.class);
TypeConverterMapper.register(UserList.class, UserListImpl.class);
TypeConverterMapper.register(DirectMessage.class, DirectMessageImpl.class);
TypeConverterMapper.register(SavedSearch.class, SavedSearchImpl.class);
TypeConverterMapper.register(UrlEntity.class, UrlEntityImpl.class);
TypeConverterMapper.register(MediaEntity.class, MediaEntityImpl.class);
TypeConverterMapper.register(MediaEntity.Size.class, MediaEntityImpl.SizeImpl.class);
TypeConverterMapper.register(MediaEntity.Feature.class, MediaEntityImpl.FeatureImpl.class);
TypeConverterMapper.register(MediaEntity.Feature.Face.class, MediaEntityImpl.FeatureImpl.FaceImpl.class);
TypeConverterMapper.register(MediaEntity.VideoInfo.class, MediaEntityImpl.VideoInfoImpl.class);
TypeConverterMapper.register(MediaEntity.VideoInfo.Variant.class, MediaEntityImpl.VideoInfoImpl.VariantImpl.class);
TypeConverterMapper.register(UserMentionEntity.class, UserMentionEntityImpl.class);
TypeConverterMapper.register(HashtagEntity.class, HashtagEntityImpl.class);
TypeConverterMapper.register(CardEntity.class, CardEntityImpl.class);
TypeConverterMapper.register(Place.class, PlaceImpl.class);
TypeConverterMapper.register(Relationship.class, RelationshipImpl.class);
TypeConverterMapper.register(MediaUploadResponse.class, MediaUploadResponseImpl.class);
TypeConverterMapper.register(MediaUploadResponse.Image.class, MediaUploadResponseImpl.ImageImpl.class);
TypeConverterMapper.register(ErrorInfo.class, ErrorInfoImpl.class);
TypeConverterMapper.register(TranslationResult.class, TranslationResultImpl.class);
TypeConverterMapper.register(Language.class, LanguageImpl.class);
TypeConverterMapper.register(Trend.class, TrendImpl.class);
TypeConverterMapper.register(Trends.class, TrendsImpl.class);
TypeConverterMapper.register(Location.class, LocationImpl.class);
TypeConverterMapper.register(Location.PlaceType.class, LocationImpl.PlaceTypeImpl.class);
TypeConverterMapper.register(StatusActivitySummary.class, StatusActivitySummaryImpl.class);
TypeConverterMapper.register(TimeZone.class, TimeZoneImpl.class);
TypeConverterMapper.register(AccountSettings.class, AccountSettingsImpl.class);
TypeConverterMapper.register(IDs.class, IDsImpl.class, IDsImpl.MAPPER);
TypeConverterMapper.register(Activity.class, ActivityImpl.class, ActivityImpl.MAPPER);
TypeConverterMapper.register(Warning.class, WarningImpl.class);
TypeConverterMapper.register(StatusDeletionNotice.class, StatusDeletionNoticeImpl.class);
TypeConverterMapper.register(ScheduledStatus.class, ScheduledStatusImpl.class);
TypeConverterMapper.register(ExtendedProfile.class, ExtendedProfileImpl.class);
LoganSquare.registerTypeConverter(Indices.class, Indices.CONVERTER);
LoganSquare.registerTypeConverter(GeoLocation.class, GeoLocation.CONVERTER);
LoganSquare.registerTypeConverter(CardEntity.BindingValue.class, CardEntityImpl.BindingValueWrapper.CONVERTER);
LoganSquare.registerTypeConverter(IDs.class, IDsImpl.CONVERTER);
LoganSquare.registerTypeConverter(MediaEntity.Type.class, EnumConverter.get(MediaEntity.Type.class));
LoganSquare.registerTypeConverter(UserList.Mode.class, EnumConverter.get(UserList.Mode.class));
LoganSquare.registerTypeConverter(Activity.Action.class, EnumConverter.get(Activity.Action.class));
LoganSquare.registerTypeConverter(ScheduledStatus.State.class, EnumConverter.get(ScheduledStatus.State.class));
registerWrapper(QueryResult.class, QueryResultWrapper.class);
registerWrapper(PageableResponseList.class, PageableResponseListWrapper.class);
registerWrapper(Relationship.class, RelationshipWrapper.class);
registerWrapper(CardEntity.BindingValue.class, CardEntityImpl.BindingValueWrapper.class);
registerWrapper(ScheduledStatusesList.class, ScheduledStatusesListWrapper.class);
}
public static TwitterException parseTwitterException(RestHttpResponse resp) {
try {
final TypedData body = resp.getBody();
if (body == null) return new TwitterException(resp);
final TwitterException parse = LoganSquare.parse(body.stream(), TwitterException.class);
final TwitterException parse = LoganSquareWrapper.parse(body.stream(), TwitterException.class);
if (parse != null) return parse;
return new TwitterException(resp);
} catch (JsonParseException e) {
@ -193,7 +71,7 @@ public class TwitterConverter implements Converter {
private static <T> T parseOrThrow(RestHttpResponse resp, InputStream stream, Class<T> cls) throws IOException, TwitterException {
try {
final T parse = LoganSquare.parse(stream, cls);
final T parse = LoganSquareWrapper.parse(stream, cls);
if (TwitterException.class.isAssignableFrom(cls) && parse == null) {
throw new TwitterException();
}
@ -205,16 +83,12 @@ public class TwitterConverter implements Converter {
private static <T> List<T> parseListOrThrow(RestHttpResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
try {
return LoganSquare.parseList(stream, elementCls);
return LoganSquareWrapper.parseList(stream, elementCls);
} catch (JsonParseException e) {
throw new TwitterException("Malformed JSON Data", resp);
}
}
private static <T> void registerWrapper(Class<T> cls, Class<? extends Wrapper<? extends T>> wrapperCls) {
wrapperMap.put(cls, wrapperCls);
}
@Override
public Object convert(RestHttpResponse response, Type type) throws Exception {
final TypedData body = response.getBody();
@ -226,9 +100,9 @@ public class TwitterConverter implements Converter {
try {
if (type instanceof Class<?>) {
final Class<?> cls = (Class<?>) type;
final Class<?> wrapperCls = wrapperMap.get(cls);
final Class<?> wrapperCls = LoganSquareWrapper.getWrapperClass(cls);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
final TwitterModelWrapper<?> wrapper = (TwitterModelWrapper<?>) parseOrThrow(response, stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(null);
} else if (OAuthToken.class.isAssignableFrom(cls)) {
@ -256,9 +130,9 @@ public class TwitterConverter implements Converter {
final Type rawType = ((ParameterizedType) type).getRawType();
if (rawType instanceof Class<?>) {
final Class<?> rawClass = (Class<?>) rawType;
final Class<?> wrapperCls = wrapperMap.get(rawClass);
final Class<?> wrapperCls = LoganSquareWrapper.getWrapperClass(rawClass);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
final TwitterModelWrapper<?> wrapper = (TwitterModelWrapper<?>) parseOrThrow(response, stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(((ParameterizedType) type).getActualTypeArguments());
} else if (ResponseList.class.isAssignableFrom(rawClass)) {

View File

@ -54,6 +54,9 @@ public class NotificationEvent extends BaseEvent implements Parcelable {
@JsonField(name = "item_id")
long itemId;
@ParcelableThisPlease
@JsonField(name = "item_user_id")
long itemUserId;
@ParcelableThisPlease
@JsonField(name = "account_id")
long accountId;
@ParcelableThisPlease
@ -71,6 +74,28 @@ public class NotificationEvent extends BaseEvent implements Parcelable {
NotificationEventParcelablePlease.readFromParcel(this, in);
}
public static NotificationEvent create(Context context, Action action, long postTime, long respondTime, String type, long accountId, long itemId, long itemUserId) {
final NotificationEvent event = new NotificationEvent();
event.setAction(action);
event.setStartTime(postTime);
event.setEndTime(respondTime);
event.setTimeOffset(TimeZone.getDefault().getOffset(postTime));
event.setLocation(HotMobiLogger.getCachedLatLng(context));
event.setType(type);
event.setAccountId(accountId);
event.setItemId(itemId);
event.setItemUserId(itemUserId);
return event;
}
public static NotificationEvent deleted(Context context, long postTime, String type, long accountId, long itemId, long itemUserId) {
return create(context, Action.DELETE, System.currentTimeMillis(), postTime, type, accountId, itemId, itemUserId);
}
public static NotificationEvent open(Context context, long postTime, String type, long accountId, long itemId, long itemUserId) {
return create(context, Action.OPEN, System.currentTimeMillis(), postTime, type, accountId, itemId, itemUserId);
}
public Action getAction() {
return action;
}
@ -114,25 +139,12 @@ public class NotificationEvent extends BaseEvent implements Parcelable {
NotificationEventParcelablePlease.writeToParcel(this, dest, flags);
}
public static NotificationEvent create(Context context, Action action, long postTime, long respondTime, String type, long accountId, long itemId) {
final NotificationEvent event = new NotificationEvent();
event.setAction(action);
event.setStartTime(postTime);
event.setEndTime(respondTime);
event.setTimeOffset(TimeZone.getDefault().getOffset(postTime));
event.setLocation(HotMobiLogger.getCachedLatLng(context));
event.setType(type);
event.setAccountId(accountId);
event.setItemId(itemId);
return event;
public long getItemUserId() {
return itemUserId;
}
public static NotificationEvent deleted(Context context, long postTime, String type, long accountId, long itemId) {
return create(context, Action.DELETE, System.currentTimeMillis(), postTime, type, accountId, itemId);
}
public static NotificationEvent open(Context context, long postTime, String type, long accountId, long itemId) {
return create(context, Action.OPEN, System.currentTimeMillis(), postTime, type, accountId, itemId);
public void setItemUserId(long itemUserId) {
this.itemUserId = itemUserId;
}
public enum Action {

View File

@ -25,9 +25,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@ -81,6 +81,8 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
}
}
};
private Runnable mResumeFragmentRunnable;
private boolean mFragmentsResumed;
@Override
public void onClick(final View v) {
@ -230,18 +232,61 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
mCreateUserListContainer.setVisibility(isMyAccount ? View.VISIBLE : View.GONE);
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
if (!mFragmentsResumed && mResumeFragmentRunnable != null) {
mResumeFragmentRunnable.run();
}
mFragmentsResumed = true;
}
@Override
protected void onPause() {
mFragmentsResumed = false;
super.onPause();
}
private void dismissDialogFragment(final String tag) {
mResumeFragmentRunnable = new Runnable() {
@Override
public void run() {
final FragmentManager fm = getSupportFragmentManager();
final Fragment f = fm.findFragmentByTag(tag);
if (f instanceof DialogFragment) {
((DialogFragment) f).dismiss();
}
mResumeFragmentRunnable = null;
}
};
if (mFragmentsResumed) {
mResumeFragmentRunnable.run();
}
}
private void showDialogFragment(final DialogFragment df, final String tag) {
mResumeFragmentRunnable = new Runnable() {
@Override
public void run() {
df.show(getSupportFragmentManager(), tag);
mResumeFragmentRunnable = null;
}
};
if (mFragmentsResumed) {
mResumeFragmentRunnable.run();
}
}
private static class GetUserListsTask extends AsyncTask<Object, Object, SingleResponse<List<ParcelableUserList>>> {
private static final String FRAGMENT_TAG_GET_USER_LISTS = "get_user_lists";
private final UserListSelectorActivity mActivity;
private final Handler mHandler;
private final long mAccountId;
private final String mScreenName;
GetUserListsTask(final UserListSelectorActivity activity, final long accountId, final String screenName) {
mActivity = activity;
mHandler = new Handler(activity.getMainLooper());
mAccountId = accountId;
mScreenName = screenName;
}
@ -274,10 +319,7 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
@Override
protected void onPostExecute(final SingleResponse<List<ParcelableUserList>> result) {
final Fragment f = mActivity.getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_GET_USER_LISTS);
if (f instanceof DialogFragment) {
((DialogFragment) f).dismiss();
}
mActivity.dismissDialogFragment(FRAGMENT_TAG_GET_USER_LISTS);
if (result.getData() != null) {
mActivity.setUserListsData(result.getData(), result.getExtras().getBoolean(EXTRA_IS_MY_ACCOUNT));
} else if (result.getException() instanceof TwitterException) {
@ -290,13 +332,9 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
@Override
protected void onPreExecute() {
mHandler.post(new Runnable() {
@Override
public void run() {
final SupportProgressDialogFragment df = SupportProgressDialogFragment.show(mActivity, FRAGMENT_TAG_GET_USER_LISTS);
df.setCancelable(false);
}
});
final SupportProgressDialogFragment df = new SupportProgressDialogFragment();
df.setCancelable(false);
mActivity.showDialogFragment(df, FRAGMENT_TAG_GET_USER_LISTS);
}
}
@ -305,14 +343,12 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
private static final String FRAGMENT_TAG_SEARCH_USERS = "search_users";
private final UserListSelectorActivity mActivity;
private final Handler mHandler;
private final long mAccountId;
private final String mName;
SearchUsersTask(final UserListSelectorActivity activity, final long accountId, final String name) {
mActivity = activity;
mHandler = new Handler(activity.getMainLooper());
mAccountId = accountId;
mName = name;
}
@ -337,10 +373,7 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
@Override
protected void onPostExecute(final SingleResponse<List<ParcelableUser>> result) {
final Fragment f = mActivity.getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_SEARCH_USERS);
if (f instanceof DialogFragment) {
((DialogFragment) f).dismiss();
}
mActivity.dismissDialogFragment(FRAGMENT_TAG_SEARCH_USERS);
if (result.getData() != null) {
mActivity.setUsersData(result.getData());
}
@ -348,15 +381,12 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen
@Override
protected void onPreExecute() {
mHandler.post(new Runnable() {
@Override
public void run() {
final SupportProgressDialogFragment df = SupportProgressDialogFragment.show(mActivity, FRAGMENT_TAG_SEARCH_USERS);
df.setCancelable(false);
}
});
final SupportProgressDialogFragment df = new SupportProgressDialogFragment();
df.setCancelable(false);
mActivity.showDialogFragment(df, FRAGMENT_TAG_SEARCH_USERS);
}
}
}

View File

@ -57,7 +57,7 @@ public class TweetSearchLoader extends TwitterAPIStatusesLoader {
}
protected String processQuery(final String query) {
return String.format("%s", query);
return String.format("%s -RT", query);
}
@Override

View File

@ -33,7 +33,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.model.ParcelableActivity;
import org.mariotaku.twidere.util.LoganSquareWrapper;
import org.mariotaku.twidere.util.JsonSerializer;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import java.io.File;
@ -151,7 +151,7 @@ public abstract class TwitterAPIActivitiesLoader extends ParcelableActivitiesLoa
private List<ParcelableActivity> getCachedData(final File file) {
if (file == null) return null;
try {
return LoganSquareWrapper.parseList(file, ParcelableActivity.class);
return JsonSerializer.parseList(file, ParcelableActivity.class);
} catch (final IOException e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
@ -168,7 +168,7 @@ public abstract class TwitterAPIActivitiesLoader extends ParcelableActivitiesLoa
private File getSerializationFile() {
if (mSavedStatusesFileArgs == null) return null;
try {
return LoganSquareWrapper.getSerializationFile(mContext, mSavedStatusesFileArgs);
return JsonSerializer.getSerializationFile(mContext, mSavedStatusesFileArgs);
} catch (final IOException e) {
e.printStackTrace();
}

View File

@ -36,7 +36,7 @@ import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.model.ListResponse;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.util.LoganSquareWrapper;
import org.mariotaku.twidere.util.JsonSerializer;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.TwitterContentUtils;
import org.mariotaku.twidere.util.Utils;
@ -185,7 +185,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
private List<ParcelableStatus> getCachedData(final File file) {
if (file == null) return null;
try {
return LoganSquareWrapper.parseList(file, ParcelableStatus.class);
return JsonSerializer.parseList(file, ParcelableStatus.class);
} catch (final IOException e) {
Log.w(LOGTAG, e);
}
@ -195,7 +195,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
private File getSerializationFile() {
if (mSavedStatusesFileArgs == null) return null;
try {
return LoganSquareWrapper.getSerializationFile(mContext, mSavedStatusesFileArgs);
return JsonSerializer.getSerializationFile(mContext, mSavedStatusesFileArgs);
} catch (final IOException e) {
e.printStackTrace();
}

View File

@ -21,15 +21,14 @@ package org.mariotaku.twidere.loader.support;
import android.content.Context;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.api.twitter.model.User;
import org.mariotaku.twidere.model.ParcelableUser;
import java.util.List;
import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.User;
public class UserSearchLoader extends TwitterAPIUsersLoader {
private final String mQuery;

View File

@ -111,6 +111,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.TwidereArrayUtils;
import org.mariotaku.twidere.util.TwidereQueryBuilder.CachedUsersQueryBuilder;
import org.mariotaku.twidere.util.TwidereQueryBuilder.ConversationQueryBuilder;
import org.mariotaku.twidere.util.UriExtraUtils;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.collection.CompactHashSet;
@ -181,10 +182,10 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
private boolean mNameFirst;
private static PendingIntent getMarkReadDeleteIntent(Context context, String type, long accountId, long position) {
return getMarkReadDeleteIntent(context, type, accountId, position, -1);
return getMarkReadDeleteIntent(context, type, accountId, position, -1, -1);
}
private static PendingIntent getMarkReadDeleteIntent(Context context, String type, long accountId, long position, long extraId) {
private static PendingIntent getMarkReadDeleteIntent(Context context, String type, long accountId, long position, long extraId, long extraUserId) {
// Setup delete intent
final Intent intent = new Intent(context, NotificationReceiver.class);
intent.setAction(BROADCAST_NOTIFICATION_DELETED);
@ -194,9 +195,11 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
linkBuilder.appendPath(type);
linkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
linkBuilder.appendQueryParameter(QUERY_PARAM_READ_POSITION, String.valueOf(position));
linkBuilder.appendQueryParameter(QUERY_PARAM_EXTRA_ID, String.valueOf(extraId));
linkBuilder.appendQueryParameter(QUERY_PARAM_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
linkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, type);
UriExtraUtils.addExtra(linkBuilder, "item_id", extraId);
UriExtraUtils.addExtra(linkBuilder, "item_user_id", extraUserId);
intent.setData(linkBuilder.build());
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
@ -1230,6 +1233,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
// Add rich notification and get latest tweet timestamp
for (int i = 0, j = Math.min(statusCursor.getCount(), 5); statusCursor.moveToPosition(i) && i < j; i++) {
final long statusId = statusCursor.getLong(indices.status_id);
final long userId = statusCursor.getLong(indices.user_id);
final String text = statusCursor.getString(indices.text_unescaped);
final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
builder.setTicker(text);
@ -1241,9 +1245,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
builder.setContentText(text);
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
builder.setContentIntent(getStatusContentIntent(context, AUTHORITY_MENTIONS, accountId,
statusId));
statusId, userId));
builder.setDeleteIntent(getMarkReadDeleteIntent(context, AUTHORITY_MENTIONS, accountId,
statusId, statusId));
statusId, statusId, userId));
builder.setWhen(statusCursor.getLong(indices.status_timestamp));
builder.setStyle(style);
style.bigText(text);
@ -1363,7 +1367,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
return PendingIntent.getActivity(context, 0, homeIntent, 0);
}
private PendingIntent getStatusContentIntent(Context context, String type, long accountId, long statusId) {
private PendingIntent getStatusContentIntent(Context context, String type, long accountId,
long statusId, long userId) {
// Setup click intent
final Intent homeIntent = new Intent(Intent.ACTION_VIEW);
homeIntent.setPackage(BuildConfig.APPLICATION_ID);
@ -1372,7 +1377,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
homeLinkBuilder.authority(AUTHORITY_STATUS);
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(statusId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_EXTRA_ID, String.valueOf(statusId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_EXTRA, "item_id=" + String.valueOf(statusId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_EXTRA, "item_user_id=" + String.valueOf(userId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_FROM_NOTIFICATION, String.valueOf(true));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, type);

View File

@ -30,6 +30,7 @@ import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.model.StringLongPair;
import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.UriExtraUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.ApplicationModule;
@ -50,12 +51,14 @@ public class NotificationReceiver extends BroadcastReceiver implements Constants
if (uri == null) return;
final String type = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE);
final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
final long extraId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_EXTRA_ID), -1);
final long itemId = ParseUtils.parseLong(UriExtraUtils.getExtra(uri, "item_id"), -1);
final long itemUserId = ParseUtils.parseLong(UriExtraUtils.getExtra(uri, "item_user_id"), -1);
final long timestamp = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_TIMESTAMP), -1);
final ApplicationModule module = ApplicationModule.get(context);
if (AUTHORITY_MENTIONS.equals(type) && accountId != -1 && extraId != -1 && timestamp != -1) {
if (AUTHORITY_MENTIONS.equals(type) && accountId != -1 && itemId != -1 && timestamp != -1) {
final HotMobiLogger logger = module.getHotMobiLogger();
logger.log(accountId, NotificationEvent.deleted(context, timestamp, type, accountId, extraId));
logger.log(accountId, NotificationEvent.deleted(context, timestamp, type, accountId,
itemId, itemUserId));
}
final ReadStateManager manager = module.getReadStateManager();
final String paramReadPosition, paramReadPositions;

View File

@ -167,7 +167,7 @@ public class DataImportExportUtils implements Constants {
@NonNull final ProcessStrategy strategy) throws IOException {
final ZipEntry entry = zipFile.getEntry(entryName);
if (entry == null) return;
final JSONObject json = LoganSquareWrapper.convertJSONObject(zipFile.getInputStream(entry));
final JSONObject json = JsonSerializer.convertJSONObject(zipFile.getInputStream(entry));
final Iterator<String> keys = json.keys();
final SharedPreferences preferences = context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();

View File

@ -19,12 +19,22 @@
package org.mariotaku.twidere.util;
import android.content.Context;
import android.support.annotation.Nullable;
import com.bluelinelabs.logansquare.LoganSquare;
import org.json.JSONException;
import org.json.JSONObject;
import org.mariotaku.library.logansquare.extension.LoganSquareWrapper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
@ -32,11 +42,13 @@ import java.util.List;
* Created by mariotaku on 15/8/6.
*/
public class JsonSerializer {
public static final String JSON_CACHE_DIR = "json_cache";
@Nullable
public static <T> String serialize(@Nullable final List<T> list, final Class<T> cls) {
if (list == null) return null;
try {
return LoganSquare.serialize(list, cls);
return LoganSquareWrapper.serialize(list, cls);
} catch (IOException e) {
return null;
}
@ -46,7 +58,7 @@ public class JsonSerializer {
public static <T> String serialize(@Nullable final T object, final Class<T> cls) {
if (object == null) return null;
try {
return LoganSquare.mapperFor(cls).serialize(object);
return LoganSquareWrapper.mapperFor(cls).serialize(object);
} catch (IOException e) {
return null;
}
@ -56,7 +68,7 @@ public class JsonSerializer {
public static <T> String serializeArray(@Nullable final T[] object, final Class<T> cls) {
if (object == null) return null;
try {
return LoganSquare.mapperFor(cls).serialize(Arrays.asList(object));
return LoganSquareWrapper.mapperFor(cls).serialize(Arrays.asList(object));
} catch (IOException e) {
return null;
}
@ -66,7 +78,7 @@ public class JsonSerializer {
public static <T> List<T> parseList(@Nullable final String string, final Class<T> cls) {
if (string == null) return null;
try {
return LoganSquare.mapperFor(cls).parseList(string);
return LoganSquareWrapper.mapperFor(cls).parseList(string);
} catch (IOException e) {
return null;
}
@ -76,7 +88,7 @@ public class JsonSerializer {
public static <T> T[] parseArray(@Nullable final String string, final Class<T> cls) {
if (string == null) return null;
try {
final List<T> list = LoganSquare.mapperFor(cls).parseList(string);
final List<T> list = LoganSquareWrapper.mapperFor(cls).parseList(string);
//noinspection unchecked
return list.toArray((T[]) Array.newInstance(cls, list.size()));
} catch (IOException e) {
@ -88,7 +100,7 @@ public class JsonSerializer {
public static <T> T parse(@Nullable final String string, final Class<T> cls) {
if (string == null) return null;
try {
return LoganSquare.mapperFor(cls).parse(string);
return LoganSquareWrapper.mapperFor(cls).parse(string);
} catch (IOException e) {
return null;
}
@ -100,4 +112,46 @@ public class JsonSerializer {
//noinspection unchecked
return serialize(obj, (Class<T>) obj.getClass());
}
public static <E> List<E> parseList(File file, Class<E> jsonObjectClass) throws IOException {
final FileInputStream is = new FileInputStream(file);
//noinspection TryFinallyCanBeTryWithResources
try {
return LoganSquareWrapper.parseList(is, jsonObjectClass);
} finally {
is.close();
}
}
public static JSONObject convertJSONObject(final InputStream stream) throws IOException {
final String string = convertString(stream);
try {
return new JSONObject(string);
} catch (final JSONException e) {
throw new IOException(e);
}
}
public static String convertString(final InputStream stream) throws IOException {
if (stream == null) throw new FileNotFoundException();
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
final StringBuilder buf = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buf.append(line);
buf.append('\n');
}
reader.close();
return buf.toString();
}
public static File getSerializationFile(final Context context, final Object... args) throws IOException {
if (context == null || args == null || args.length == 0) return null;
final File cacheDir = Utils.getBestCacheDir(context, JSON_CACHE_DIR);
if (!cacheDir.exists()) {
AbsLogger.logIfFalse(cacheDir.mkdirs(), "Unable to create cache dir " + cacheDir);
}
final String filename = Utils.encodeQueryParams(TwidereArrayUtils.toString(args, '.', false));
return new File(cacheDir, filename + ".json");
}
}

View File

@ -1,67 +0,0 @@
package org.mariotaku.twidere.util;
import android.content.Context;
import com.bluelinelabs.logansquare.LoganSquare;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.List;
public class LoganSquareWrapper extends LoganSquare {
public static final String JSON_CACHE_DIR = "json_cache";
public static JSONObject convertJSONObject(final InputStream stream) throws IOException {
final String string = convertString(stream);
try {
return new JSONObject(string);
} catch (final JSONException e) {
throw new IOException(e);
}
}
public static <E> List<E> parseList(File file, Class<E> jsonObjectClass) throws IOException {
final FileInputStream is = new FileInputStream(file);
//noinspection TryFinallyCanBeTryWithResources
try {
return LoganSquare.parseList(is, jsonObjectClass);
} finally {
is.close();
}
}
public static String convertString(final InputStream stream) throws IOException {
if (stream == null) throw new FileNotFoundException();
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
final StringBuilder buf = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buf.append(line);
buf.append('\n');
}
reader.close();
return buf.toString();
}
public static File getSerializationFile(final Context context, final Object... args) throws IOException {
if (context == null || args == null || args.length == 0) return null;
final File cacheDir = Utils.getBestCacheDir(context, JSON_CACHE_DIR);
if (!cacheDir.exists()) {
AbsLogger.logIfFalse(cacheDir.mkdirs(), "Unable to create cache dir " + cacheDir);
}
final String filename = Utils.encodeQueryParams(TwidereArrayUtils.toString(args, '.', false));
return new File(cacheDir, filename + ".json");
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.util;
import android.net.Uri;
import org.mariotaku.twidere.Constants;
import java.util.List;
/**
* Created by mariotaku on 15/10/20.
*/
public class UriExtraUtils implements Constants {
public static void addExtra(Uri.Builder builder, String key, Object value) {
builder.appendQueryParameter(QUERY_PARAM_EXTRA, key + "=" + String.valueOf(value));
}
public static String getExtra(Uri uri, String key) {
return getExtra(uri.getQueryParameters(QUERY_PARAM_EXTRA), key);
}
public static String getExtra(List<String> extras, String key) {
for (String extra : extras) {
final int i = extra.indexOf(key + "=");
if (i == 0) {
return extra.substring(i);
}
}
return null;
}
}

View File

@ -3946,12 +3946,14 @@ public final class Utils implements Constants {
if (!uri.getBooleanQueryParameter(QUERY_PARAM_FROM_NOTIFICATION, false)) return;
final String type = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE);
final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
final long extraId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_EXTRA_ID), -1);
final long itemId = ParseUtils.parseLong(UriExtraUtils.getExtra(uri, "item_id"), -1);
final long itemUserId = ParseUtils.parseLong(UriExtraUtils.getExtra(uri, "item_user_id"), -1);
final long timestamp = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_TIMESTAMP), -1);
if (!AUTHORITY_STATUS.equals(type) || accountId < 0 || extraId < 0 || timestamp < 0) return;
if (!AUTHORITY_STATUS.equals(type) || accountId < 0 || itemId < 0 || timestamp < 0) return;
final ApplicationModule module = ApplicationModule.get(context);
final HotMobiLogger logger = module.getHotMobiLogger();
logger.log(accountId, NotificationEvent.open(context, timestamp, type, accountId, extraId));
logger.log(accountId, NotificationEvent.open(context, timestamp, type, accountId, itemId, itemUserId));
}
public static boolean hasOfficialAPIAccess(Context context, SharedPreferences preferences, ParcelableCredentials account) {