updated some api

This commit is contained in:
Mariotaku Lee 2015-05-08 17:29:07 +08:00
parent a01fb65e46
commit 3657295baf
20 changed files with 205 additions and 332 deletions

View File

@ -109,6 +109,7 @@ public final class RestMethodInfo {
for (Map.Entry<Form, Object> entry : forms.entrySet()) {
final Form form = entry.getKey();
final Object value = entry.getValue();
if (value == null) continue;
if (value instanceof ValueMap) {
final ValueMap valueMap = (ValueMap) value;
for (String key : getValueMapKeys(form.value(), valueMap)) {
@ -116,9 +117,11 @@ public final class RestMethodInfo {
list.add(Pair.create(key, String.valueOf(valueMap.get(key))));
}
}
} else if (value != null) {
} else {
final char delimiter = form.arrayDelimiter();
String valueString = Utils.toString(value, delimiter);
for (String key : form.value()) {
list.add(Pair.create(key, String.valueOf(value)));
list.add(Pair.create(key, valueString));
}
}
}
@ -190,6 +193,7 @@ public final class RestMethodInfo {
for (Map.Entry<Query, Object> entry : queries.entrySet()) {
final Query form = entry.getKey();
final Object value = entry.getValue();
if (value == null) continue;
if (value instanceof ValueMap) {
final ValueMap valueMap = (ValueMap) value;
for (String key : getValueMapKeys(form.value(), valueMap)) {
@ -197,9 +201,11 @@ public final class RestMethodInfo {
list.add(Pair.create(key, String.valueOf(valueMap.get(key))));
}
}
} else if (value != null) {
} else {
final char delimiter = form.arrayDelimiter();
String valueString = Utils.toString(value, delimiter);
for (String key : form.value()) {
list.add(Pair.create(key, String.valueOf(value)));
list.add(Pair.create(key, valueString));
}
}
}

View File

@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
@ -157,4 +158,21 @@ public class Utils {
}
return new String(hexChars);
}
@NonNull
public static String toString(@NonNull Object value, char delimiter) {
final Class<?> valueClass = value.getClass();
if (valueClass.isArray()) {
final StringBuilder sb = new StringBuilder();
for (int i = 0, j = Array.getLength(value); i < j; i++) {
if (i != 0) {
sb.append(delimiter);
}
sb.append(Array.get(value, i));
}
return sb.toString();
} else {
return value.toString();
}
}
}

View File

@ -44,6 +44,10 @@ public class SimpleValueMap implements ValueMap {
internalMap.put(key, value);
}
protected void remove(String key) {
internalMap.remove(key);
}
@Override
public String[] keys() {
final Set<String> keySet = internalMap.keySet();

View File

@ -12,4 +12,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Form {
String[] value() default {};
char arrayDelimiter() default ',';
}

View File

@ -12,4 +12,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Header {
String[] value();
char arrayDelimiter() default ',';
}

View File

@ -12,4 +12,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Part {
String[] value();
char arrayDelimiter() default ',';
}

View File

@ -12,4 +12,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Query {
String[] value() default {};
char arrayDelimiter() default ',';
}

View File

@ -34,7 +34,7 @@ import twitter4j.RateLimitStatus;
* Twitter Developers</a>
*/
@JsonObject
final class RateLimitStatusJSONImpl implements RateLimitStatus {
public final class RateLimitStatusJSONImpl implements RateLimitStatus {
private final long creationTimeInMillis;
@ -129,7 +129,7 @@ final class RateLimitStatusJSONImpl implements RateLimitStatus {
'}';
}
static RateLimitStatus createFromResponseHeader(final RestResponse res) {
public static RateLimitStatus createFromResponseHeader(final RestResponse res) {
if (null == res) return null;
int remainingHits;// "X-Rate-Limit-Remaining"
int limit;// "X-Rate-Limit-Limit"

View File

@ -24,15 +24,4 @@ package twitter4j;
public interface IDs extends TwitterResponse, CursorSupport {
long[] getIDs();
@Override
long getNextCursor();
@Override
long getPreviousCursor();
@Override
boolean hasNext();
@Override
boolean hasPrevious();
}

View File

@ -0,0 +1,73 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package twitter4j;
import org.mariotaku.simplerestapi.http.SimpleValueMap;
/**
* Created by mariotaku on 15/1/6.
*/
public class ProfileUpdate extends SimpleValueMap {
public void setName(String name) {
put("name", name);
}
public void setUrl(String url) {
put("url", url);
}
public void setLocation(String location) {
put("location", location);
}
public void setDescription(String description) {
put("description", description);
}
public void setLinkColor(int profileLinkColor) {
put("profile_link_color", profileLinkColor);
}
public ProfileUpdate name(String name) {
setName(name);
return this;
}
public ProfileUpdate url(String url) {
setUrl(url);
return this;
}
public ProfileUpdate location(String location) {
setLocation(location);
return this;
}
public ProfileUpdate description(String description) {
setDescription(description);
return this;
}
public ProfileUpdate linkColor(int linkColor) {
setLinkColor(linkColor);
return this;
}
}

View File

@ -16,28 +16,13 @@
package twitter4j;
import org.mariotaku.simplerestapi.http.ValueMap;
import org.mariotaku.simplerestapi.Utils;
import org.mariotaku.simplerestapi.http.SimpleValueMap;
import java.util.Arrays;
import twitter4j.internal.util.InternalStringUtil;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.1
*/
public final class StatusUpdate implements ValueMap {
private final String status;
private long inReplyToStatusId = -1l;
private GeoLocation location = null;
private String placeId = null;
private boolean displayCoordinates = true;
private boolean possiblySensitive;
private long[] mediaIds;
public final class StatusUpdate extends SimpleValueMap {
public StatusUpdate(final String status) {
this.status = status;
put("status", status);
}
public StatusUpdate displayCoordinates(final boolean displayCoordinates) {
@ -45,40 +30,26 @@ public final class StatusUpdate implements ValueMap {
return this;
}
public long getInReplyToStatusId() {
return inReplyToStatusId;
}
public void setInReplyToStatusId(final long inReplyToStatusId) {
this.inReplyToStatusId = inReplyToStatusId;
}
public GeoLocation getLocation() {
return location;
put("in_reply_to_status_id", inReplyToStatusId);
}
public void setLocation(final GeoLocation location) {
this.location = location;
}
public long[] getMediaIds() {
return mediaIds;
remove("lat");
remove("long");
if (location == null) return;
put("lat", location.getLatitude());
put("long", location.getLongitude());
}
public void setMediaIds(final long... mediaIds) {
this.mediaIds = mediaIds;
}
public String getPlaceId() {
return placeId;
remove("media_ids");
if (mediaIds == null) return;
put("media_ids", Utils.toString(mediaIds, ','));
}
public void setPlaceId(final String placeId) {
this.placeId = placeId;
}
public String getStatus() {
return status;
put("place_id", placeId);
}
public StatusUpdate inReplyToStatusId(final long inReplyToStatusId) {
@ -86,26 +57,14 @@ public final class StatusUpdate implements ValueMap {
return this;
}
public boolean isDisplayCoordinates() {
return displayCoordinates;
}
public void setDisplayCoordinates(final boolean displayCoordinates) {
this.displayCoordinates = displayCoordinates;
put("display_coordinates", displayCoordinates);
}
/**
* @since Twitter4J 2.2.5
*/
public boolean isPossiblySensitive() {
return possiblySensitive;
}
/**
* @since Twitter4J 2.2.5
*/
public void setPossiblySensitive(final boolean possiblySensitive) {
this.possiblySensitive = possiblySensitive;
put("possibly_sensitive", possiblySensitive);
}
public StatusUpdate location(final GeoLocation location) {
@ -123,122 +82,10 @@ public final class StatusUpdate implements ValueMap {
return this;
}
/**
* @since Twitter4J 2.2.5
*/
public StatusUpdate possiblySensitive(final boolean possiblySensitive) {
setPossiblySensitive(possiblySensitive);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatusUpdate that = (StatusUpdate) o;
if (displayCoordinates != that.displayCoordinates) return false;
if (inReplyToStatusId != that.inReplyToStatusId) return false;
if (possiblySensitive != that.possiblySensitive) return false;
if (location != null ? !location.equals(that.location) : that.location != null)
return false;
if (!Arrays.equals(mediaIds, that.mediaIds)) return false;
if (placeId != null ? !placeId.equals(that.placeId) : that.placeId != null) return false;
if (status != null ? !status.equals(that.status) : that.status != null) return false;
return true;
}
@Override
public int hashCode() {
int result = status != null ? status.hashCode() : 0;
result = 31 * result + (int) (inReplyToStatusId ^ (inReplyToStatusId >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (placeId != null ? placeId.hashCode() : 0);
result = 31 * result + (displayCoordinates ? 1 : 0);
result = 31 * result + (possiblySensitive ? 1 : 0);
result = 31 * result + (mediaIds != null ? Arrays.hashCode(mediaIds) : 0);
return result;
}
@Override
public String toString() {
return "StatusUpdate{" +
"status='" + status + '\'' +
", inReplyToStatusId=" + inReplyToStatusId +
", location=" + location +
", placeId='" + placeId + '\'' +
", displayCoordinates=" + displayCoordinates +
", possiblySensitive=" + possiblySensitive +
", mediaIds=" + Arrays.toString(mediaIds) +
'}';
}
@Override
public boolean has(String key) {
switch (key) {
case "status": {
return status != null;
}
case "in_reply_to_status_id": {
return inReplyToStatusId != -1;
}
case "lat":
case "long": {
return location != null;
}
case "place_id": {
return placeId != null;
}
case "possibly_sensitive":
case "display_coordinates": {
return true;
}
case "media_ids": {
return mediaIds != null && mediaIds.length > 0;
}
}
return false;
}
@Override
public String get(String key) {
switch (key) {
case "status": {
return status;
}
case "in_reply_to_status_id": {
return String.valueOf(inReplyToStatusId);
}
case "lat": {
if (location == null) return null;
return String.valueOf(location.getLatitude());
}
case "long": {
if (location == null) return null;
return String.valueOf(location.getLongitude());
}
case "place_id": {
return placeId;
}
case "possibly_sensitive": {
return String.valueOf(possiblySensitive);
}
case "display_coordinates": {
return String.valueOf(displayCoordinates);
}
case "media_ids": {
if (mediaIds == null) return null;
return InternalStringUtil.join(mediaIds);
}
}
return null;
}
@Override
public String[] keys() {
return new String[]{"status", "in_reply_to_status_id", "lat", "long", "place_id",
"possibly_sensitive", "display_coordinates", "media_ids"};
}
}

View File

@ -24,6 +24,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.simplerestapi.http.RestRequest;
import org.mariotaku.simplerestapi.http.RestResponse;
import org.mariotaku.twidere.api.twitter.model.impl.RateLimitStatusJSONImpl;
import java.util.Locale;
@ -44,6 +45,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
ErrorInfo[] errors;
private int statusCode = -1;
private RateLimitStatus rateLimitStatus;
public ErrorInfo[] getErrors() {
return errors;
@ -77,14 +79,15 @@ public class TwitterException extends Exception implements TwitterResponse, Http
public TwitterException(final String message, final RestRequest req, final RestResponse res) {
this(message);
response = res;
setResponse(res);
request = req;
statusCode = res != null ? res.getStatus() : -1;
if (response != null) {
// try {
// decode(response.asString());
// } catch (TwitterException ignore) {
// }
}
private void setResponse(RestResponse res) {
response = res;
if (res != null) {
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(res);
}
}
@ -169,10 +172,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
*/
@Override
public RateLimitStatus getRateLimitStatus() {
// if (null == response) return null;
// return InternalJSONFactoryImpl.createRateLimitStatusFromResponseHeader(response);
// TODO support rate limit message
throw new UnsupportedOperationException();
return rateLimitStatus;
}
public String getResponseHeader(final String name) {

View File

@ -19,8 +19,8 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.param.Query;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Paging;
import twitter4j.ResponseList;
@ -33,38 +33,20 @@ import twitter4j.TwitterException;
public interface TimelinesResources {
@GET("/statuses/home_timeline.json")
ResponseList<Status> getHomeTimeline() throws TwitterException;
@GET("/statuses/home_timeline.json")
ResponseList<Status> getHomeTimeline(@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getHomeTimeline(@Query Paging paging) throws TwitterException;
@GET("/statuses/mentions_timeline.json")
ResponseList<Status> getMentionsTimeline() throws TwitterException;
@GET("/statuses/mentions_timeline.json")
ResponseList<Status> getMentionsTimeline(@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getMentionsTimeline(@Query Paging paging) throws TwitterException;
@GET("/statuses/retweets_of_me.json")
ResponseList<Status> getRetweetsOfMe() throws TwitterException;
@GET("/statuses/retweets_of_me.json")
ResponseList<Status> getRetweetsOfMe(@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getRetweetsOfMe(@Query Paging paging) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline() throws TwitterException;
ResponseList<Status> getUserTimeline(@Query("user_id") long userId, @Query Paging paging) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline(@Query("user_id") long userId) throws TwitterException;
ResponseList<Status> getUserTimeline(@Query Paging paging) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline(@Query("user_id") long userId, @Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline(@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline(@Query("screen_name") String screenName) throws TwitterException;
@GET("/statuses/user_timeline.json")
ResponseList<Status> getUserTimeline(@Query("screen_name") String screenName, @Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getUserTimeline(@Query("screen_name") String screenName, @Query Paging paging) throws TwitterException;
}

View File

@ -29,7 +29,6 @@ import org.mariotaku.simplerestapi.param.Query;
import twitter4j.IDs;
import twitter4j.Paging;
import twitter4j.ReportAs;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.StatusUpdate;
@ -42,17 +41,11 @@ public interface TweetResources {
@POST("/statuses/destroy/{id}.json")
Status destroyStatus(@Path("id") long statusId) throws TwitterException;
@GET("/statuses/retweeters/ids.json")
IDs getRetweetersIDs(@Query("id") long statusId) throws TwitterException;
@GET("/statuses/retweeters/ids.json")
IDs getRetweetersIDs(@Query("id") long statusId, @Query Paging paging) throws TwitterException;
ResponseList<Status> getRetweets(long statusId) throws TwitterException;
ResponseList<Status> getRetweets(long statusId, int count) throws TwitterException;
int reportSpam(long statusId, ReportAs reportAs, boolean blockUser) throws TwitterException;
@GET("/statuses/retweets/{id}.json")
ResponseList<Status> getRetweets(@Path("id") long statusId, @Query Paging paging) throws TwitterException;
@POST("/statuses/retweet/{id}.json")
Status retweetStatus(@Path("id") long statusId) throws TwitterException;
@ -64,7 +57,4 @@ public interface TweetResources {
@Body(BodyType.FORM)
Status updateStatus(@Form StatusUpdate latestStatus) throws TwitterException;
@POST("/statuses/update.json")
@Body(BodyType.FORM)
Status updateStatus(@Form("status") String status) throws TwitterException;
}

View File

@ -19,7 +19,11 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.http.BodyType;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.method.POST;
import org.mariotaku.simplerestapi.param.Body;
import org.mariotaku.simplerestapi.param.Form;
import org.mariotaku.simplerestapi.param.Query;
import java.io.File;
@ -30,6 +34,7 @@ import twitter4j.Category;
import twitter4j.IDs;
import twitter4j.PageableResponseList;
import twitter4j.Paging;
import twitter4j.ProfileUpdate;
import twitter4j.ResponseList;
import twitter4j.SettingsUpdate;
import twitter4j.TwitterException;
@ -39,44 +44,53 @@ import twitter4j.User;
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
public interface UsersResources {
User createBlock(long userId) throws TwitterException;
User createBlock(String screenName) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User createBlock(@Form("user_id") long userId) throws TwitterException;
User createMute(long userId) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User createBlock(@Query("screen_name") String screenName) throws TwitterException;
User createMute(String screenName) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User createMute(@Form("user_id") long userId) throws TwitterException;
User destroyBlock(long userId) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User createMute(@Query("screen_name") String screenName) throws TwitterException;
User destroyBlock(String screenName) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User destroyBlock(@Form("user_id") long userId) throws TwitterException;
User destroyMute(long userId) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User destroyBlock(@Query("screen_name") String screenName) throws TwitterException;
User destroyMute(String screenName) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User destroyMute(@Form("user_id") long userId) throws TwitterException;
@POST("/blocks/create.json")
@Body(BodyType.FORM)
User destroyMute(@Query("screen_name") String screenName) throws TwitterException;
@GET("/account/settings.json")
AccountSettings getAccountSettings() throws TwitterException;
@GET("/blocks/ids.json")
IDs getBlocksIDs() throws TwitterException;
@GET("/blocks/ids.json")
IDs getBlocksIDs(@Query Paging paging) throws TwitterException;
@GET("/blocks/list.json")
PageableResponseList<User> getBlocksList() throws TwitterException;
@GET("/blocks/list.json")
PageableResponseList<User> getBlocksList(@Query Paging paging) throws TwitterException;
ResponseList<User> getMemberSuggestions(String categorySlug) throws TwitterException;
IDs getMutesUsersIDs() throws TwitterException;
@GET("/mutes/users/ids.json")
IDs getMutesUsersIDs(Paging paging) throws TwitterException;
PageableResponseList<User> getMutesUsersList() throws TwitterException;
@GET("/mutes/users/list.json")
PageableResponseList<User> getMutesUsersList(@Query Paging paging) throws TwitterException;
@ -84,10 +98,13 @@ public interface UsersResources {
ResponseList<User> getUserSuggestions(String categorySlug) throws TwitterException;
ResponseList<User> lookupUsers(long[] ids) throws TwitterException;
@POST("/users/lookup.json")
ResponseList<User> lookupUsers(@Form("id") long[] ids) throws TwitterException;
ResponseList<User> lookupUsers(String[] screenNames) throws TwitterException;
@GET("/users/lookup.json")
ResponseList<User> lookupUsers(@Form("id") String[] screenNames) throws TwitterException;
@POST("/account/remove_profile_banner.json")
void removeProfileBannerImage() throws TwitterException;
@GET("/users/search.json")
@ -99,9 +116,13 @@ public interface UsersResources {
@GET("/users/show.json")
User showUser(@Query("screen_name") String screenName) throws TwitterException;
AccountSettings updateAccountSettings(SettingsUpdate settingsUpdate) throws TwitterException;
@POST("/account/settings.json")
@Body(BodyType.FORM)
AccountSettings updateAccountSettings(@Form SettingsUpdate settingsUpdate) throws TwitterException;
User updateProfile(String name, String url, String location, String description) throws TwitterException;
@POST("/account/update_profile.json")
@Body(BodyType.FORM)
User updateProfile(@Form ProfileUpdate profileUpdate) throws TwitterException;
User updateProfileBackgroundImage(File image, boolean tile) throws TwitterException;
@ -117,13 +138,10 @@ public interface UsersResources {
void updateProfileBannerImage(InputStream banner, int width, int height, int offsetLeft, int offsetTop)
throws TwitterException;
User updateProfileColors(String profileBackgroundColor, String profileTextColor, String profileLinkColor,
String profileSidebarFillColor, String profileSidebarBorderColor) throws TwitterException;
User updateProfileImage(File image) throws TwitterException;
User updateProfileImage(InputStream image) throws TwitterException;
@GET(" account/verify_credentials.json")
@GET("/account/verify_credentials.json")
User verifyCredentials() throws TwitterException;
}

View File

@ -69,12 +69,12 @@ import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.ForegroundColorView;
import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener;
import twitter4j.ProfileUpdate;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
import static android.text.TextUtils.isEmpty;
import static org.mariotaku.twidere.util.TwitterAPIUtils.getTwitterInstance;
public class UserProfileEditorFragment extends BaseSupportFragment implements OnSizeChangedListener, TextWatcher,
OnClickListener, LoaderCallbacks<SingleResponse<ParcelableUser>>,
@ -418,7 +418,6 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
private final String mLocation;
private final String mDescription;
private final int mLinkColor;
private final int mBackgroundColor;
private final FragmentActivity mActivity;
public UpdateProfileTaskInternal(final UserProfileEditorFragment fragment,
@ -436,7 +435,6 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
mLocation = location;
mDescription = description;
mLinkColor = linkColor;
mBackgroundColor = backgroundColor;
}
@Override
@ -444,13 +442,14 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(mActivity, mAccountId, true);
try {
User user = null;
if (isColorChanged()) {
final String linkColor = String.format("%08x", mLinkColor).substring(2);
final String backgroundColor = String.format("%08x", mBackgroundColor).substring(2);
user = twitter.updateProfileColors(backgroundColor, null, linkColor, null, null);
}
if (isProfileChanged()) {
user = twitter.updateProfile(mName, mUrl, mLocation, mDescription);
final ProfileUpdate profileUpdate = new ProfileUpdate();
profileUpdate.name(mName);
profileUpdate.url(mUrl);
profileUpdate.location(mLocation);
profileUpdate.description(mDescription);
profileUpdate.linkColor(mLinkColor);
user = twitter.updateProfile(profileUpdate);
}
if (user == null) {
// User profile unchanged
@ -462,17 +461,10 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
}
}
private boolean isColorChanged() {
final ParcelableUser orig = mOriginal;
if (orig == null) return true;
if (mLinkColor != orig.link_color) return true;
if (mBackgroundColor != orig.background_color) return true;
return false;
}
private boolean isProfileChanged() {
final ParcelableUser orig = mOriginal;
if (orig == null) return true;
if (mLinkColor != orig.link_color) return true;
if (!stringEquals(mName, orig.name)) return true;
if (!stringEquals(mDescription, isEmpty(orig.description_expanded) ? orig.description_plain : orig.description_expanded))
return true;

View File

@ -524,9 +524,9 @@ public class BackgroundOperationService extends IntentService implements Constan
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(this, account.account_id, true, true);
final TwitterUpload upload = TwitterAPIUtils.getTwitterInstance(this, account.account_id, true, true, TwitterUpload.class);
final StatusUpdate status = new StatusUpdate(shortenedText);
status.setInReplyToStatusId(statusUpdate.in_reply_to_status_id);
status.inReplyToStatusId(statusUpdate.in_reply_to_status_id);
if (statusUpdate.location != null) {
status.setLocation(ParcelableLocation.toGeoLocation(statusUpdate.location));
status.location(ParcelableLocation.toGeoLocation(statusUpdate.location));
}
if (!mUseUploader && hasMedia) {
final BitmapFactory.Options o = new BitmapFactory.Options();
@ -558,7 +558,7 @@ public class BackgroundOperationService extends IntentService implements Constan
}
status.mediaIds(mediaIds);
}
status.setPossiblySensitive(statusUpdate.is_possibly_sensitive);
status.possiblySensitive(statusUpdate.is_possibly_sensitive);
if (twitter == null) {
results.add(new SingleResponse<ParcelableStatus>(null, new NullPointerException()));

View File

@ -641,43 +641,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
}
public static class UpdateProfileTask extends ManagedAsyncTask<Object, Object, SingleResponse<ParcelableUser>> {
private final long account_id;
private final String name, url, location, description;
private final Context context;
public UpdateProfileTask(final Context context, final AsyncTaskManager manager, final long account_id,
final String name, final String url, final String location, final String description) {
super(context, manager);
this.context = context;
this.account_id = account_id;
this.name = name;
this.url = url;
this.location = location;
this.description = description;
}
@Override
protected SingleResponse<ParcelableUser> doInBackground(final Object... params) {
return updateProfile(context, account_id, name, url, location, description);
}
@Override
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
if (result.hasData()) {
showOkMessage(context, R.string.profile_updated, false);
final Bus bus = TwidereApplication.getInstance(context).getMessageBus();
bus.post(new ProfileUpdatedEvent(result.getData()));
} else {
showErrorMessage(context, context.getString(R.string.action_updating_profile),
result.getException(), true);
}
super.onPostExecute(result);
}
}
class AcceptFriendshipTask extends ManagedAsyncTask<Object, Object, SingleResponse<User>> {
private final long mAccountId;

View File

@ -161,20 +161,6 @@ public class TwitterWrapper implements Constants {
return showUserAlternative(twitter, id, screenName);
}
public static SingleResponse<ParcelableUser> updateProfile(final Context context, final long account_id,
final String name, final String url, final String location, final String description) {
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(context, account_id, false);
if (twitter != null) {
try {
final User user = twitter.updateProfile(name, url, location, description);
return new SingleResponse<>(new ParcelableUser(user, account_id), null);
} catch (final TwitterException e) {
return new SingleResponse<>(null, e);
}
}
return SingleResponse.getInstance();
}
public static void updateProfileBannerImage(final Context context, final long accountId,
final Uri imageUri, final boolean deleteImage)
throws FileNotFoundException, TwitterException {

View File

@ -262,7 +262,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
mediaPreview.setStyle(adapter.getMediaPreviewStyle());
final boolean hasMedia = status.media != null && status.media.length > 0;
if (hasMedia && (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive)) {
mediaPreview.setVisibility(hasMedia ? View.VISIBLE : View.GONE);
mediaPreview.setVisibility(View.VISIBLE);
mediaPreview.displayMedia(status.media, loader, status.account_id, this,
adapter.getMediaLoadingHandler());
} else {
@ -473,7 +473,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
if (adapter.isMediaPreviewEnabled()) {
final boolean hasMedia = media != null && media.length > 0;
if (hasMedia && (adapter.isSensitiveContentEnabled() || !sensitive)) {
mediaPreview.setVisibility(hasMedia ? View.VISIBLE : View.GONE);
mediaPreview.setVisibility(View.VISIBLE);
mediaPreview.displayMedia(media, loader, account_id, this, adapter.getMediaLoadingHandler());
} else {
mediaPreview.setVisibility(View.GONE);