From 196901670017142e58e44e606ddda8405b60c730 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 15 Feb 2016 14:53:27 +0800 Subject: [PATCH] implemented follow request --- .../api/PrivateFriendsFollowersResources.java | 15 +- .../twidere/constant/IntentConstants.java | 2 - .../twidere/model/ParcelableUser.java | 120 ++++++------ .../activity/support/HomeActivity.java | 4 +- .../support/UserListSelectorActivity.java | 2 +- .../adapter/AbsParcelableStatusesAdapter.java | 7 +- .../twidere/adapter/AbsUsersAdapter.java | 47 ++--- .../adapter/ParcelableActivitiesAdapter.java | 11 +- .../adapter/ParcelableUsersAdapter.java | 42 ++++- .../twidere/adapter/iface/IUsersAdapter.java | 24 ++- .../support/AbsActivitiesFragment.java | 2 +- .../fragment/support/AbsStatusesFragment.java | 2 +- .../fragment/support/AbsUsersFragment.java | 6 +- .../support/CursorActivitiesFragment.java | 14 +- .../support/CursorStatusesFragment.java | 14 +- .../support/DirectMessagesFragment.java | 2 +- .../support/IncomingFriendshipsFragment.java | 57 +++++- .../support/MessagesConversationFragment.java | 2 +- .../support/ParcelableStatusesFragment.java | 10 +- .../support/ParcelableUsersFragment.java | 9 +- .../fragment/support/StatusFragment.java | 6 +- .../support/TrendsSuggestionsFragment.java | 2 +- .../fragment/support/UserFragment.java | 8 +- .../fragment/support/UserListsFragment.java | 2 +- .../message/AccountChangedEvent.java | 2 +- .../message/FavoriteCreatedEvent.java | 2 +- .../message/FavoriteDestroyedEvent.java | 2 +- .../model/message/FollowRequestTaskEvent.java | 67 +++++++ .../message/FriendshipUpdatedEvent.java | 2 +- .../message/FriendshipUserUpdatedEvent.java | 2 +- .../message/GetActivitiesTaskEvent.java | 2 +- .../message/GetMessagesTaskEvent.java | 2 +- .../message/GetStatusesTaskEvent.java | 2 +- .../message/ProfileUpdatedEvent.java | 2 +- .../message/StatusDestroyedEvent.java | 2 +- .../message/StatusItemChangedEvent.java | 2 +- .../message/StatusListChangedEvent.java | 2 +- .../message/StatusRetweetedEvent.java | 2 +- .../message/TaskStateChangedEvent.java | 2 +- .../message/UnreadCountUpdatedEvent.java | 2 +- .../message/UserListCreatedEvent.java | 2 +- .../message/UserListDestroyedEvent.java | 2 +- .../message/VideoLoadFinishedEvent.java | 2 +- .../twidere/provider/TwidereDataProvider.java | 2 +- .../twidere/task/GetDirectMessagesTask.java | 2 +- .../twidere/task/ManagedAsyncTask.java | 11 +- .../task/twitter/GetActivitiesTask.java | 2 +- .../twidere/task/twitter/GetStatusesTask.java | 2 +- .../twidere/util/AsyncTwitterWrapper.java | 103 +++++++--- .../org/mariotaku/twidere/view/NameView.java | 16 +- .../twidere/view/holder/UserViewHolder.java | 64 +++++-- .../src/main/res/layout/activity_sign_in.xml | 19 +- .../src/main/res/layout/card_item_user.xml | 177 ------------------ .../res/layout/card_item_user_compact.xml | 145 +++++++++----- .../layout/card_item_user_list_compact.xml | 21 ++- twidere/src/main/res/values/dimens.xml | 3 - 56 files changed, 612 insertions(+), 468 deletions(-) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/AccountChangedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/FavoriteCreatedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/FavoriteDestroyedEvent.java (96%) create mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/FriendshipUpdatedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/FriendshipUserUpdatedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/GetActivitiesTaskEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/GetMessagesTaskEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/GetStatusesTaskEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/ProfileUpdatedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/StatusDestroyedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/StatusItemChangedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/StatusListChangedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/StatusRetweetedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/TaskStateChangedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/UnreadCountUpdatedEvent.java (95%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/UserListCreatedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/UserListDestroyedEvent.java (96%) rename twidere/src/main/java/org/mariotaku/twidere/{util => model}/message/VideoLoadFinishedEvent.java (95%) delete mode 100644 twidere/src/main/res/layout/card_item_user.xml diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/PrivateFriendsFollowersResources.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/PrivateFriendsFollowersResources.java index bfe17fd49..2ceb6d98b 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/PrivateFriendsFollowersResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/PrivateFriendsFollowersResources.java @@ -19,21 +19,26 @@ package org.mariotaku.twidere.api.twitter.api; +import org.mariotaku.restfu.annotation.method.POST; import org.mariotaku.restfu.annotation.param.KeyValue; +import org.mariotaku.restfu.annotation.param.Param; import org.mariotaku.restfu.annotation.param.Queries; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.User; -@SuppressWarnings("RedundantThrows") @Queries({@KeyValue(key = "include_entities", valueKey = "include_entities")}) public interface PrivateFriendsFollowersResources extends PrivateResources { - User acceptFriendship(long userId) throws TwitterException; + @POST("/friendships/accept.json") + User acceptFriendship(@Param("user_id") long userId) throws TwitterException; - User acceptFriendship(String screenName) throws TwitterException; + @POST("/friendships/accept.json") + User acceptFriendship(@Param("screen_name") String screenName) throws TwitterException; - User denyFriendship(long userId) throws TwitterException; + @POST("/friendships/deny.json") + User denyFriendship(@Param("user_id") long userId) throws TwitterException; - User denyFriendship(String screenName) throws TwitterException; + @POST("/friendships/deny.json") + User denyFriendship(@Param("screen_name") String screenName) throws TwitterException; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index aab193789..744f66d2e 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -75,8 +75,6 @@ public interface IntentConstants { String BROADCAST_NOTIFICATION_DELETED = INTENT_PACKAGE_PREFIX + "NOTIFICATION_DELETED"; String BROADCAST_USER_LIST_DETAILS_UPDATED = INTENT_PACKAGE_PREFIX + "USER_LIST_DETAILS_UPDATED"; - String BROADCAST_FRIENDSHIP_ACCEPTED = INTENT_PACKAGE_PREFIX + "FRIENDSHIP_ACCEPTED"; - String BROADCAST_FRIENDSHIP_DENIED = INTENT_PACKAGE_PREFIX + "FRIENDSHIP_DENIED"; String BROADCAST_USER_LIST_MEMBERS_DELETED = INTENT_PACKAGE_PREFIX + "USER_LIST_MEMBER_DELETED"; String BROADCAST_USER_LIST_MEMBERS_ADDED = INTENT_PACKAGE_PREFIX + "USER_LIST_MEMBER_ADDED"; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java index b018caa55..c47e19dc3 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java @@ -170,6 +170,17 @@ public class ParcelableUser implements Parcelable, Comparable { @ParcelableThisPlease @JsonField(name = "is_basic") public boolean is_basic; + public static final Creator CREATOR = new Creator() { + public ParcelableUser createFromParcel(Parcel source) { + ParcelableUser target = new ParcelableUser(); + ParcelableUserParcelablePlease.readFromParcel(target, source); + return target; + } + + public ParcelableUser[] newArray(int size) { + return new ParcelableUser[size]; + } + }; public ParcelableUser() { } @@ -208,13 +219,6 @@ public class ParcelableUser implements Parcelable, Comparable { is_basic = true; } - @AfterCursorObjectCreated - void afterCursorObjectCreated() { - is_cache = true; - description_unescaped = HtmlEscapeHelper.toPlainText(description_html); - is_basic = description_plain == null || url == null || location == null; - } - public ParcelableUser(final User user, final long account_id) { this(user, account_id, 0); } @@ -253,12 +257,12 @@ public class ParcelableUser implements Parcelable, Comparable { is_basic = false; } - @Override - public int compareTo(@NonNull final ParcelableUser that) { - final long diff = position - that.position; - if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; - if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; - return (int) diff; + public static int calculateHashCode(long accountId, long userId) { + final int prime = 31; + int result = 1; + result = prime * result + (int) (accountId ^ accountId >>> 32); + result = prime * result + (int) (userId ^ userId >>> 32); + return result; } public static ParcelableUser[] fromUsersArray(@Nullable final User[] users, long account_id) { @@ -270,40 +274,6 @@ public class ParcelableUser implements Parcelable, Comparable { return result; } - @Override - public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof ParcelableUser)) return false; - final ParcelableUser other = (ParcelableUser) obj; - if (account_id != other.account_id) return false; - if (id != other.id) return false; - return true; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (int) (account_id ^ account_id >>> 32); - result = prime * result + (int) (id ^ id >>> 32); - return result; - } - - @Override - public String toString() { - return "ParcelableUser{account_id=" + account_id + ", id=" + id + ", created_at=" + created_at + ", position=" - + position + ", is_protected=" + is_protected + ", is_verified=" + is_verified - + ", is_follow_request_sent=" + is_follow_request_sent + ", is_following=" + is_following - + ", description_plain=" + description_plain + ", name=" + name + ", screen_name=" + screen_name - + ", location=" + location + ", profile_image_url=" + profile_image_url + ", profile_banner_url=" - + profile_banner_url + ", url=" + url + ", url_expanded=" + url_expanded + ", description_html=" - + description_html + ", description_unescaped=" + description_unescaped + ", description_expanded=" - + description_expanded + ", followers_count=" + followers_count + ", friends_count=" + friends_count - + ", statuses_count=" + statuses_count + ", favorites_count=" + favorites_count + ", is_cache=" - + is_cache + "}"; - } - public static ParcelableUser fromDirectMessageConversationEntry(final Cursor cursor) { final long account_id = cursor.getLong(ConversationEntries.IDX_ACCOUNT_ID); final long id = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID); @@ -323,6 +293,50 @@ public class ParcelableUser implements Parcelable, Comparable { return result; } + @AfterCursorObjectCreated + void afterCursorObjectCreated() { + is_cache = true; + description_unescaped = HtmlEscapeHelper.toPlainText(description_html); + is_basic = description_plain == null || url == null || location == null; + } + + @Override + public int compareTo(@NonNull final ParcelableUser that) { + final long diff = position - that.position; + if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; + if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; + return (int) diff; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof ParcelableUser)) return false; + final ParcelableUser other = (ParcelableUser) obj; + if (account_id != other.account_id) return false; + if (id != other.id) return false; + return true; + } + + @Override + public int hashCode() { + return calculateHashCode(account_id, id); + } + + @Override + public String toString() { + return "ParcelableUser{account_id=" + account_id + ", id=" + id + ", created_at=" + created_at + ", position=" + + position + ", is_protected=" + is_protected + ", is_verified=" + is_verified + + ", is_follow_request_sent=" + is_follow_request_sent + ", is_following=" + is_following + + ", description_plain=" + description_plain + ", name=" + name + ", screen_name=" + screen_name + + ", location=" + location + ", profile_image_url=" + profile_image_url + ", profile_banner_url=" + + profile_banner_url + ", url=" + url + ", url_expanded=" + url_expanded + ", description_html=" + + description_html + ", description_unescaped=" + description_unescaped + ", description_expanded=" + + description_expanded + ", followers_count=" + followers_count + ", friends_count=" + friends_count + + ", statuses_count=" + statuses_count + ", favorites_count=" + favorites_count + ", is_cache=" + + is_cache + "}"; + } @Override public int describeContents() { @@ -333,16 +347,4 @@ public class ParcelableUser implements Parcelable, Comparable { public void writeToParcel(Parcel dest, int flags) { ParcelableUserParcelablePlease.writeToParcel(this, dest, flags); } - - public static final Creator CREATOR = new Creator() { - public ParcelableUser createFromParcel(Parcel source) { - ParcelableUser target = new ParcelableUser(); - ParcelableUserParcelablePlease.readFromParcel(target, source); - return target; - } - - public ParcelableUser[] newArray(int size) { - return new ParcelableUser[size]; - } - }; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java index 6df236aee..e5d9d3140 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java @@ -98,8 +98,8 @@ import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TwidereColorUtils; import org.mariotaku.twidere.util.TwidereMathUtils; import org.mariotaku.twidere.util.Utils; -import org.mariotaku.twidere.util.message.TaskStateChangedEvent; -import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent; +import org.mariotaku.twidere.model.message.TaskStateChangedEvent; +import org.mariotaku.twidere.model.message.UnreadCountUpdatedEvent; import org.mariotaku.twidere.util.support.ActivitySupport; import org.mariotaku.twidere.util.support.ActivitySupport.TaskDescriptionCompat; import org.mariotaku.twidere.util.support.ViewSupport; diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java index fcdc0457d..599d85d10 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java @@ -54,7 +54,7 @@ import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.util.AsyncTaskUtils; import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.TwitterAPIFactory; -import org.mariotaku.twidere.util.message.UserListCreatedEvent; +import org.mariotaku.twidere.model.message.UserListCreatedEvent; import java.util.ArrayList; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java index 924755ec4..71f2ff24c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java @@ -46,9 +46,10 @@ public abstract class AbsParcelableStatusesAdapter extends AbsStatusesAdapter
  • = getStatusCount()) return null; + return mData.get(dataPosition); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsUsersAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsUsersAdapter.java index 2a8663f62..8f116f3e8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsUsersAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsUsersAdapter.java @@ -45,6 +45,8 @@ public abstract class AbsUsersAdapter extends LoadMoreSupportAdapter extends LoadMoreSupportAdapter extends LoadMoreSupportAdapter extends LoadMoreSupportAdapter= getActivityCount()) return null; + return mData.get(dataPosition); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.java index 7682bed51..ca9c49628 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.java @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter; import android.content.Context; +import android.support.v7.widget.RecyclerView; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.view.holder.UserViewHolder; @@ -55,7 +56,7 @@ public class ParcelableUsersAdapter extends AbsUsersAdapter @Override public int getItemCount() { final int position = getLoadMoreIndicatorPosition(); - int count = getUsersCount(); + int count = getUserCount(); if ((position & IndicatorPosition.START) != 0) { count++; } @@ -66,20 +67,49 @@ public class ParcelableUsersAdapter extends AbsUsersAdapter } @Override - public ParcelableUser getUser(int position) { - if (position == getUsersCount()) return null; - return mData.get(position); + public ParcelableUser getUser(int adapterPosition) { + int dataPosition = adapterPosition - getUserStartIndex(); + if (dataPosition < 0 || dataPosition >= getUserCount()) return null; + return mData.get(dataPosition); + } + + public int getUserStartIndex() { + final int position = getLoadMoreIndicatorPosition(); + int start = 0; + if ((position & IndicatorPosition.START) != 0) { + start += 1; + } + return start; } @Override public long getUserId(int position) { - if (position == getUsersCount()) return -1; + if (position == getUserCount()) return -1; return mData.get(position).id; } @Override - public int getUsersCount() { + public int getUserCount() { if (mData == null) return 0; return mData.size(); } + + public boolean removeUserAt(int adapterPosition) { + int dataPosition = adapterPosition - getUserStartIndex(); + if (dataPosition < 0 || dataPosition >= getUserCount()) return false; + mData.remove(dataPosition); + notifyItemRemoved(adapterPosition); + return true; + } + + public int findPosition(long accountId, long userId) { + if (mData == null) return RecyclerView.NO_POSITION; + for (int i = getUserStartIndex(), j = i + getUserCount(); i < j; i++) { + final ParcelableUser user = mData.get(i); + if (user.account_id == accountId && user.id == userId) { + return i; + } + } + return RecyclerView.NO_POSITION; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IUsersAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IUsersAdapter.java index a1c762b22..2c17dc651 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IUsersAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IUsersAdapter.java @@ -23,25 +23,43 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.util.MediaLoaderWrapper; -import org.mariotaku.twidere.view.holder.UserViewHolder.UserClickListener; +import org.mariotaku.twidere.view.holder.UserViewHolder; /** * Created by mariotaku on 15/4/16. */ -public interface IUsersAdapter extends IContentCardAdapter, UserClickListener { +public interface IUsersAdapter extends IContentCardAdapter { ParcelableUser getUser(int position); long getUserId(int position); - int getUsersCount(); + int getUserCount(); void setData(Data data); + UserAdapterListener getUserAdapterListener(); + + RequestClickListener getRequestClickListener(); + boolean shouldShowAccountsColor(); @NonNull @Override MediaLoaderWrapper getMediaLoader(); + interface UserAdapterListener { + + void onUserClick(UserViewHolder holder, int position); + + boolean onUserLongClick(UserViewHolder holder, int position); + + } + + interface RequestClickListener { + + void onAcceptClicked(UserViewHolder holder, int position); + + void onDenyClicked(UserViewHolder holder, int position); + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java index 6ef7de2c5..357fed789 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java @@ -57,7 +57,7 @@ import org.mariotaku.twidere.util.RecyclerViewNavigationHelper; import org.mariotaku.twidere.util.RecyclerViewUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.imageloader.PauseRecyclerViewOnScrollListener; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder; import org.mariotaku.twidere.view.holder.GapViewHolder; import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index 21f3c49ce..33fcd0b64 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -60,7 +60,7 @@ import org.mariotaku.twidere.util.RecyclerViewNavigationHelper; import org.mariotaku.twidere.util.RecyclerViewUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.imageloader.PauseRecyclerViewOnScrollListener; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.view.holder.GapViewHolder; import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java index cb930db56..b655ac1d6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java @@ -31,7 +31,7 @@ import android.support.v7.widget.RecyclerView; import android.view.KeyEvent; import org.mariotaku.twidere.adapter.AbsUsersAdapter; -import org.mariotaku.twidere.adapter.AbsUsersAdapter.UserAdapterListener; +import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserAdapterListener; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.loader.iface.IExtendedLoader; import org.mariotaku.twidere.model.ParcelableUser; @@ -71,7 +71,7 @@ abstract class AbsUsersFragment extends AbsContentListRecyclerViewFragment final AbsUsersAdapter adapter = getAdapter(); final RecyclerView recyclerView = getRecyclerView(); final LinearLayoutManager layoutManager = getLayoutManager(); - adapter.setListener(this); + adapter.setUserAdapterListener(this); mNavigationHelper = new RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, this); @@ -131,7 +131,7 @@ abstract class AbsUsersFragment extends AbsContentListRecyclerViewFragment @Override protected void setupRecyclerView(Context context, boolean compact) { - + super.setupRecyclerView(context, true); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java index ba58c0475..b074340bf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java @@ -52,13 +52,13 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.ErrorInfoStore; -import org.mariotaku.twidere.util.message.AccountChangedEvent; -import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; -import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; -import org.mariotaku.twidere.util.message.GetActivitiesTaskEvent; -import org.mariotaku.twidere.util.message.StatusDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; -import org.mariotaku.twidere.util.message.StatusRetweetedEvent; +import org.mariotaku.twidere.model.message.AccountChangedEvent; +import org.mariotaku.twidere.model.message.FavoriteCreatedEvent; +import org.mariotaku.twidere.model.message.FavoriteDestroyedEvent; +import org.mariotaku.twidere.model.message.GetActivitiesTaskEvent; +import org.mariotaku.twidere.model.message.StatusDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusRetweetedEvent; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java index 0e038e99e..8d5170ca8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java @@ -49,13 +49,13 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.ErrorInfoStore; -import org.mariotaku.twidere.util.message.AccountChangedEvent; -import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; -import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; -import org.mariotaku.twidere.util.message.GetStatusesTaskEvent; -import org.mariotaku.twidere.util.message.StatusDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; -import org.mariotaku.twidere.util.message.StatusRetweetedEvent; +import org.mariotaku.twidere.model.message.AccountChangedEvent; +import org.mariotaku.twidere.model.message.FavoriteCreatedEvent; +import org.mariotaku.twidere.model.message.FavoriteDestroyedEvent; +import org.mariotaku.twidere.model.message.GetStatusesTaskEvent; +import org.mariotaku.twidere.model.message.StatusDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusRetweetedEvent; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java index c13be59b6..d602fb0bf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java @@ -65,7 +65,7 @@ import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallb import org.mariotaku.twidere.util.RecyclerViewNavigationHelper; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver; -import org.mariotaku.twidere.util.message.GetMessagesTaskEvent; +import org.mariotaku.twidere.model.message.GetMessagesTaskEvent; import java.util.Collections; import java.util.HashSet; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java index 2a62a7b88..3312998a1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java @@ -23,10 +23,31 @@ import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; +import com.squareup.otto.Subscribe; + +import org.mariotaku.twidere.adapter.AbsUsersAdapter; +import org.mariotaku.twidere.adapter.ParcelableUsersAdapter; +import org.mariotaku.twidere.adapter.iface.IUsersAdapter; import org.mariotaku.twidere.loader.support.IDsUsersLoader; import org.mariotaku.twidere.loader.support.IncomingFriendshipsLoader; +import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.message.FollowRequestTaskEvent; +import org.mariotaku.twidere.view.holder.UserViewHolder; -public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment { +import java.util.List; + +public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment implements IUsersAdapter.RequestClickListener { + @Override + public void onStart() { + super.onStart(); + mBus.register(this); + } + + @Override + public void onStop() { + mBus.unregister(this); + super.onStop(); + } @Override public IDsUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { @@ -34,4 +55,38 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment return new IncomingFriendshipsLoader(context, accountId, getNextCursor(), getData(), fromUser); } + @NonNull + @Override + protected ParcelableUsersAdapter onCreateAdapter(Context context, boolean compact) { + final ParcelableUsersAdapter adapter = super.onCreateAdapter(context, compact); + adapter.setRequestClickListener(this); + return adapter; + } + + @Override + public void onAcceptClicked(UserViewHolder holder, int position) { + final AbsUsersAdapter> adapter = getAdapter(); + final ParcelableUser user = adapter.getUser(position); + if (user == null) return; + mTwitterWrapper.acceptFriendshipAsync(user.account_id, user.id); + } + + @Override + public void onDenyClicked(UserViewHolder holder, int position) { + final AbsUsersAdapter> adapter = getAdapter(); + final ParcelableUser user = adapter.getUser(position); + if (user == null) return; + mTwitterWrapper.denyFriendshipAsync(user.account_id, user.id); + } + + @Subscribe + public void onFollowRequestTaskEvent(FollowRequestTaskEvent event) { + final ParcelableUsersAdapter adapter = getAdapter(); + final int position = adapter.findPosition(event.getAccountId(), event.getUserId()); + if (event.isFinished() && event.isSucceeded()) { + adapter.removeUserAt(position); + } else { + adapter.notifyItemChanged(position); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java index fde35c65d..f00c8366c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java @@ -107,7 +107,7 @@ import org.mariotaku.twidere.util.ReadStateManager; import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.TaskStateChangedEvent; +import org.mariotaku.twidere.model.message.TaskStateChangedEvent; import org.mariotaku.twidere.view.ComposeEditText; import java.util.ArrayList; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java index ec5cffd99..bdc6cebf4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java @@ -30,11 +30,11 @@ import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.model.ParcelableStatus; -import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; -import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; -import org.mariotaku.twidere.util.message.StatusRetweetedEvent; +import org.mariotaku.twidere.model.message.FavoriteCreatedEvent; +import org.mariotaku.twidere.model.message.FavoriteDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusRetweetedEvent; import java.util.HashSet; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUsersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUsersFragment.java index 4a271c7c4..58cea4c30 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUsersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUsersFragment.java @@ -25,7 +25,6 @@ import android.support.annotation.NonNull; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; -import org.mariotaku.twidere.adapter.AbsUsersAdapter; import org.mariotaku.twidere.adapter.ParcelableUsersAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.model.ParcelableUser; @@ -42,10 +41,16 @@ public abstract class ParcelableUsersFragment extends AbsUsersFragment> onCreateAdapter(Context context, boolean compact) { + protected ParcelableUsersAdapter onCreateAdapter(Context context, boolean compact) { return new ParcelableUsersAdapter(context); } + @NonNull + @Override + public ParcelableUsersAdapter getAdapter() { + return (ParcelableUsersAdapter) super.getAdapter(); + } + protected long getAccountId() { final Bundle args = getArguments(); return args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index 8248fcf60..b96a56bb9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -140,9 +140,9 @@ import org.mariotaku.twidere.util.TwitterCardUtils; import org.mariotaku.twidere.util.TwitterContentUtils; import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; -import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; -import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.FavoriteCreatedEvent; +import org.mariotaku.twidere.model.message.FavoriteDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.view.CardMediaContainer; import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener; import org.mariotaku.twidere.view.ColorLabelRelativeLayout; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java index bcb1f6b01..165f43d9d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java @@ -36,7 +36,7 @@ import com.squareup.otto.Subscribe; import org.mariotaku.twidere.adapter.TrendsAdapter; import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends; import org.mariotaku.twidere.util.AsyncTwitterWrapper; -import org.mariotaku.twidere.util.message.TaskStateChangedEvent; +import org.mariotaku.twidere.model.message.TaskStateChangedEvent; import static org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri; import static org.mariotaku.twidere.util.Utils.getDefaultAccountId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index 8b3ec4288..7943cb325 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -135,10 +135,10 @@ import org.mariotaku.twidere.util.TwitterAPIFactory; import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.menu.TwidereMenuInfo; -import org.mariotaku.twidere.util.message.FriendshipUpdatedEvent; -import org.mariotaku.twidere.util.message.FriendshipUserUpdatedEvent; -import org.mariotaku.twidere.util.message.ProfileUpdatedEvent; -import org.mariotaku.twidere.util.message.TaskStateChangedEvent; +import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent; +import org.mariotaku.twidere.model.message.FriendshipUserUpdatedEvent; +import org.mariotaku.twidere.model.message.ProfileUpdatedEvent; +import org.mariotaku.twidere.model.message.TaskStateChangedEvent; import org.mariotaku.twidere.util.support.ActivitySupport; import org.mariotaku.twidere.util.support.ActivitySupport.TaskDescriptionCompat; import org.mariotaku.twidere.util.support.ViewSupport; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java index e50d88503..7e42cda53 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java @@ -35,7 +35,7 @@ import org.mariotaku.twidere.loader.support.UserListsLoader; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.util.MenuUtils; import org.mariotaku.twidere.util.Utils; -import org.mariotaku.twidere.util.message.UserListDestroyedEvent; +import org.mariotaku.twidere.model.message.UserListDestroyedEvent; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/AccountChangedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/AccountChangedEvent.java index d4205f816..c4ace6de5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/AccountChangedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; /** * Created by mariotaku on 15/4/24. diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteCreatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteCreatedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteCreatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteCreatedEvent.java index 3801a24bf..cbd78e4da 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteCreatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteCreatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteDestroyedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteDestroyedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteDestroyedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteDestroyedEvent.java index fadf12650..03dc81664 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/FavoriteDestroyedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteDestroyedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java new file mode 100644 index 000000000..6eee7a3c3 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java @@ -0,0 +1,67 @@ +package org.mariotaku.twidere.model.message; + +import android.support.annotation.IntDef; + +/** + * Created by mariotaku on 16/2/15. + */ +public class FollowRequestTaskEvent { + + @Action + private int action; + private boolean finished; + private boolean succeeded; + private long accountId; + private long userId; + + public FollowRequestTaskEvent(@Action int action, long accountId, long userId) { + this.action = action; + this.accountId = accountId; + this.userId = userId; + } + + @Action + public int getAction() { + return action; + } + + public boolean isFinished() { + return finished; + } + + public void setFinished(boolean finished) { + this.finished = finished; + } + + public long getAccountId() { + return accountId; + } + + public long getUserId() { + return userId; + } + + public boolean isSucceeded() { + return succeeded; + } + + public void setSucceeded(boolean succeeded) { + this.succeeded = succeeded; + } + + @Override + public String toString() { + return "FollowRequestTaskEvent{" + + "action=" + action + + ", finished=" + finished + + ", accountId=" + accountId + + ", userId=" + userId + + '}'; + } + + @IntDef({Action.ACCEPT, Action.DENY}) + public @interface Action { + int ACCEPT = 1; + int DENY = 2; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java index f9cfbadce..7e3661f42 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUserUpdatedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUserUpdatedEvent.java index 8415eff5e..7d0f8023c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUserUpdatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetActivitiesTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetActivitiesTaskEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/GetActivitiesTaskEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/GetActivitiesTaskEvent.java index f7ce6a046..14b44a272 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetActivitiesTaskEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetActivitiesTaskEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.net.Uri; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetMessagesTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetMessagesTaskEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/GetMessagesTaskEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/GetMessagesTaskEvent.java index 4d8826830..6e0b7f108 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetMessagesTaskEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetMessagesTaskEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.net.Uri; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetStatusesTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetStatusesTaskEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/GetStatusesTaskEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/GetStatusesTaskEvent.java index e1c94973a..51b229d9e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/GetStatusesTaskEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/GetStatusesTaskEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.net.Uri; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/ProfileUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/ProfileUpdatedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/ProfileUpdatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/ProfileUpdatedEvent.java index 67ec37ac8..10bc51755 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/ProfileUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/ProfileUpdatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusDestroyedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusDestroyedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/StatusDestroyedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/StatusDestroyedEvent.java index dfea51e54..e20afa119 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusDestroyedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusDestroyedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import org.mariotaku.twidere.model.ParcelableStatus; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusItemChangedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusItemChangedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/StatusItemChangedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/StatusItemChangedEvent.java index abdda0f4c..b9880345f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusItemChangedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusItemChangedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import org.mariotaku.twidere.model.ParcelableStatus; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusListChangedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusListChangedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/StatusListChangedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/StatusListChangedEvent.java index 136f8c452..ba808b89d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusListChangedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusListChangedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; /** * Created by mariotaku on 14/12/12. diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusRetweetedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusRetweetedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/StatusRetweetedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/StatusRetweetedEvent.java index 33d82592c..142f2e90b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/StatusRetweetedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/StatusRetweetedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import org.mariotaku.twidere.model.ParcelableStatus; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/TaskStateChangedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/TaskStateChangedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/TaskStateChangedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/TaskStateChangedEvent.java index c51c5865d..25965336f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/TaskStateChangedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/TaskStateChangedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; /** * Created by mariotaku on 14/12/7. diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/UnreadCountUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/UnreadCountUpdatedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/UnreadCountUpdatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/UnreadCountUpdatedEvent.java index 93263418f..f9277f385 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/UnreadCountUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/UnreadCountUpdatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; /** * Created by mariotaku on 14/12/7. diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/UserListCreatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/UserListCreatedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/UserListCreatedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/UserListCreatedEvent.java index 8a769fb8b..2c57c53f6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/UserListCreatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/UserListCreatedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/UserListDestroyedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/UserListDestroyedEvent.java similarity index 96% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/UserListDestroyedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/UserListDestroyedEvent.java index f28feeebc..726a24561 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/UserListDestroyedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/UserListDestroyedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/VideoLoadFinishedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/VideoLoadFinishedEvent.java similarity index 95% rename from twidere/src/main/java/org/mariotaku/twidere/util/message/VideoLoadFinishedEvent.java rename to twidere/src/main/java/org/mariotaku/twidere/model/message/VideoLoadFinishedEvent.java index 1fbe620be..d75340129 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/VideoLoadFinishedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/VideoLoadFinishedEvent.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.util.message; +package org.mariotaku.twidere.model.message; /** * Created by mariotaku on 15/3/23. diff --git a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java index 442ac3b33..c1ba275c4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java @@ -127,7 +127,7 @@ import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.collection.CompactHashSet; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent; +import org.mariotaku.twidere.model.message.UnreadCountUpdatedEvent; import org.mariotaku.twidere.util.net.TwidereDns; import org.oshkimaadziig.george.androidutils.SpanFormatter; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java index 89c123c3a..90508f48b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java @@ -28,7 +28,7 @@ import org.mariotaku.twidere.util.UriUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.GetMessagesTaskEvent; +import org.mariotaku.twidere.model.message.GetMessagesTaskEvent; import java.util.ArrayList; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/ManagedAsyncTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/ManagedAsyncTask.java index 48e97f002..2bc788fd0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/ManagedAsyncTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/ManagedAsyncTask.java @@ -26,8 +26,11 @@ import com.squareup.otto.Bus; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.util.AsyncTaskManager; +import org.mariotaku.twidere.util.AsyncTwitterWrapper; +import org.mariotaku.twidere.util.SharedPreferencesWrapper; +import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.TaskStateChangedEvent; +import org.mariotaku.twidere.model.message.TaskStateChangedEvent; import javax.inject.Inject; @@ -38,6 +41,12 @@ public abstract class ManagedAsyncTask extends AsyncTa protected AsyncTaskManager manager; @Inject protected Bus bus; + @Inject + protected UserColorNameManager mUserColorNameManager; + @Inject + protected SharedPreferencesWrapper mPreferences; + @Inject + protected AsyncTwitterWrapper mAsyncTwitterWrapper; private final Context context; private final String tag; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java index 92b21b9e6..52bd135aa 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java @@ -34,7 +34,7 @@ import org.mariotaku.twidere.util.TwitterAPIFactory; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.GetActivitiesTaskEvent; +import org.mariotaku.twidere.model.message.GetActivitiesTaskEvent; import java.util.ArrayList; import java.util.Arrays; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java index 0d52b9032..2d74c9b1c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java @@ -40,7 +40,7 @@ import org.mariotaku.twidere.util.UriUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; -import org.mariotaku.twidere.util.message.GetStatusesTaskEvent; +import org.mariotaku.twidere.model.message.GetStatusesTaskEvent; import java.util.ArrayList; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java index 1a1107fff..12f63acc9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java @@ -36,7 +36,9 @@ import com.desmond.asyncmanager.BackgroundTask; import com.desmond.asyncmanager.TaskRunnable; import com.squareup.otto.Bus; +import org.apache.commons.collections.primitives.ArrayIntList; import org.apache.commons.collections.primitives.ArrayLongList; +import org.apache.commons.collections.primitives.IntList; import org.apache.commons.collections.primitives.LongList; import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.twidere.BuildConfig; @@ -66,6 +68,17 @@ import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.Response; import org.mariotaku.twidere.model.SingleResponse; +import org.mariotaku.twidere.model.message.FavoriteCreatedEvent; +import org.mariotaku.twidere.model.message.FavoriteDestroyedEvent; +import org.mariotaku.twidere.model.message.FollowRequestTaskEvent; +import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent; +import org.mariotaku.twidere.model.message.FriendshipUserUpdatedEvent; +import org.mariotaku.twidere.model.message.ProfileUpdatedEvent; +import org.mariotaku.twidere.model.message.StatusDestroyedEvent; +import org.mariotaku.twidere.model.message.StatusListChangedEvent; +import org.mariotaku.twidere.model.message.StatusRetweetedEvent; +import org.mariotaku.twidere.model.message.UserListCreatedEvent; +import org.mariotaku.twidere.model.message.UserListDestroyedEvent; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -87,16 +100,6 @@ import org.mariotaku.twidere.task.ManagedAsyncTask; import org.mariotaku.twidere.task.twitter.GetActivitiesTask; import org.mariotaku.twidere.util.collection.LongSparseMap; import org.mariotaku.twidere.util.content.ContentResolverUtils; -import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; -import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; -import org.mariotaku.twidere.util.message.FriendshipUpdatedEvent; -import org.mariotaku.twidere.util.message.FriendshipUserUpdatedEvent; -import org.mariotaku.twidere.util.message.ProfileUpdatedEvent; -import org.mariotaku.twidere.util.message.StatusDestroyedEvent; -import org.mariotaku.twidere.util.message.StatusListChangedEvent; -import org.mariotaku.twidere.util.message.StatusRetweetedEvent; -import org.mariotaku.twidere.util.message.UserListCreatedEvent; -import org.mariotaku.twidere.util.message.UserListDestroyedEvent; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -123,6 +126,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { private LongSparseMap mDestroyingFavoriteIds = new LongSparseMap<>(); private LongSparseMap mCreatingRetweetIds = new LongSparseMap<>(); private LongSparseMap mDestroyingStatusIds = new LongSparseMap<>(); + private IntList mProcessingFriendshipRequestIds = new ArrayIntList(); private final LongList mSendingDraftIds = new ArrayLongList(); @@ -139,7 +143,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } public int acceptFriendshipAsync(final long accountId, final long userId) { - final AcceptFriendshipTask task = new AcceptFriendshipTask(accountId, userId); + final AcceptFriendshipTask task = new AcceptFriendshipTask(mContext, accountId, userId); return mAsyncTaskManager.add(task, true); } @@ -584,6 +588,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return mErrorInfoStore; } + private void addProcessingFriendshipRequestId(long accountId, long userId) { + mProcessingFriendshipRequestIds.add(ParcelableUser.calculateHashCode(accountId, userId)); + } + + private void removeProcessingFriendshipRequestId(long accountId, long userId) { + mProcessingFriendshipRequestIds.removeElement(ParcelableUser.calculateHashCode(accountId, userId)); + } + + public boolean isProcessingFollowRequest(long accountId, long userId) { + return mProcessingFriendshipRequestIds.contains(ParcelableUser.calculateHashCode(accountId, userId)); + } + public static class UpdateProfileBannerImageTask extends ManagedAsyncTask> { private final long mAccountId; @@ -684,15 +700,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } - class AcceptFriendshipTask extends ManagedAsyncTask> { + static class AcceptFriendshipTask extends ManagedAsyncTask> { private final long mAccountId; private final long mUserId; - public AcceptFriendshipTask(final long account_id, final long user_id) { - super(mContext); - mAccountId = account_id; - mUserId = user_id; + public AcceptFriendshipTask(final Context context, final long accountId, final long userId) { + super(context); + mAccountId = accountId; + mUserId = userId; } public long getAccountId() { @@ -703,10 +719,21 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return mUserId; } + @Override + protected void onPreExecute() { + final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, + mAccountId, mUserId); + event.setFinished(false); + bus.post(event); + mAsyncTwitterWrapper.addProcessingFriendshipRequestId(mAccountId, mUserId); + super.onPreExecute(); + } + + @Override protected SingleResponse doInBackground(final Object... params) { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountId, false); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, false); if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.acceptFriendship(mUserId); @@ -718,19 +745,23 @@ public class AsyncTwitterWrapper extends TwitterWrapper { @Override protected void onPostExecute(final SingleResponse result) { + final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, + mAccountId, mUserId); + event.setFinished(true); if (result.hasData()) { final User user = result.getData(); final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); - final String message = mContext.getString(R.string.accepted_users_follow_request, + final String message = getContext().getString(R.string.accepted_users_follow_request, mUserColorNameManager.getDisplayName(user, nameFirst, true)); - Utils.showOkMessage(mContext, message, false); + Utils.showOkMessage(getContext(), message, false); + event.setSucceeded(true); } else { - Utils.showErrorMessage(mContext, R.string.action_accepting_follow_request, + Utils.showErrorMessage(getContext(), R.string.action_accepting_follow_request, result.getException(), false); + event.setSucceeded(false); } - final Intent intent = new Intent(BROADCAST_FRIENDSHIP_ACCEPTED); - intent.putExtra(EXTRA_USER_ID, mUserId); - mContext.sendBroadcast(intent); + mAsyncTwitterWrapper.removeProcessingFriendshipRequestId(mAccountId, mUserId); + bus.post(event); super.onPostExecute(result); } @@ -1311,10 +1342,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { private final long mAccountId; private final long mUserId; - public DenyFriendshipTask(final long account_id, final long user_id) { + public DenyFriendshipTask(final long accountId, final long userId) { super(mContext); - mAccountId = account_id; - mUserId = user_id; + mAccountId = accountId; + mUserId = userId; } public long getAccountId() { @@ -1338,21 +1369,35 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } } + @Override + protected void onPreExecute() { + addProcessingFriendshipRequestId(mAccountId, mUserId); + final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, + mAccountId, mUserId); + event.setFinished(false); + bus.post(event); + super.onPreExecute(); + } + @Override protected void onPostExecute(final SingleResponse result) { + final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, + mAccountId, mUserId); + event.setFinished(true); if (result.hasData()) { final User user = result.getData(); final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); final String message = mContext.getString(R.string.denied_users_follow_request, mUserColorNameManager.getDisplayName(user, nameFirst, true)); Utils.showOkMessage(mContext, message, false); + event.setSucceeded(true); } else { Utils.showErrorMessage(mContext, R.string.action_denying_follow_request, result.getException(), false); + event.setSucceeded(false); } - final Intent intent = new Intent(BROADCAST_FRIENDSHIP_DENIED); - intent.putExtra(EXTRA_USER_ID, mUserId); - mContext.sendBroadcast(intent); super.onPostExecute(result); + removeProcessingFriendshipRequestId(mAccountId, mUserId); + bus.post(event); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/NameView.java b/twidere/src/main/java/org/mariotaku/twidere/view/NameView.java index 0aa68607c..82c9282c8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/NameView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/NameView.java @@ -64,12 +64,7 @@ public class NameView extends ThemedTextView { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NameView, defStyleAttr, 0); setPrimaryTextColor(a.getColor(R.styleable.NameView_nv_primaryTextColor, 0)); setSecondaryTextColor(a.getColor(R.styleable.NameView_nv_secondaryTextColor, 0)); - if (mTwoLine = a.getBoolean(R.styleable.NameView_nv_twoLine, false)) { - setSingleLine(false); - setMaxLines(2); - } else { - setSingleLine(true); - } + setTwoLine(a.getBoolean(R.styleable.NameView_nv_twoLine, false)); mPrimaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_primaryTextStyle, 0)); mSecondaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_secondaryTextStyle, 0)); a.recycle(); @@ -156,4 +151,13 @@ public class NameView extends ThemedTextView { mSecondaryTextSize = new AbsoluteSizeSpan((int) calculateTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)); } + public void setTwoLine(boolean twoLine) { + mTwoLine = twoLine; + if (twoLine) { + setSingleLine(false); + setMaxLines(2); + } else { + setSingleLine(true); + } + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java index 11eaa8ec7..118d71f2e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java @@ -28,9 +28,11 @@ import android.widget.ImageView; import android.widget.TextView; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.adapter.iface.ContentCardClickListener; import org.mariotaku.twidere.adapter.iface.IUsersAdapter; +import org.mariotaku.twidere.adapter.iface.IUsersAdapter.RequestClickListener; +import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserAdapterListener; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.view.NameView; @@ -52,7 +54,12 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon private final TextView descriptionView, locationView, urlView, statusesCountView, followersCountView, friendsCountView; - private UserClickListener userClickListener; + private final View acceptRequestButton, denyRequestButton; + private final View followRequestContainer; + private final View processingRequestProgress; + + private UserAdapterListener userClickListener; + private RequestClickListener requestClickListener; public UserViewHolder(final IUsersAdapter adapter, final View itemView) { super(itemView); @@ -67,12 +74,17 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon statusesCountView = (TextView) itemView.findViewById(R.id.statuses_count); followersCountView = (TextView) itemView.findViewById(R.id.followers_count); friendsCountView = (TextView) itemView.findViewById(R.id.friends_count); + followRequestContainer = itemView.findViewById(R.id.follow_request_container); + acceptRequestButton = itemView.findViewById(R.id.accept_request); + denyRequestButton = itemView.findViewById(R.id.deny_request); + processingRequestProgress = itemView.findViewById(R.id.processing_request); } public void displayUser(ParcelableUser user) { final MediaLoaderWrapper loader = adapter.getMediaLoader(); final UserColorNameManager manager = adapter.getUserColorNameManager(); + final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper(); itemContent.drawStart(manager.getUserColor(user.id, false)); @@ -103,6 +115,16 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon profileImageView.setVisibility(View.GONE); loader.cancelDisplayTask(profileImageView); } + + if (twitter.isProcessingFollowRequest(user.account_id, user.id)) { + processingRequestProgress.setVisibility(View.VISIBLE); + acceptRequestButton.setVisibility(View.GONE); + denyRequestButton.setVisibility(View.GONE); + } else { + processingRequestProgress.setVisibility(View.GONE); + acceptRequestButton.setVisibility(View.VISIBLE); + denyRequestButton.setVisibility(View.VISIBLE); + } } public ImageView getProfileImageView() { @@ -115,12 +137,22 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon @Override public void onClick(View v) { - if (userClickListener == null) return; switch (v.getId()) { case R.id.item_content: { + if (userClickListener == null) return; userClickListener.onUserClick(this, getLayoutPosition()); break; } + case R.id.accept_request: { + if (requestClickListener == null) return; + requestClickListener.onAcceptClicked(this, getLayoutPosition()); + break; + } + case R.id.deny_request: { + if (requestClickListener == null) return; + requestClickListener.onDenyClicked(this, getLayoutPosition()); + break; + } } } @@ -136,7 +168,22 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon } public void setOnClickListeners() { - setUserClickListener(adapter); + setUserClickListener(adapter.getUserAdapterListener()); + setRequestClickListener(adapter.getRequestClickListener()); + } + + private void setRequestClickListener(RequestClickListener listener) { + requestClickListener = listener; + if (listener != null) { + nameView.setTwoLine(true); + followRequestContainer.setVisibility(View.VISIBLE); + } else { + nameView.setTwoLine(false); + followRequestContainer.setVisibility(View.GONE); + } + nameView.updateText(); + acceptRequestButton.setOnClickListener(this); + denyRequestButton.setOnClickListener(this); } public void setTextSize(final float textSize) { @@ -150,7 +197,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon friendsCountView.setTextSize(textSize); } - public void setUserClickListener(UserClickListener listener) { + public void setUserClickListener(UserAdapterListener listener) { userClickListener = listener; ((View) itemContent).setOnClickListener(this); ((View) itemContent).setOnLongClickListener(this); @@ -160,11 +207,4 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon setTextSize(adapter.getTextSize()); } - public interface UserClickListener extends ContentCardClickListener { - - void onUserClick(UserViewHolder holder, int position); - - boolean onUserLongClick(UserViewHolder holder, int position); - - } } diff --git a/twidere/src/main/res/layout/activity_sign_in.xml b/twidere/src/main/res/layout/activity_sign_in.xml index e50369035..5654adf56 100644 --- a/twidere/src/main/res/layout/activity_sign_in.xml +++ b/twidere/src/main/res/layout/activity_sign_in.xml @@ -17,10 +17,10 @@ ~ along with this program. If not, see . --> @@ -57,7 +57,7 @@ android:hint="@string/username" android:inputType="textEmailAddress" android:singleLine="true" - android:typeface="normal" /> + android:typeface="normal"/> + android:typeface="normal"/> + android:text="@string/register"/> -