improved statusnet api

This commit is contained in:
Mariotaku Lee 2016-03-05 00:40:23 +08:00
parent 7a77a25452
commit 680deb22c5
10 changed files with 62 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.api.statusnet.api; package org.mariotaku.twidere.api.statusnet.api;
import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.method.GET;
import org.mariotaku.restfu.annotation.param.Path;
import org.mariotaku.restfu.annotation.param.Query; import org.mariotaku.restfu.annotation.param.Query;
import org.mariotaku.twidere.api.statusnet.model.StatusNetConfig; import org.mariotaku.twidere.api.statusnet.model.StatusNetConfig;
import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.TwitterException;
@ -16,5 +17,6 @@ public interface StatusNetResources {
@GET("/statusnet/config.json") @GET("/statusnet/config.json")
StatusNetConfig getStatusNetConfig() throws TwitterException; StatusNetConfig getStatusNetConfig() throws TwitterException;
@GET("/statusnet/conversation/{id}.json")
ResponseList<Status> getStatusNetConversation(@Path("id") long statusId, @Query Paging paging) throws TwitterException;
} }

View File

@ -44,12 +44,6 @@ public interface PrivateTweetResources extends PrivateResources {
@GET("/statuses/{id}/activity/summary.json") @GET("/statuses/{id}/activity/summary.json")
StatusActivitySummary getStatusActivitySummary(@Path("id") long statusId) throws TwitterException; StatusActivitySummary getStatusActivitySummary(@Path("id") long statusId) throws TwitterException;
@GET("/statuses/{id}/activity/summary.json")
StatusActivitySummary getStatusActivitySummary(@Path("id") long statusId, boolean includeUserEntities) throws TwitterException;
@GET("/conversation/show.json")
ResponseList<Status> showConversation(@Query("id") long statusId) throws TwitterException;
@GET("/conversation/show.json") @GET("/conversation/show.json")
ResponseList<Status> showConversation(@Query("id") long statusId, @Query Paging paging) throws TwitterException; ResponseList<Status> showConversation(@Query("id") long statusId, @Query Paging paging) throws TwitterException;

View File

@ -73,6 +73,9 @@ public class User extends TwitterResponseObject implements Comparable<User> {
@JsonField(name = "listed_count") @JsonField(name = "listed_count")
long listedCount = -1; long listedCount = -1;
@JsonField(name = "groups_count")
long groupsCount = -1;
@JsonField(name = "created_at", typeConverter = TwitterDateConverter.class) @JsonField(name = "created_at", typeConverter = TwitterDateConverter.class)
Date createdAt; Date createdAt;
@ -299,6 +302,9 @@ public class User extends TwitterResponseObject implements Comparable<User> {
return listedCount; return listedCount;
} }
public long getGroupsCount() {
return groupsCount;
}
public String getLocation() { public String getLocation() {
return location; return location;

View File

@ -307,6 +307,9 @@ public class ParcelableUser implements Parcelable, Comparable<ParcelableUser> {
@JsonField(name = "profile_image_url_profile_size") @JsonField(name = "profile_image_url_profile_size")
@ParcelableThisPlease @ParcelableThisPlease
public String profile_image_url_profile_size; public String profile_image_url_profile_size;
@JsonField(name = "groups_count")
@ParcelableThisPlease
public long groups_count = -1;
@Override @Override
public int describeContents() { public int describeContents() {

View File

@ -181,9 +181,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private ProfileBannerImageView mProfileBannerView; private ProfileBannerImageView mProfileBannerView;
private View mProfileBirthdayBannerView; private View mProfileBirthdayBannerView;
private TextView mNameView, mScreenNameView, mDescriptionView, mLocationView, mURLView, mCreatedAtView, private TextView mNameView, mScreenNameView, mDescriptionView, mLocationView, mURLView, mCreatedAtView,
mListedCount, mFollowersCount, mFriendsCount, mHeaderErrorTextView; mHeaderErrorTextView;
private View mDescriptionContainer, mLocationContainer, mURLContainer, mListedContainer, mFollowersContainer, private TextView mListedCount, mFollowersCount, mFriendsCount, mGroupsCount;
mFriendsContainer; private View mDescriptionContainer, mLocationContainer, mURLContainer;
private View mListedContainer, mFollowersContainer, mFriendsContainer, mGroupsContainer;
private ImageView mHeaderErrorIcon; private ImageView mHeaderErrorIcon;
private ColorLabelRelativeLayout mProfileNameContainer; private ColorLabelRelativeLayout mProfileNameContainer;
private View mProgressContainer, mHeaderErrorContainer; private View mProgressContainer, mHeaderErrorContainer;
@ -554,9 +555,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mCreatedAtView.setText(resources.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets, mCreatedAtView.setText(resources.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets,
createdAt, dailyTweets)); createdAt, dailyTweets));
mListedCount.setText(Utils.getLocalizedNumber(mLocale, user.listed_count)); mListedCount.setText(Utils.getLocalizedNumber(mLocale, user.listed_count));
final long groupsCount = user.extras != null ? user.extras.groups_count : -1;
mGroupsCount.setText(Utils.getLocalizedNumber(mLocale, groupsCount));
mFollowersCount.setText(Utils.getLocalizedNumber(mLocale, user.followers_count)); mFollowersCount.setText(Utils.getLocalizedNumber(mLocale, user.followers_count));
mFriendsCount.setText(Utils.getLocalizedNumber(mLocale, user.friends_count)); mFriendsCount.setText(Utils.getLocalizedNumber(mLocale, user.friends_count));
mListedContainer.setVisibility(user.listed_count < 0 ? View.GONE : View.VISIBLE);
mGroupsContainer.setVisibility(groupsCount < 0 ? View.GONE : View.VISIBLE);
mMediaLoader.displayOriginalProfileImage(mProfileImageView, user); mMediaLoader.displayOriginalProfileImage(mProfileImageView, user);
if (userColor != 0) { if (userColor != 0) {
setUiColor(userColor); setUiColor(userColor);
@ -1150,7 +1156,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mURLView = (TextView) headerView.findViewById(R.id.url); mURLView = (TextView) headerView.findViewById(R.id.url);
mCreatedAtView = (TextView) headerView.findViewById(R.id.created_at); mCreatedAtView = (TextView) headerView.findViewById(R.id.created_at);
mListedContainer = headerView.findViewById(R.id.listed_container); mListedContainer = headerView.findViewById(R.id.listed_container);
mGroupsContainer = headerView.findViewById(R.id.groups_container);
mListedCount = (TextView) headerView.findViewById(R.id.listed_count); mListedCount = (TextView) headerView.findViewById(R.id.listed_count);
mGroupsCount = (TextView) headerView.findViewById(R.id.groups_count);
mFollowersContainer = headerView.findViewById(R.id.followers_container); mFollowersContainer = headerView.findViewById(R.id.followers_container);
mFollowersCount = (TextView) headerView.findViewById(R.id.followers_count); mFollowersCount = (TextView) headerView.findViewById(R.id.followers_count);
mFriendsContainer = headerView.findViewById(R.id.friends_container); mFriendsContainer = headerView.findViewById(R.id.friends_container);

View File

@ -63,6 +63,8 @@ public class ConversationLoader extends TwitterAPIStatusesLoader {
if (credentials == null) throw new TwitterException("Null credentials"); if (credentials == null) throw new TwitterException("Null credentials");
if (Utils.isOfficialCredentials(getContext(), credentials)) { if (Utils.isOfficialCredentials(getContext(), credentials)) {
return twitter.showConversation(status.id, paging); return twitter.showConversation(status.id, paging);
} else if (!TwitterAPIFactory.isTwitterCredentials(credentials)) {
return twitter.getStatusNetConversation(status.id, paging);
} }
final List<Status> statuses = new ArrayList<>(); final List<Status> statuses = new ArrayList<>();
final long maxId = getMaxId(), sinceId = getSinceId(); final long maxId = getMaxId(), sinceId = getSinceId();

View File

@ -1,7 +1,6 @@
package org.mariotaku.twidere.model.util; package org.mariotaku.twidere.model.util;
import android.database.Cursor; import android.database.Cursor;
import android.support.annotation.Nullable;
import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.api.twitter.model.UrlEntity; import org.mariotaku.twidere.api.twitter.model.UrlEntity;
@ -17,7 +16,7 @@ import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor;
/** /**
* Created by mariotaku on 16/2/24. * Created by mariotaku on 16/2/24.
*/ */
public class ParcelableUserUtils implements TwidereConstants{ public class ParcelableUserUtils implements TwidereConstants {
public static ParcelableUser fromUser(User user, long accountId) { public static ParcelableUser fromUser(User user, long accountId) {
return fromUser(user, accountId, 0); return fromUser(user, accountId, 0);
@ -64,6 +63,7 @@ public class ParcelableUserUtils implements TwidereConstants{
extras.statusnet_profile_url = user.getStatusnetProfileUrl(); extras.statusnet_profile_url = user.getStatusnetProfileUrl();
extras.profile_image_url_original = user.getProfileImageUrlOriginal(); extras.profile_image_url_original = user.getProfileImageUrlOriginal();
extras.profile_image_url_profile_size = user.getProfileImageUrlProfileSize(); extras.profile_image_url_profile_size = user.getProfileImageUrlProfileSize();
extras.groups_count = user.getGroupsCount();
obj.extras = extras; obj.extras = extras;
obj.user_type = getUserType(extras.ostatus_uri); obj.user_type = getUserType(extras.ostatus_uri);
return obj; return obj;

View File

@ -151,9 +151,12 @@ public class TwitterWrapper implements Constants {
try { try {
return showUser(twitter, id, screenName); return showUser(twitter, id, screenName);
} catch (final TwitterException e) { } catch (final TwitterException e) {
if (e.isCausedByNetworkIssue()) throw e; // Twitter specific error for private API calling through proxy
if (e.getStatusCode() == 200) {
return showUserAlternative(twitter, id, screenName);
}
throw e;
} }
return showUserAlternative(twitter, id, screenName);
} }
public static void updateProfileBannerImage(final Context context, final long accountId, public static void updateProfileBannerImage(final Context context, final long accountId,

View File

@ -362,6 +362,35 @@
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorSecondary" /> android:textColor="?android:textColorSecondary" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/groups_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?selectableItemBackground"
android:clickable="true"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/element_spacing_small">
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/groups_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
tools:text="255" />
<org.mariotaku.twidere.view.themed.ThemedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/groups"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorSecondary" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -755,4 +755,5 @@
<string name="translation">Translation</string> <string name="translation">Translation</string>
<string name="shortener_version_incompatible">Incompatible tweet shortener</string> <string name="shortener_version_incompatible">Incompatible tweet shortener</string>
<string name="uploader_version_incompatible">Incompatible media uploader</string> <string name="uploader_version_incompatible">Incompatible media uploader</string>
<string name="groups">Groups</string>
</resources> </resources>