From 1a2914f86e5f476749013c3e9c9fdfc2420b2158 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 7 Mar 2016 09:00:28 +0800 Subject: [PATCH] migrating account --- twidere.component.common/build.gradle | 4 +- twidere/build.gradle | 4 +- .../tsinghua/hotmobi/model/TweetEvent.java | 25 +++++-- .../activity/support/HomeActivity.java | 2 +- .../activity/support/MediaViewerActivity.java | 4 +- .../support/QuickSearchBarActivity.java | 22 +++--- .../twidere/adapter/AbsActivitiesAdapter.java | 6 +- .../twidere/adapter/DraftsAdapter.java | 2 +- .../adapter/MessageConversationAdapter.java | 3 +- .../adapter/ParcelableUsersAdapter.java | 7 +- ...taggeredGridParcelableStatusesAdapter.java | 6 +- .../fragment/support/AbsStatusesFragment.java | 5 +- .../fragment/support/AbsUsersFragment.java | 5 +- .../support/AccountsDashboardFragment.java | 5 +- .../support/AccountsManagerFragment.java | 6 +- .../support/CursorStatusesFragment.java | 10 +++ .../support/DirectMessagesFragment.java | 4 +- .../support/HomeTimelineFragment.java | 10 +-- .../support/IncomingFriendshipsFragment.java | 13 ++-- .../support/InteractionsTimelineFragment.java | 5 +- .../support/MessagesConversationFragment.java | 41 ++++++----- .../support/MutesUsersListFragment.java | 5 +- .../fragment/support/StatusFragment.java | 42 ++++++----- .../support/UserFollowersFragment.java | 6 +- .../fragment/support/UserFragment.java | 10 +-- .../fragment/support/UserListFragment.java | 5 +- .../loader/support/ConversationLoader.java | 4 +- .../loader/support/MutesUsersLoader.java | 5 +- .../support/ParcelableStatusLoader.java | 8 ++- .../loader/support/ParcelableUserLoader.java | 14 ++-- .../loader/support/RetweetsOfMeLoader.java | 6 +- .../loader/support/SavedSearchesLoader.java | 10 +-- .../support/ScheduledStatusesLoader.java | 8 ++- .../loader/support/UserSearchLoader.java | 7 +- .../twidere/model/BaseRefreshTaskParam.java | 16 ++++- .../twidere/model/RefreshTaskParam.java | 4 ++ .../twidere/model/SimpleRefreshTaskParam.java | 10 +++ .../util/ParcelableDirectMessageUtils.java | 8 ++- .../model/util/ParcelableMediaUtils.java | 4 +- .../service/BackgroundOperationService.java | 40 ++++++----- .../twidere/service/StreamingService.java | 26 +++---- .../twidere/task/CacheUsersStatusesTask.java | 3 +- .../twidere/task/GetSavedSearchesTask.java | 3 +- .../twidere/task/twitter/GetStatusesTask.java | 21 +++--- .../twidere/text/TwidereURLSpan.java | 9 +-- .../twidere/util/ContentValuesCreator.java | 5 +- .../twidere/util/DataStoreUtils.java | 7 +- .../mariotaku/twidere/util/IntentUtils.java | 8 +-- .../mariotaku/twidere/util/LinkCreator.java | 14 ++-- .../twidere/util/MediaLoaderWrapper.java | 8 ++- .../twidere/util/OnLinkClickHandler.java | 23 +++--- .../twidere/util/StatusLinkClickHandler.java | 4 +- .../twidere/util/TwidereLinkify.java | 70 ++++++++++--------- .../org/mariotaku/twidere/util/Utils.java | 28 ++++---- .../twidere/util/media/MediaExtra.java | 12 ++-- .../util/media/TwidereMediaDownloader.java | 2 +- .../twidere/view/CardMediaContainer.java | 15 ++-- .../view/holder/iface/IStatusViewHolder.java | 3 +- 58 files changed, 399 insertions(+), 263 deletions(-) diff --git a/twidere.component.common/build.gradle b/twidere.component.common/build.gradle index 0cec10085..d9a1ec0fc 100644 --- a/twidere.component.common/build.gradle +++ b/twidere.component.common/build.gradle @@ -38,11 +38,11 @@ android { dependencies { apt 'com.bluelinelabs:logansquare-compiler:1.3.4' apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2' - apt 'com.github.mariotaku.ObjectCursor:processor:0.9.6-SNAPSHOT' + apt 'com.github.mariotaku.ObjectCursor:processor:0.9.6' compile 'com.android.support:support-annotations:23.2.0' compile 'com.bluelinelabs:logansquare:1.3.4' compile 'com.github.mariotaku.RestFu:library:0.9.24' compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2' - compile 'com.github.mariotaku.ObjectCursor:core:0.9.6-SNAPSHOT' + compile 'com.github.mariotaku.ObjectCursor:core:0.9.6' compile fileTree(dir: 'libs', include: ['*.jar']) } diff --git a/twidere/build.gradle b/twidere/build.gradle index ccacd4d51..549070970 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -78,7 +78,7 @@ dependencies { androidTestApt 'com.bluelinelabs:logansquare-compiler:1.3.4' apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2' apt 'com.google.dagger:dagger-compiler:2.0.2' - apt "com.github.mariotaku.ObjectCursor:processor:0.9.6-SNAPSHOT" + apt "com.github.mariotaku.ObjectCursor:processor:0.9.6" compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:support-v13:23.2.0' @@ -117,7 +117,7 @@ dependencies { compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.12' compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.12' compile 'com.github.mariotaku.SQLiteQB:library:0.9.5' - compile 'com.github.mariotaku.ObjectCursor:core:0.9.6-SNAPSHOT' + compile 'com.github.mariotaku.ObjectCursor:core:0.9.6' compile project(':twidere.component.common') compile project(':twidere.component.nyan') diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java index cab6dc1fd..3ddabe82d 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java @@ -47,6 +47,9 @@ public class TweetEvent extends BaseEvent implements Parcelable { @JsonField(name = "account_id") long accountId; @ParcelableThisPlease + @JsonField(name = "account_host") + String accountHost; + @ParcelableThisPlease @JsonField(name = "user_id") long userId; @ParcelableThisPlease @@ -81,6 +84,7 @@ public class TweetEvent extends BaseEvent implements Parcelable { event.markStart(context); event.setId(status.id); event.setAccountId(status.account_id); + event.setAccountHost(status.account_host); event.setUserId(status.user_id); event.setTimelineType(timelineType); event.setTweetType(TwidereDataUtils.getTweetType(status)); @@ -116,19 +120,28 @@ public class TweetEvent extends BaseEvent implements Parcelable { return accountId; } - public void setAccountId(long accountId) { - this.accountId = accountId; + public void setAccountId(long accountKey) { + this.accountId = accountKey; + } + + public String getAccountHost() { + return accountHost; + } + + public void setAccountHost(String accountHost) { + this.accountHost = accountHost; } @Override public String toString() { return "TweetEvent{" + "id=" + id + - ", mAccountKey=" + accountId + + ", accountKey=" + accountId + ", userId=" + userId + - ", tweetType=" + tweetType + - ", timelineType=" + timelineType + - ", action=" + action + + ", tweetType='" + tweetType + '\'' + + ", timelineType='" + timelineType + '\'' + + ", action='" + action + '\'' + + ", following=" + following + "} " + super.toString(); } 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 016c8a74d..3d1f9dc73 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 @@ -819,7 +819,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen if (mPagerAdapter.getCount() == 0) return; final SupportTabSpec tab = mPagerAdapter.getTab(position); if (DirectMessagesFragment.class == tab.cls) { - Utils.openMessageConversation(this, -1, -1); + Utils.openMessageConversation(this, null, -1); } else if (TrendsSuggestionsFragment.class == tab.cls) { openSearchView(null); } else { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java index 9c7c98611..cce091cf9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java @@ -30,6 +30,7 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.os.Parcelable; import android.support.annotation.CallSuper; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; @@ -81,6 +82,7 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IExtendedActivity; import org.mariotaku.twidere.fragment.ProgressDialogFragment; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.provider.CacheProvider; @@ -824,7 +826,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements @Override protected Object getDownloadExtra() { final MediaExtra mediaExtra = new MediaExtra(); - mediaExtra.setAccountId(getArguments().getLong(EXTRA_ACCOUNT_ID, -1)); + mediaExtra.setAccountKey(getArguments().getParcelable(EXTRA_ACCOUNT_KEY)); final Uri origDownloadUri = super.getDownloadUri(); final Uri downloadUri = getDownloadUri(); if (origDownloadUri != null && downloadUri != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java index 922b7b095..7bb0a1df2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java @@ -56,6 +56,8 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter; import org.mariotaku.twidere.fragment.support.UserFragment; +import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory; import org.mariotaku.twidere.provider.TwidereDataStore.Suggestions; @@ -142,10 +144,12 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On @Override public Loader onCreateLoader(int id, Bundle args) { - final long accountId = getAccountId(); + final AccountKey accountId = getSelectedAccountKey(); final Uri.Builder builder = Suggestions.Search.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_QUERY, ParseUtils.parseString(mSearchQuery.getText())); - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, ParseUtils.parseString(accountId)); + if (accountId != null) { + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountId.toString()); + } return new CursorLoader(this, builder.build(), Suggestions.Search.COLUMNS, null, null, null); } @@ -170,20 +174,20 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On final SuggestionItem item = mUsersSearchAdapter.getSuggestionItem(position); switch (mUsersSearchAdapter.getItemViewType(position)) { case SuggestionsAdapter.VIEW_TYPE_USER_SUGGESTION_ITEM: { - IntentUtils.openUserProfile(this, getAccountId(), item.extra_id, item.summary, null, + IntentUtils.openUserProfile(this, getSelectedAccountKey(), item.extra_id, item.summary, null, true, UserFragment.Referral.DIRECT); finish(); break; } case SuggestionsAdapter.VIEW_TYPE_USER_SCREEN_NAME: { - IntentUtils.openUserProfile(this, getAccountId(), -1, item.title, null, true, + IntentUtils.openUserProfile(this, getSelectedAccountKey(), -1, item.title, null, true, UserFragment.Referral.DIRECT); finish(); break; } case SuggestionsAdapter.VIEW_TYPE_SAVED_SEARCH: case SuggestionsAdapter.VIEW_TYPE_SEARCH_HISTORY: { - Utils.openSearch(this, getAccountId(), item.title); + Utils.openSearch(this, getSelectedAccountKey(), item.title); finish(); break; } @@ -284,13 +288,13 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On if (isFinishing()) return; final String query = ParseUtils.parseString(mSearchQuery.getText()); if (TextUtils.isEmpty(query)) return; - final long accountId = mAccountSpinner.getSelectedItemId(); - Utils.openSearch(this, accountId, query); + Utils.openSearch(this, getSelectedAccountKey(), query); finish(); } - private long getAccountId() { - return mAccountSpinner.getSelectedItemId(); + private AccountKey getSelectedAccountKey() { + final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem(); + return new AccountKey(account.account_id, account.account_host); } private void updateWindowAttributes() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java index d86ac583b..eff053259 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java @@ -36,6 +36,7 @@ import org.mariotaku.twidere.adapter.iface.IActivitiesAdapter; import org.mariotaku.twidere.api.twitter.model.Activity; import org.mariotaku.twidere.fragment.support.CursorActivitiesFragment; import org.mariotaku.twidere.fragment.support.UserFragment; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; @@ -438,8 +439,9 @@ public abstract class AbsActivitiesAdapter extends LoadMoreSupportAdapter< final ParcelableActivity activity = adapter.getActivity(position); final ParcelableStatus status = ParcelableActivity.getActivityStatus(activity); assert status != null; - IntentUtils.openUserProfile(context, status.account_id, status.user_id, - status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); + IntentUtils.openUserProfile(context, new AccountKey(status.account_id, + status.account_host), status.user_id, status.user_screen_name, null, true, + UserFragment.Referral.TIMELINE_STATUS); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/DraftsAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/DraftsAdapter.java index 4fec45f3b..867a87edf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/DraftsAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/DraftsAdapter.java @@ -87,7 +87,7 @@ public class DraftsAdapter extends SimpleCursorAdapter implements Constants { case Draft.Action.QUOTE: { final ParcelableMedia[] media = ParcelableMediaUtils.fromMediaUpdates(mediaUpdates); holder.media_preview_container.setVisibility(View.VISIBLE); - holder.media_preview_container.displayMedia(media, mImageLoader, -1, -1, null, + holder.media_preview_container.displayMedia(media, mImageLoader, null, -1, null, mMediaLoadingHandler); break; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java index 9051d56d8..07e666bc7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java @@ -29,6 +29,7 @@ import android.view.ViewGroup; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IDirectMessagesAdapter; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices; import org.mariotaku.twidere.model.ParcelableMedia; @@ -205,7 +206,7 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter return true; } - public int findPosition(long accountId, long userId) { + public int findPosition(AccountKey accountKey, long userId) { + return findPosition(accountKey.getId(), accountKey.getHost(), userId); + } + + public int findPosition(long accountId, String accountHost, 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); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java index 4ea143431..2bd81bb80 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java @@ -33,6 +33,7 @@ import com.commonsware.cwac.layouts.AspectLockedFrameLayout; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; @@ -100,7 +101,8 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse mediaImageView.setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(firstMedia.type)); loader.displayProfileImage(mediaProfileImageView, status.user_profile_image_url); loader.displayPreviewImageWithCredentials(mediaImageView, firstMedia.preview_url, - status.account_id, adapter.getMediaLoadingHandler()); + new AccountKey(status.account_id, status.account_host), + adapter.getMediaLoadingHandler()); } @Override @@ -136,7 +138,7 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse } @Override - public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) { + public void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long extraId) { } @Override 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 9aaadb4df..950a4984a 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 @@ -406,8 +406,9 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi @Override public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) { final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, status.account_id, status.user_id, - status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); + IntentUtils.openUserProfile(activity, new AccountKey(status.account_id, status.account_host), + status.user_id, status.user_screen_name, null, true, + UserFragment.Referral.TIMELINE_STATUS); } @Override 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 390dfa6d0..9a24bfe5f 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 @@ -34,6 +34,7 @@ import org.mariotaku.twidere.adapter.AbsUsersAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserAdapterListener; import org.mariotaku.twidere.loader.iface.IExtendedLoader; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.util.IntentUtils; import org.mariotaku.twidere.util.KeyboardShortcutsHandler; @@ -112,8 +113,8 @@ abstract class AbsUsersFragment extends AbsContentListRecyclerViewFragment public void onUserClick(UserViewHolder holder, int position) { final ParcelableUser user = getAdapter().getUser(position); final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, user.account_id, user.id, user.screen_name, null, - true, getUserReferral()); + IntentUtils.openUserProfile(activity, new AccountKey(user.account_id, user.account_host), + user.id, user.screen_name, null, true, getUserReferral()); } @UserFragment.Referral diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java index c13e93223..d21c89092 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java @@ -248,8 +248,9 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final ParcelableAccount account = mAccountsAdapter.getSelectedAccount(); if (account == null) return; final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, account.account_id, account.account_id, - account.screen_name, null, true, UserFragment.Referral.SELF_PROFILE); + IntentUtils.openUserProfile(activity, new AccountKey(account.account_id, + account.account_host), account.account_id, account.screen_name, null, true, + UserFragment.Referral.SELF_PROFILE); break; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java index fd06a694d..c11a3a6d7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java @@ -44,6 +44,7 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.support.ColorPickerDialogActivity; import org.mariotaku.twidere.activity.support.SignInActivity; import org.mariotaku.twidere.adapter.AccountsAdapter; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; @@ -148,8 +149,9 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load @Override public void onItemClick(AdapterView parent, View view, int position, long id) { final ParcelableAccount account = mAdapter.getAccount(position); - IntentUtils.openUserProfile(getActivity(), account.account_id, account.account_id, account.screen_name, - null, true, UserFragment.Referral.SELF_PROFILE); + IntentUtils.openUserProfile(getActivity(), new AccountKey(account.account_id, + account.account_host), account.account_id, account.screen_name, null, true, + UserFragment.Referral.SELF_PROFILE); } @Override 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 66ce4b53d..6a008e507 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 @@ -258,6 +258,11 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.acceptFriendshipAsync(user.account_id, user.id); + mTwitterWrapper.acceptFriendshipAsync(new AccountKey(user.account_id, user.account_host), + user.id); } @Override @@ -78,7 +82,8 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment final AbsUsersAdapter> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.denyFriendshipAsync(user.account_id, user.id); + mTwitterWrapper.denyFriendshipAsync(new AccountKey(user.account_id, user.account_host), + user.id); } @Subscribe diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/InteractionsTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/InteractionsTimelineFragment.java index 23173e281..ce94d252f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/InteractionsTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/InteractionsTimelineFragment.java @@ -30,6 +30,7 @@ import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter; import org.mariotaku.twidere.annotation.ReadPositionTag; import org.mariotaku.twidere.api.twitter.model.Activity; +import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.util.ErrorInfoStore; @@ -38,8 +39,8 @@ import edu.tsinghua.hotmobi.model.TimelineType; public class InteractionsTimelineFragment extends CursorActivitiesFragment { @Override - public boolean getActivities(long[] accountIds, long[] maxIds, long[] sinceIds) { - mTwitterWrapper.getActivitiesAboutMeAsync(accountIds, maxIds, sinceIds); + public boolean getActivities(RefreshTaskParam param) { + mTwitterWrapper.getActivitiesAboutMeAsync(param); return true; } 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 922883237..92fe42a44 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 @@ -83,6 +83,7 @@ import org.mariotaku.twidere.adapter.SimpleParcelableUsersAdapter; import org.mariotaku.twidere.adapter.iface.IBaseCardAdapter.MenuButtonClickListener; import org.mariotaku.twidere.annotation.CustomTabType; import org.mariotaku.twidere.loader.support.UserSearchLoader; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableUser; @@ -137,11 +138,11 @@ public class MessagesConversationFragment extends BaseSupportFragment implements mUsersSearchList.setVisibility(View.GONE); mUsersSearchEmpty.setVisibility(View.GONE); mUsersSearchProgress.setVisibility(View.VISIBLE); - final long accountId = args.getLong(EXTRA_ACCOUNT_ID); + final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final String query = args.getString(EXTRA_QUERY); final boolean fromCache = args.getBoolean(EXTRA_FROM_CACHE); final boolean fromUser = args.getBoolean(EXTRA_FROM_USER, false); - return new CacheUserSearchLoader(MessagesConversationFragment.this, accountId, query, + return new CacheUserSearchLoader(MessagesConversationFragment.this, accountKey, query, fromCache, fromUser); } @@ -304,13 +305,13 @@ public class MessagesConversationFragment extends BaseSupportFragment implements } else if (args.containsKey(EXTRA_ACCOUNT_ID)) { final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_RECIPIENT_ID, -1); - final int accountPos = accountsSpinnerAdapter.findItemPosition(accountId); + final int accountPos = accountsSpinnerAdapter.findItemPosition(accountKey.getId()); if (accountPos >= 0) { mAccountSpinner.setSelection(accountPos); } account = accountPos >= 0 ? accountsSpinnerAdapter.getItem(accountPos) : - DataStoreUtils.getCredentials(activity, accountId); - recipient = Utils.getUserForConversation(activity, accountId, userId); + DataStoreUtils.getCredentials(activity, accountKey); + recipient = Utils.getUserForConversation(activity, accountKey, userId); } else { account = null; recipient = null; @@ -401,8 +402,10 @@ public class MessagesConversationFragment extends BaseSupportFragment implements public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.delete_all: { - if (mAccount == null || mRecipient == null) return true; - mTwitterWrapper.destroyMessageConversationAsync(mAccount.account_id, mRecipient.id); + final ParcelableCredentials account = mAccount; + if (account == null || mRecipient == null) return true; + mTwitterWrapper.destroyMessageConversationAsync(new AccountKey(account.account_id, + account.account_host), mRecipient.id); return true; } } @@ -489,16 +492,16 @@ public class MessagesConversationFragment extends BaseSupportFragment implements @Override public boolean onMenuItemClick(final MenuItem item) { - if (mSelectedDirectMessage != null) { - final long message_id = mSelectedDirectMessage.id; - final long account_id = mSelectedDirectMessage.account_id; + final ParcelableDirectMessage message = mSelectedDirectMessage; + if (message != null) { switch (item.getItemId()) { case R.id.delete: { - mTwitterWrapper.destroyDirectMessageAsync(account_id, message_id); + mTwitterWrapper.destroyDirectMessageAsync(new AccountKey(message.account_id, + message.account_host), message.id); break; } case R.id.copy: { - if (ClipboardUtils.setText(getActivity(), mSelectedDirectMessage.text_plain)) { + if (ClipboardUtils.setText(getActivity(), message.text_plain)) { Utils.showOkMessage(getActivity(), R.string.text_copied, false); } break; @@ -659,7 +662,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (((BaseAppCompatActivity) activity).getKeyMetaState() != 0) return false; final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); if (account == null) return false; - mEditText.setAccountKey(account.account_id); + mEditText.setAccountKey(new AccountKey(account.account_id, account.account_host)); searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false); return true; } @@ -678,7 +681,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements public void afterTextChanged(Editable s) { final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); if (account == null) return; - mEditText.setAccountKey(account.account_id); + mEditText.setAccountKey(new AccountKey(account.account_id, account.account_host)); searchUsers(account.account_id, ParseUtils.parseString(s), true); } }); @@ -831,8 +834,9 @@ public class MessagesConversationFragment extends BaseSupportFragment implements private final boolean mFromCache; private final UserColorNameManager mUserColorNameManager; - public CacheUserSearchLoader(MessagesConversationFragment fragment, long accountId, String query, boolean fromCache, boolean fromUser) { - super(fragment.getContext(), accountId, query, 0, null, fromUser); + public CacheUserSearchLoader(MessagesConversationFragment fragment, AccountKey accountKey, + String query, boolean fromCache, boolean fromUser) { + super(fragment.getContext(), accountKey, query, 0, null, fromUser); mUserColorNameManager = fragment.mUserColorNameManager; mFromCache = fromCache; } @@ -896,9 +900,10 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final Bundle args = getArguments(); final ParcelableCredentials account = args.getParcelable(EXTRA_ACCOUNT); final ParcelableUser user = args.getParcelable(EXTRA_USER); - if (account == null || user == null) return; final AsyncTwitterWrapper twitter = mTwitterWrapper; - twitter.destroyMessageConversationAsync(account.account_id, user.id); + if (account == null || user == null || twitter == null) return; + twitter.destroyMessageConversationAsync(new AccountKey(account.account_id, + account.account_host), user.id); break; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java index e142cedde..fd710a87d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java @@ -25,13 +25,16 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.MutesUsersLoader; +import org.mariotaku.twidere.model.AccountKey; public class MutesUsersListFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); - return new MutesUsersLoader(context, accountId, getNextCursor(), getData(), fromUser); + final MutesUsersLoader loader = new MutesUsersLoader(context, accountKey, getData(), fromUser); + loader.setCursor(getNextCursor()); + return loader; } } 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 c7c16c030..7c5d1c341 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 @@ -462,15 +462,15 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac @Override public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) { final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, status.account_id, status.user_id, - status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); + IntentUtils.openUserProfile(activity, new AccountKey(status.account_id, status.account_host), + status.user_id, status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } @Override - public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) { + public void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long extraId) { final ParcelableStatus status = mStatusAdapter.getStatus(); if (status == null) return; - IntentUtils.openMediaDirectly(getActivity(), accountId, status, media, null, true); + IntentUtils.openMediaDirectly(getActivity(), accountKey, status, media, null, true); // BEGIN HotMobi MediaEvent event = MediaEvent.create(getActivity(), status, media, TimelineType.OTHER, mStatusAdapter.isMediaPreviewEnabled()); @@ -545,9 +545,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac @Override public Loader> onCreateLoader(final int id, final Bundle args) { final Bundle fragmentArgs = getArguments(); - final long accountId = fragmentArgs.getLong(EXTRA_ACCOUNT_ID, -1); + final AccountKey accountKey = fragmentArgs.getParcelable(EXTRA_ACCOUNT_KEY); final long statusId = fragmentArgs.getLong(EXTRA_STATUS_ID, -1); - return new ParcelableStatusLoader(getActivity(), false, fragmentArgs, accountId, statusId); + return new ParcelableStatusLoader(getActivity(), false, fragmentArgs, accountKey, statusId); } @Override @@ -592,7 +592,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final TweetEvent event = mStatusEvent; if (event == null) return; event.markEnd(); - HotMobiLogger.getInstance(getActivity()).log(event.getAccountId(), event); + final AccountKey accountKey = new AccountKey(event.getAccountId(), event.getAccountHost()); + HotMobiLogger.getInstance(getActivity()).log(accountKey, event); } @Override @@ -673,7 +674,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac private void loadConversation(ParcelableStatus status, long sinceId, long maxId) { if (status == null) return; final Bundle args = new Bundle(); - args.putLong(EXTRA_ACCOUNT_ID, status.account_id); + args.putParcelable(EXTRA_ACCOUNT_KEY, new AccountKey(status.account_id, status.account_host)); args.putLong(EXTRA_STATUS_ID, status.is_retweet ? status.retweet_id : status.id); args.putLong(EXTRA_SINCE_ID, sinceId); args.putLong(EXTRA_MAX_ID, maxId); @@ -1016,7 +1017,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final CharSequence quotedText = HtmlSpanBuilder.fromHtml(status.quoted_text_html, status.text_unescaped); if (quotedText instanceof Spanned) { - quotedTextView.setText(linkify.applyAllLinks(quotedText, status.account_id, + quotedTextView.setText(linkify.applyAllLinks(quotedText, + new AccountKey(status.account_id, status.account_host), layoutPosition, status.is_possibly_sensitive, skipLinksInText)); } @@ -1070,8 +1072,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final CharSequence text = HtmlSpanBuilder.fromHtml(status.text_html, status.text_unescaped); if (text instanceof Spanned) { - textView.setText(linkify.applyAllLinks(text, status.account_id, layoutPosition, - status.is_possibly_sensitive, skipLinksInText)); + textView.setText(linkify.applyAllLinks(text, new AccountKey(status.account_id, + status.account_host), layoutPosition, status.is_possibly_sensitive, skipLinksInText)); } final ParcelableLocation location; @@ -1125,8 +1127,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac mediaPreviewContainer.setVisibility(View.VISIBLE); mediaPreview.setVisibility(View.VISIBLE); mediaPreviewLoad.setVisibility(View.GONE); - mediaPreview.displayMedia(media, loader, status.account_id, -1, adapter.getFragment(), - adapter.getMediaLoadingHandler()); + mediaPreview.displayMedia(media, loader, new AccountKey(status.account_id, + status.account_host), -1, adapter.getFragment(), adapter.getMediaLoadingHandler()); } else { mediaPreviewContainer.setVisibility(View.VISIBLE); mediaPreview.setVisibility(View.GONE); @@ -1190,6 +1192,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final ParcelableStatus status = adapter.getStatus(getLayoutPosition()); final StatusFragment fragment = adapter.getFragment(); if (status == null || fragment == null) return; + final AccountKey accountKey = new AccountKey(status.account_id, status.account_host); switch (v.getId()) { case R.id.media_preview_load: { if (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive) { @@ -1202,13 +1205,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } case R.id.profile_container: { final FragmentActivity activity = fragment.getActivity(); - IntentUtils.openUserProfile(activity, status.account_id, status.user_id, + IntentUtils.openUserProfile(activity, accountKey, status.user_id, status.user_screen_name, null, true, UserFragment.Referral.STATUS); break; } case R.id.retweeted_by: { if (status.retweet_id > 0) { - IntentUtils.openUserProfile(adapter.getContext(), status.account_id, + IntentUtils.openUserProfile(adapter.getContext(), accountKey, status.retweeted_by_user_id, status.retweeted_by_user_screen_name, null, true, UserFragment.Referral.STATUS); } @@ -1221,13 +1224,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac break; } case R.id.quoted_name_container: { - IntentUtils.openUserProfile(adapter.getContext(), status.account_id, + IntentUtils.openUserProfile(adapter.getContext(), accountKey, status.quoted_user_id, status.quoted_user_screen_name, null, true, UserFragment.Referral.STATUS); break; } case R.id.quote_original_link: { - Utils.openStatus(adapter.getContext(), status.account_id, status.quoted_id); + Utils.openStatus(adapter.getContext(), accountKey, status.quoted_id); break; } case R.id.translate_label: { @@ -1590,7 +1593,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } @Override - public void onLinkClick(String link, String orig, long accountId, long extraId, int type, boolean sensitive, int start, int end) { + public void onLinkClick(final String link, final String orig, final AccountKey accountKey, + long extraId, int type, boolean sensitive, int start, int end) { final ParcelableStatus status = adapter.getStatus(); ParcelableMedia current; if ((current = ParcelableMediaUtils.findByUrl(status.media, link)) != null && @@ -1607,7 +1611,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac expandOrOpenMedia(null); return; } - super.onLinkClick(link, orig, accountId, extraId, type, sensitive, start, end); + super.onLinkClick(link, orig, accountKey, extraId, type, sensitive, start, end); } private void expandOrOpenMedia(ParcelableMedia current) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java index ef227ee69..ba73818a2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java @@ -41,11 +41,11 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment { if (getActivity() == null || !isAdded() || isDetached()) return; final String action = intent.getAction(); if (BROADCAST_MULTI_BLOCKSTATE_CHANGED.equals(action)) { - final long account_id = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1); - final String screen_name = getAccountScreenName(getActivity(), account_id); + final AccountKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); + final String screen_name = getAccountScreenName(getActivity(), accountKey); final Bundle args = getArguments(); if (args == null) return; - if (account_id > 0 && args.getLong(EXTRA_USER_ID, -1) == account_id || screen_name != null + if (accountKey != null && accountKey.getId() == args.getLong(EXTRA_USER_ID, -1) || screen_name != null && screen_name.equalsIgnoreCase(args.getString(EXTRA_SCREEN_NAME))) { removeUsers(intent.getLongArrayExtra(EXTRA_USER_IDS)); } 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 37ab4f0cf..c4428e967 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 @@ -1318,7 +1318,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener ParcelableMedia profileImage = ParcelableMediaUtils.image(url); profileImage.type = ParcelableMedia.Type.IMAGE; final ParcelableMedia[] media = {profileImage}; - IntentUtils.openMedia(activity, user.account_id, false, null, media, null, true); + IntentUtils.openMedia(activity, new AccountKey(user.account_id, user.account_host), + false, null, media, null, true); break; } case R.id.profile_banner: { @@ -1327,7 +1328,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener ParcelableMedia profileBanner = ParcelableMediaUtils.image(url); profileBanner.type = ParcelableMedia.Type.IMAGE; final ParcelableMedia[] media = {profileBanner}; - IntentUtils.openMedia(activity, user.account_id, false, null, media, null, true); + IntentUtils.openMedia(activity, new AccountKey(user.account_id, user.account_host), + false, null, media, null, true); break; } case R.id.listed_container: { @@ -1364,8 +1366,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (user == null) return; switch (type) { case TwidereLinkify.LINK_TYPE_MENTION: { - IntentUtils.openUserProfile(getActivity(), user.account_id, -1, link, null, - true, Referral.USER_MENTION); + IntentUtils.openUserProfile(getActivity(), new AccountKey(user.account_id, + user.account_host), -1, link, null, true, Referral.USER_MENTION); break; } case TwidereLinkify.LINK_TYPE_HASHTAG: { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java index ca62cbade..eee418d92 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java @@ -354,8 +354,9 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList case R.id.profile_image: { final ParcelableUserList userList = mUserList; if (userList == null) return; - IntentUtils.openUserProfile(getActivity(), userList.account_id, userList.user_id, - userList.user_screen_name, null, true, null); + IntentUtils.openUserProfile(getActivity(), new AccountKey(userList.account_id, + userList.account_host), userList.user_id, userList.user_screen_name, null, + true, null); break; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java index 20de5f15a..f9d8fd58a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java @@ -29,6 +29,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.SearchQuery; import org.mariotaku.twidere.api.twitter.model.Status; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; @@ -50,7 +51,8 @@ public class ConversationLoader extends TwitterAPIStatusesLoader { public ConversationLoader(final Context context, @NonNull final ParcelableStatus status, final long sinceId, final long maxId, final List data, final boolean fromUser) { - super(context, status.account_id, sinceId, maxId, data, null, -1, fromUser); + super(context, new AccountKey(status.account_id, status.account_host), sinceId, maxId, data, + null, -1, fromUser); mStatus = Nullables.assertNonNull(ParcelUtils.clone(status)); ParcelableStatusUtils.makeOriginalStatus(mStatus); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java index ff6dd6cc8..6845c0371 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java @@ -22,6 +22,7 @@ package org.mariotaku.twidere.loader.support; import android.content.Context; import android.support.annotation.NonNull; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -34,9 +35,9 @@ import org.mariotaku.twidere.api.twitter.model.User; public class MutesUsersLoader extends CursorSupportUsersLoader { - public MutesUsersLoader(final Context context, final long accountId, final long cursor, + public MutesUsersLoader(final Context context, final AccountKey accountKey, final List data, boolean fromUser) { - super(context, accountId, data, fromUser); + super(context, accountKey, data, fromUser); } @NonNull diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java index a9d97183b..aa41dd9e2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.support.v4.content.AsyncTaskLoader; import org.mariotaku.twidere.constant.IntentConstants; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.SingleResponse; @@ -41,10 +42,11 @@ public class ParcelableStatusLoader extends AsyncTaskLoader response = SingleResponse.getInstance(status); final Bundle extras = response.getExtras(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java index c8c93feda..74783eb48 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java @@ -44,9 +44,9 @@ import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.JsonSerializer; import org.mariotaku.twidere.util.TwitterAPIFactory; import org.mariotaku.twidere.util.TwitterWrapper; +import org.mariotaku.twidere.util.Utils; import static org.mariotaku.twidere.util.ContentValuesCreator.createCachedUser; -import static org.mariotaku.twidere.util.Utils.isMyAccount; public final class ParcelableUserLoader extends AsyncTaskLoader> implements Constants { @@ -72,7 +72,8 @@ public final class ParcelableUserLoader extends AsyncTaskLoader loadInBackground() { final Context context = getContext(); final ContentResolver resolver = context.getContentResolver(); - int accountColor = DataStoreUtils.getAccountColor(context, mAccountId); + final AccountKey accountKey = mAccountId; + int accountColor = DataStoreUtils.getAccountColor(context, accountKey); if (!mOmitIntentExtra && mExtras != null) { final ParcelableUser user = mExtras.getParcelable(EXTRA_USER); if (user != null) { @@ -82,7 +83,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) { - super(context, accountId, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser); + super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser); } @NonNull diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java index ae3545596..fe3159f88 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java @@ -27,22 +27,24 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.util.TwitterAPIFactory; import static org.mariotaku.twidere.TwidereConstants.LOGTAG; public class SavedSearchesLoader extends AsyncTaskLoader> { - private final long mAccountId; + private final AccountKey mAccountId; - public SavedSearchesLoader(final Context context, final long account_id) { + public SavedSearchesLoader(final Context context, final AccountKey accountKey) { super(context); - mAccountId = account_id; + mAccountId = accountKey; } @Override public ResponseList loadInBackground() { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, accountHost, false); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, + false); if (twitter == null) return null; try { return twitter.getSavedSearches(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java index 6f8822425..d54bf68e3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java @@ -26,6 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ScheduledStatus; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.util.TwitterAPIFactory; import java.util.List; @@ -35,13 +36,13 @@ import java.util.List; */ public class ScheduledStatusesLoader extends AsyncTaskLoader> { - private final long mAccountId; + private final AccountKey mAccountId; private final long mSinceId; private final long mMaxId; @ScheduledStatus.State private final String[] mStates; - public ScheduledStatusesLoader(Context context, long accountId, long sinceId, long maxId, + public ScheduledStatusesLoader(Context context, AccountKey accountId, long sinceId, long maxId, @ScheduledStatus.State String[] states, List data) { super(context); mAccountId = accountId; @@ -53,7 +54,8 @@ public class ScheduledStatusesLoader extends AsyncTaskLoader loadInBackground() { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, accountHost, true); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, true); + if (twitter == null) return null; final Paging paging = new Paging(); if (mSinceId > 0) { paging.setSinceId(mSinceId); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java index 3161ecf59..5b3745074 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java @@ -26,6 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -35,9 +36,9 @@ public class UserSearchLoader extends TwitterAPIUsersLoader { private final String mQuery; private final int mPage; - public UserSearchLoader(final Context context, final long accountId, final String query, final int page, - final List data, boolean fromUser) { - super(context, accountId, data, fromUser); + public UserSearchLoader(final Context context, final AccountKey accountKey, final String query, + final int page, final List data, boolean fromUser) { + super(context, accountKey, data, fromUser); mQuery = query; mPage = page; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java b/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java index 1e8a5151d..0bd556544 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java @@ -8,14 +8,14 @@ import android.support.annotation.Nullable; */ public class BaseRefreshTaskParam implements RefreshTaskParam { - private final AccountKey[] mAccountKeys; + private final AccountKey[] accountKeys; private final long[] maxIds; private final long[] sinceIds; @NonNull @Override public AccountKey[] getAccountKeys() { - return mAccountKeys; + return accountKeys; } @Nullable @@ -30,8 +30,18 @@ public class BaseRefreshTaskParam implements RefreshTaskParam { return sinceIds; } + @Override + public boolean hasMaxIds() { + return maxIds != null; + } + + @Override + public boolean hasSinceIds() { + return sinceIds != null; + } + public BaseRefreshTaskParam(AccountKey[] accountKeys, long[] maxIds, long[] sinceIds) { - this.mAccountKeys = accountKeys; + this.accountKeys = accountKeys; this.maxIds = maxIds; this.sinceIds = sinceIds; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java b/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java index 3e2bb8a4c..1ce3fe9f8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java @@ -16,4 +16,8 @@ public interface RefreshTaskParam { @Nullable long[] getSinceIds(); + boolean hasMaxIds(); + + boolean hasSinceIds(); + } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/SimpleRefreshTaskParam.java b/twidere/src/main/java/org/mariotaku/twidere/model/SimpleRefreshTaskParam.java index 7bc8f4502..a1faef9b3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/SimpleRefreshTaskParam.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/SimpleRefreshTaskParam.java @@ -18,4 +18,14 @@ public abstract class SimpleRefreshTaskParam implements RefreshTaskParam { public long[] getSinceIds() { return null; } + + @Override + public boolean hasMaxIds() { + return getMaxIds() != null; + } + + @Override + public boolean hasSinceIds() { + return getSinceIds() != null; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java index 0dadbd018..8f330a35a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java @@ -2,6 +2,7 @@ package org.mariotaku.twidere.model.util; import org.mariotaku.twidere.api.twitter.model.DirectMessage; import org.mariotaku.twidere.api.twitter.model.User; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import org.mariotaku.twidere.util.TwitterContentUtils; @@ -14,9 +15,14 @@ import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText; * Created by mariotaku on 16/2/13. */ public class ParcelableDirectMessageUtils { - public static ParcelableDirectMessage fromDirectMessage(DirectMessage message, long accountId, boolean isOutgoing) { + public static ParcelableDirectMessage fromDirectMessage(DirectMessage message, AccountKey accountKey, boolean isOutgoing) { + return fromDirectMessage(message, accountKey.getId(), accountKey.getHost(), isOutgoing); + } + + public static ParcelableDirectMessage fromDirectMessage(DirectMessage message, long accountId, String accountHost, boolean isOutgoing) { ParcelableDirectMessage result = new ParcelableDirectMessage(); result.account_id = accountId; + result.account_host = accountHost; result.is_outgoing = isOutgoing; final User sender = message.getSender(), recipient = message.getRecipient(); assert sender != null && recipient != null; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java index 081e844c9..bf917fa4f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java @@ -134,7 +134,7 @@ public class ParcelableMediaUtils { if ("animated_gif".equals(name) || "player".equals(name)) { final ParcelableMedia media = new ParcelableMedia(); final CardEntity.BindingValue playerStreamUrl = card.getBindingValue("player_stream_url"); - media.card = ParcelableCardEntityUtils.fromCardEntity(card, -1); + media.card = ParcelableCardEntityUtils.fromCardEntity(card, null); CardEntity.StringValue appUrlResolved = (CardEntity.StringValue) card.getBindingValue("app_url_resolved"); media.url = checkUrl(appUrlResolved) ? appUrlResolved.getValue() : card.getUrl(); if ("animated_gif".equals(name)) { @@ -179,7 +179,7 @@ public class ParcelableMediaUtils { final ParcelableMedia media = new ParcelableMedia(); media.url = card.getUrl(); - media.card = ParcelableCardEntityUtils.fromCardEntity(card, -1); + media.card = ParcelableCardEntityUtils.fromCardEntity(card, null); media.type = ParcelableMedia.Type.IMAGE; media.media_url = ((CardEntity.ImageValue) photoImageFullSize).getUrl(); media.width = ((CardEntity.ImageValue) photoImageFullSize).getWidth(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java index bd38c022b..ecc91ae24 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java @@ -63,6 +63,7 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.StatusUpdate; import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import org.mariotaku.twidere.app.TwidereApplication; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.DraftCursorIndices; import org.mariotaku.twidere.model.DraftValuesCreator; @@ -288,15 +289,15 @@ public class BackgroundOperationService extends IntentService implements Constan } private void handleSendDirectMessageIntent(final Intent intent) { - final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1); + final AccountKey accountId = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); final long recipientId = intent.getLongExtra(EXTRA_RECIPIENT_ID, -1); final String imageUri = intent.getStringExtra(EXTRA_IMAGE_URI); final String text = intent.getStringExtra(EXTRA_TEXT); sendMessage(accountId, recipientId, text, imageUri); } - private void sendMessage(long accountId, long recipientId, String text, String imageUri) { - if (accountId <= 0 || recipientId <= 0 || isEmpty(text)) return; + private void sendMessage(AccountKey accountId, long recipientId, String text, String imageUri) { + if (accountId == null || recipientId <= 0 || isEmpty(text)) return; final String title = getString(R.string.sending_direct_message); final Builder builder = new Builder(this); builder.setSmallIcon(R.drawable.ic_stat_send); @@ -376,7 +377,8 @@ public class BackgroundOperationService extends IntentService implements Constan boolean failed = false; Exception exception = null; final Expression where = Expression.equals(Drafts._ID, draftId); - final List failedAccountIds = TwidereListUtils.fromArray(DataStoreUtils.getAccountKeys(item.accounts)); + final List failedAccountIds = new ArrayList<>(); + Collections.addAll(failedAccountIds, DataStoreUtils.getAccountKeys(item.accounts)); for (final SingleResponse response : result) { final ParcelableStatus data = response.getData(); @@ -386,11 +388,12 @@ public class BackgroundOperationService extends IntentService implements Constan exception = response.getException(); } } else if (data.account_id > 0) { - failedAccountIds.remove(data.account_id); + failedAccountIds.remove(new AccountKey(data.account_id, data.account_host)); // BEGIN HotMobi final TweetEvent event = TweetEvent.create(this, data, TimelineType.OTHER); event.setAction(TweetEvent.Action.TWEET); - HotMobiLogger.getInstance(this).log(data.account_id, event); + HotMobiLogger.getInstance(this).log(new AccountKey(data.account_id, + data.account_host), event); // END HotMobi } } @@ -442,10 +445,10 @@ public class BackgroundOperationService extends IntentService implements Constan private SingleResponse sendDirectMessage(final NotificationCompat.Builder builder, - final long accountId, final long recipientId, + final AccountKey accountKey, final long recipientId, final String text, final String imageUri) { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(this, accountId, true, true); - final TwitterUpload twitterUpload = TwitterAPIFactory.getTwitterInstance(this, accountId, accountHost, true, true, TwitterUpload.class); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(this, accountKey, true, true); + final TwitterUpload twitterUpload = TwitterAPIFactory.getTwitterInstance(this, accountKey, true, true, TwitterUpload.class); if (twitter == null || twitterUpload == null) return SingleResponse.getInstance(); try { final ParcelableDirectMessage directMessage; @@ -462,12 +465,12 @@ public class BackgroundOperationService extends IntentService implements Constan // final MediaUploadResponse uploadResp = twitter.uploadMedia(file.getName(), is, o.outMimeType); final MediaUploadResponse uploadResp = twitterUpload.uploadMedia(file); directMessage = ParcelableDirectMessageUtils.fromDirectMessage(twitter.sendDirectMessage(recipientId, text, - uploadResp.getId()), accountId, true); + uploadResp.getId()), accountKey, true); if (!file.delete()) { Log.d(LOGTAG, String.format("unable to delete %s", path)); } } else { - directMessage = ParcelableDirectMessageUtils.fromDirectMessage(twitter.sendDirectMessage(recipientId, text), accountId, true); + directMessage = ParcelableDirectMessageUtils.fromDirectMessage(twitter.sendDirectMessage(recipientId, text), accountKey, true); } Utils.setLastSeen(this, recipientId, System.currentTimeMillis()); @@ -581,12 +584,14 @@ public class BackgroundOperationService extends IntentService implements Constan shortener.waitForService(); } for (final ParcelableAccount account : statusUpdate.accounts) { - final ParcelableCredentials credentials = DataStoreUtils.getCredentials(this, account.account_id); + final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); + final ParcelableCredentials credentials = DataStoreUtils.getCredentials(this, + accountKey); // Get Twitter instance corresponding to account - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(this, account.account_id, + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(this, accountKey, true, true); - final TwitterUpload upload = TwitterAPIFactory.getTwitterInstance(this, account.account_id, - accountHost, true, true, TwitterUpload.class); + final TwitterUpload upload = TwitterAPIFactory.getTwitterInstance(this, + accountKey, true, true, TwitterUpload.class); // Shouldn't happen if (twitter == null || upload == null || credentials == null) { @@ -621,7 +626,7 @@ public class BackgroundOperationService extends IntentService implements Constan StatusShortenResult shortenedResult = null; if (shouldShorten && shortener != null) { try { - shortenedResult = shortener.shorten(statusUpdate, account.account_id, + shortenedResult = shortener.shorten(statusUpdate, accountKey.getId(), statusText); } catch (final Exception e) { throw new ShortenException(getString(R.string.error_message_tweet_shorten_failed), e); @@ -701,7 +706,8 @@ public class BackgroundOperationService extends IntentService implements Constan notReplyToOther = true; } } - final ParcelableStatus result = ParcelableStatusUtils.fromStatus(resultStatus, account.account_id, accountHost, false); + final ParcelableStatus result = ParcelableStatusUtils.fromStatus(resultStatus, + accountKey, false); if (shouldShorten && shortener != null && shortenedResult != null) { shortener.callback(shortenedResult, result); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java b/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java index 53a7765f7..b1f5d0a9a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java @@ -34,6 +34,7 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.api.twitter.model.Warning; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; @@ -61,7 +62,7 @@ public class StreamingService extends Service implements Constants { private NotificationManager mNotificationManager; - private long[] mAccountIds; + private AccountKey[] mAccountKeys; private static final Uri[] MESSAGES_URIS = new Uri[]{DirectMessages.Inbox.CONTENT_URI, DirectMessages.Outbox.CONTENT_URI}; @@ -75,7 +76,7 @@ public class StreamingService extends Service implements Constants { @Override public void onChange(final boolean selfChange, final Uri uri) { - if (!TwidereArrayUtils.contentMatch(mAccountIds, DataStoreUtils.getActivatedAccountKeys(StreamingService.this))) { + if (!TwidereArrayUtils.contentMatch(mAccountKeys, DataStoreUtils.getActivatedAccountKeys(StreamingService.this))) { initStreaming(); } } @@ -126,19 +127,20 @@ public class StreamingService extends Service implements Constants { private boolean setTwitterInstances() { final List accountsList = DataStoreUtils.getCredentialsList(this, true); - final long[] accountIds = new long[accountsList.size()]; - for (int i = 0, j = accountIds.length; i < j; i++) { - accountIds[i] = accountsList.get(i).account_id; + final AccountKey[] accountKeys = new AccountKey[accountsList.size()]; + for (int i = 0, j = accountKeys.length; i < j; i++) { + final ParcelableCredentials credentials = accountsList.get(i); + accountKeys[i] = new AccountKey(credentials.account_id, credentials.account_host); } - final AccountPreferences[] activitedPreferences = AccountPreferences.getAccountPreferences(this, accountIds); + final AccountPreferences[] activatedPreferences = AccountPreferences.getAccountPreferences(this, accountKeys); if (BuildConfig.DEBUG) { Log.d(Constants.LOGTAG, "Setting up twitter stream instances"); } - mAccountIds = accountIds; + mAccountKeys = accountKeys; clearTwitterInstances(); boolean result = false; for (int i = 0, j = accountsList.size(); i < j; i++) { - final AccountPreferences preferences = activitedPreferences[i]; + final AccountPreferences preferences = activatedPreferences[i]; if (!preferences.isStreamingEnabled()) continue; final ParcelableCredentials account = accountsList.get(i); final Endpoint endpoint = TwitterAPIFactory.getEndpoint(account, TwitterUserStream.class); @@ -246,14 +248,14 @@ public class StreamingService extends Service implements Constants { final User sender = directMessage.getSender(), recipient = directMessage.getRecipient(); if (sender.getId() == account.account_id) { final ContentValues values = ContentValuesCreator.createDirectMessage(directMessage, - account.account_id, true); + account.account_id, account.account_host, true); if (values != null) { resolver.insert(DirectMessages.Outbox.CONTENT_URI, values); } } if (recipient.getId() == account.account_id) { final ContentValues values = ContentValuesCreator.createDirectMessage(directMessage, - account.account_id, false); + account.account_id, account.account_host, false); final Uri.Builder builder = DirectMessages.Inbox.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_NOTIFY, "true"); if (values != null) { @@ -332,8 +334,8 @@ public class StreamingService extends Service implements Constants { @Override public void onStatus(final Status status) { - final ContentValues values = ContentValuesCreator.createStatus(status, account.account_id, - account.account_host); + final ContentValues values = ContentValuesCreator.createStatus(status, + new AccountKey(account.account_id, account.account_host)); if (!statusStreamStarted) { statusStreamStarted = true; values.put(Statuses.IS_GAP, true); diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java index 57289bffa..30eb96f57 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java @@ -66,8 +66,7 @@ public class CacheUsersStatusesTask extends AbstractTask hashTagValues = new HashSet<>(); final AccountKey accountKey = params.mAccountKey; - statusesValues.add(ContentValuesCreator.createStatus(status, accountKey.getId(), - accountKey.getHost())); + statusesValues.add(ContentValuesCreator.createStatus(status, accountKey)); final String text = InternalTwitterContentUtils.unescapeTwitterStatusText(status.getText()); for (final String hashtag : extractor.extractHashtags(text)) { final ContentValues values = new ContentValues(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java index a39630710..65ceada2d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java @@ -35,8 +35,7 @@ public class GetSavedSearchesTask extends AbstractTask doLongOperation(AccountKey[] params) { final ContentResolver cr = mContext.getContentResolver(); for (AccountKey accountKey : params) { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountKey.getId(), - accountKey.getHost(), true); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountKey, true); if (twitter == null) continue; try { final ResponseList searches = twitter.getSavedSearches(); 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 f3576a60b..fc70f9da4 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 @@ -78,15 +78,14 @@ public abstract class GetStatusesTask extends AbstractTask statuses, + private void storeStatus(final AccountKey accountKey, final List statuses, final long sinceId, final long maxId, final boolean notify) { - if (statuses == null || statuses.isEmpty() || accountId <= 0) { + if (statuses == null || statuses.isEmpty() || accountKey == null) { return; } final Uri uri = getContentUri(); final ContentResolver resolver = context.getContentResolver(); - final boolean noItemsBefore = DataStoreUtils.getStatusCount(context, uri, accountId) <= 0; + final boolean noItemsBefore = DataStoreUtils.getStatusCount(context, uri, accountKey) <= 0; final ContentValues[] values = new ContentValues[statuses.size()]; final long[] statusIds = new long[statuses.size()]; long minId = -1; @@ -94,7 +93,7 @@ public abstract class GetStatusesTask extends AbstractTask 0 && id <= sinceId) { @@ -107,13 +106,14 @@ public abstract class GetStatusesTask extends AbstractTask statuses = getStatuses(twitter, paging); InternalTwitterContentUtils.getStatusesWithQuoteData(twitter, statuses); - storeStatus(accountKey.getId(), accountKey.getHost(), statuses, sinceId, maxId, true); + storeStatus(accountKey, statuses, sinceId, maxId, true); // TODO cache related data and preload final CacheUsersStatusesTask cacheTask = new CacheUsersStatusesTask(context); cacheTask.setParams(new TwitterWrapper.StatusListResponse(accountKey, statuses)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java index 0f5cf6225..495a70820 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java +++ b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java @@ -25,25 +25,26 @@ import android.text.style.URLSpan; import android.view.View; import org.mariotaku.twidere.Constants; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener; public class TwidereURLSpan extends URLSpan implements Constants { private final int type, highlightStyle; - private final long accountId; + private final AccountKey accountKey; private final long extraId; private final String url, orig; private final boolean sensitive; private final OnLinkClickListener listener; private final int start, end; - public TwidereURLSpan(final String url, final String orig, final long accountId, final long extraId, + public TwidereURLSpan(final String url, final String orig, final AccountKey accountKey, final long extraId, final int type, final boolean sensitive, final int highlightStyle, int start, int end, final OnLinkClickListener listener) { super(url); this.url = url; this.orig = orig; - this.accountId = accountId; + this.accountKey = accountKey; this.extraId = extraId; this.type = type; this.sensitive = sensitive; @@ -56,7 +57,7 @@ public class TwidereURLSpan extends URLSpan implements Constants { @Override public void onClick(@NonNull final View widget) { if (listener != null) { - listener.onLinkClick(url, orig, accountId, extraId, type, sensitive, start, end); + listener.onLinkClick(url, orig, accountKey, extraId, type, sensitive, start, end); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java index c1d5e0b60..92beb179f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java @@ -222,12 +222,13 @@ public final class ContentValuesCreator implements TwidereConstants { return values; } - public static ContentValues createMessageDraft(final long accountId, final long recipientId, + public static ContentValues createMessageDraft(final AccountKey accountKey, final long recipientId, final String text, final String imageUri) { final ContentValues values = new ContentValues(); values.put(Drafts.ACTION_TYPE, Draft.Action.SEND_DIRECT_MESSAGE); values.put(Drafts.TEXT, text); - values.put(Drafts.ACCOUNT_IDS, TwidereArrayUtils.toString(new long[]{accountId}, ',', false)); + values.put(Drafts.ACCOUNT_IDS, TwidereArrayUtils.toString(new long[]{accountKey.getId()}, + ',', false)); values.put(Drafts.TIMESTAMP, System.currentTimeMillis()); if (imageUri != null) { final ParcelableMediaUpdate[] mediaArray = {new ParcelableMediaUpdate(imageUri, 0)}; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java index 9e839af89..ab1255493 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java @@ -241,9 +241,10 @@ public class DataStoreUtils implements Constants { Activities.MAX_POSITION, new OrderBy(SQLFunctions.MIN(Activities.TIMESTAMP))); } - public static int getStatusCount(final Context context, final Uri uri, final long accountId) { - final String where = Expression.equals(Statuses.ACCOUNT_ID, accountId).getSQL(); - return queryCount(context, uri, where, null); + public static int getStatusCount(final Context context, final Uri uri, final AccountKey accountId) { + final String where = Utils.getAccountCompareExpression().getSQL(); + final String[] whereArgs = {String.valueOf(accountId.getId()), accountId.getHost()}; + return queryCount(context, uri, where, whereArgs); } public static int getActivitiesCount(final Context context, final Uri uri, final AccountKey accountKey) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java index a9379d36e..1d7923c12 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java @@ -79,11 +79,11 @@ public class IntentUtils implements Constants { } } - public static void openUserProfile(final Context context, final long accountId, final long userId, - final String screenName, final Bundle activityOptions, - final boolean newDocument, + public static void openUserProfile(final Context context, @Nullable final AccountKey accountId, + final long userId, final String screenName, + final Bundle activityOptions, final boolean newDocument, @UserFragment.Referral final String referral) { - if (context == null || accountId <= 0 || userId <= 0 && isEmpty(screenName)) return; + if (context == null || userId <= 0 && isEmpty(screenName)) return; final Uri uri = LinkCreator.getTwidereUserLink(accountId, userId, screenName); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(EXTRA_REFERRAL, referral); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java b/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java index 9305373d2..3c814dc8b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java @@ -20,9 +20,11 @@ package org.mariotaku.twidere.util; import android.net.Uri; +import android.support.annotation.Nullable; import android.text.TextUtils; import org.mariotaku.twidere.Constants; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableStatus; /** @@ -42,23 +44,23 @@ public class LinkCreator implements Constants { return builder.build(); } - public static Uri getTwidereStatusLink(long accountId, long statusId) { + public static Uri getTwidereStatusLink(AccountKey accountKey, long statusId) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_STATUS); - if (accountId > 0) { - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId)); + if (accountKey != null) { + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString()); } builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(statusId)); return builder.build(); } - public static Uri getTwidereUserLink(long accountId, long userId, String screenName) { + public static Uri getTwidereUserLink(@Nullable AccountKey accountId, long userId, String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_USER); - if (accountId > 0) { - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId)); + if (accountId != null) { + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountId.toString()); } if (userId > 0) { builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(userId)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java index 328204c31..5a5d227f0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java @@ -33,6 +33,7 @@ import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import org.mariotaku.twidere.Constants; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; @@ -109,16 +110,17 @@ public class MediaLoaderWrapper implements Constants { mImageLoader.displayImage(url, view, mImageDisplayOptions, loadingHandler, loadingHandler); } - public void displayPreviewImageWithCredentials(final ImageView view, final String url, final long accountId, + public void displayPreviewImageWithCredentials(final ImageView view, final String url, + final AccountKey accountKey, final MediaLoadingHandler loadingHandler) { - if (accountId <= 0) { + if (accountKey == null) { displayPreviewImage(view, url, loadingHandler); return; } final DisplayImageOptions.Builder b = new DisplayImageOptions.Builder(); b.cloneFrom(mImageDisplayOptions); MediaExtra extra = new MediaExtra(); - extra.setAccountId(accountId); + extra.setAccountKey(accountKey); b.extraForDownloader(extra); mImageLoader.displayImage(url, view, b.build(), loadingHandler, loadingHandler); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java index 6d000cdcf..49263b750 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java @@ -29,6 +29,7 @@ import android.support.annotation.Nullable; import org.apache.commons.lang3.math.NumberUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.fragment.support.UserFragment; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener; @@ -50,30 +51,30 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { } @Override - public void onLinkClick(final String link, final String orig, final long accountId, + public void onLinkClick(final String link, final String orig, final AccountKey accountKey, final long extraId, final int type, final boolean sensitive, final int start, final int end) { if (manager != null && manager.isActive()) return; if (!isPrivateData()) { // BEGIN HotMobi final LinkEvent event = LinkEvent.create(context, link, type); - HotMobiLogger.getInstance(context).log(accountId, event); + HotMobiLogger.getInstance(context).log(accountKey, event); // END HotMobi } switch (type) { case TwidereLinkify.LINK_TYPE_MENTION: { - IntentUtils.openUserProfile(context, accountId, -1, link, null, true, + IntentUtils.openUserProfile(context, accountKey, -1, link, null, true, UserFragment.Referral.USER_MENTION); break; } case TwidereLinkify.LINK_TYPE_HASHTAG: { - Utils.openTweetSearch(context, accountId, "#" + link); + Utils.openTweetSearch(context, accountKey, "#" + link); break; } case TwidereLinkify.LINK_TYPE_ENTITY_URL: { if (PreviewMediaExtractor.isSupported(link)) { - openMedia(accountId, extraId, sensitive, link, start, end); + openMedia(accountKey, extraId, sensitive, link, start, end); } else { openLink(link); } @@ -84,20 +85,20 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { if (mentionList.length != 2) { break; } - Utils.openUserListDetails(context, accountId, -1, -1, mentionList[0], mentionList[1]); + Utils.openUserListDetails(context, accountKey, -1, -1, mentionList[0], mentionList[1]); break; } case TwidereLinkify.LINK_TYPE_CASHTAG: { - Utils.openTweetSearch(context, accountId, link); + Utils.openTweetSearch(context, accountKey, link); break; } case TwidereLinkify.LINK_TYPE_USER_ID: { - IntentUtils.openUserProfile(context, accountId, NumberUtils.toLong(link, -1), null, + IntentUtils.openUserProfile(context, accountKey, NumberUtils.toLong(link, -1), null, null, true, UserFragment.Referral.USER_MENTION); break; } case TwidereLinkify.LINK_TYPE_STATUS: { - Utils.openStatus(context, accountId, NumberUtils.toLong(link, -1)); + Utils.openStatus(context, accountKey, NumberUtils.toLong(link, -1)); break; } } @@ -107,9 +108,9 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { return false; } - protected void openMedia(long accountId, long extraId, boolean sensitive, String link, int start, int end) { + protected void openMedia(AccountKey accountKey, long extraId, boolean sensitive, String link, int start, int end) { final ParcelableMedia[] media = {ParcelableMediaUtils.image(link)}; - IntentUtils.openMedia(context, accountId, sensitive, null, media, null, true); + IntentUtils.openMedia(context, accountKey, sensitive, null, media, null, true); } protected void openLink(final String link) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java index 578734df1..d45516884 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java @@ -21,6 +21,7 @@ package org.mariotaku.twidere.util; import android.content.Context; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; @@ -32,7 +33,8 @@ public class StatusLinkClickHandler extends OnLinkClickHandler { private ParcelableStatus mStatus; @Override - protected void openMedia(long accountId, long extraId, boolean sensitive, String link, int start, int end) { + protected void openMedia(final AccountKey accountId, final long extraId, final boolean sensitive, + final String link, final int start, final int end) { final ParcelableStatus status = mStatus; final ParcelableMedia current = findByLink(status.media, link); if (current.open_browser) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java index 150332e9f..f5da08290 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java @@ -31,6 +31,7 @@ import com.twitter.Extractor.Entity; import com.twitter.Regex; import org.mariotaku.twidere.Constants; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.text.TwidereURLSpan; import java.lang.annotation.Retention; @@ -61,6 +62,7 @@ public final class TwidereLinkify implements Constants { public static final int LINK_TYPE_MENTION = 1; public static final int LINK_TYPE_HASHTAG = 2; + public static final int LINK_TYPE_BANGTAG = 3; public static final int LINK_TYPE_ENTITY_URL = 4; public static final int LINK_TYPE_LINK_IN_TEXT = 5; public static final int LINK_TYPE_LIST = 6; @@ -108,47 +110,47 @@ public final class TwidereLinkify implements Constants { setHighlightOption(highlightOption); } - public SpannableString applyAllLinks(@Nullable CharSequence text, final long accountId, + public SpannableString applyAllLinks(@Nullable CharSequence text, final AccountKey accountKey, final long extraId, final boolean sensitive, final boolean skipLinksInText) { - return applyAllLinks(text, mOnLinkClickListener, accountId, extraId, sensitive, + return applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, mHighlightOption, skipLinksInText); } - public SpannableString applyAllLinks(@Nullable CharSequence text, final long accountId, + public SpannableString applyAllLinks(@Nullable CharSequence text, final AccountKey accountKey, final boolean sensitive, final boolean skipLinksInText) { - return applyAllLinks(text, mOnLinkClickListener, accountId, -1, sensitive, mHighlightOption, skipLinksInText); + return applyAllLinks(text, mOnLinkClickListener, accountKey, -1, sensitive, mHighlightOption, skipLinksInText); } - public SpannableString applyAllLinks(@Nullable CharSequence text, final long accountId, + public SpannableString applyAllLinks(@Nullable CharSequence text, final AccountKey accountKey, final long extraId, final boolean sensitive, final int highlightOption, final boolean skipLinksInText) { - return applyAllLinks(text, mOnLinkClickListener, accountId, extraId, sensitive, highlightOption, skipLinksInText); + return applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, highlightOption, skipLinksInText); } public SpannableString applyAllLinks(@Nullable final CharSequence text, final OnLinkClickListener listener, - final long accountId, final long extraId, final boolean sensitive, + final AccountKey accountKey, final long extraId, final boolean sensitive, final int highlightOption, boolean skipLinksInText) { if (text == null) return null; final SpannableString string = SpannableString.valueOf(text); for (final int type : ALL_LINK_TYPES) { if (type == LINK_TYPE_LINK_IN_TEXT && skipLinksInText) continue; - addLinks(string, accountId, extraId, type, sensitive, listener, highlightOption); + addLinks(string, accountKey, extraId, type, sensitive, listener, highlightOption); } return string; } - public SpannableString applyUserProfileLink(final CharSequence text, final long accountId, final long extraId, + public SpannableString applyUserProfileLink(final CharSequence text, final AccountKey accountKey, final long extraId, final long userId, final String screenName) { - return applyUserProfileLink(text, accountId, extraId, userId, screenName, mHighlightOption); + return applyUserProfileLink(text, accountKey, extraId, userId, screenName, mHighlightOption); } - public SpannableString applyUserProfileLink(final CharSequence text, final long accountId, final long extraId, + public SpannableString applyUserProfileLink(final CharSequence text, final AccountKey accountKey, final long extraId, final long userId, final String screenName, final int highlightOption) { - return applyUserProfileLink(text, accountId, extraId, userId, screenName, highlightOption, mOnLinkClickListener); + return applyUserProfileLink(text, accountKey, extraId, userId, screenName, highlightOption, mOnLinkClickListener); } - public final SpannableString applyUserProfileLink(final CharSequence text, final long accountId, + public final SpannableString applyUserProfileLink(final CharSequence text, final AccountKey accountKey, final long extraId, final long userId, final String screenName, final int highlightOption, final OnLinkClickListener listener) { @@ -158,10 +160,10 @@ public final class TwidereLinkify implements Constants { string.removeSpan(span); } if (userId > 0) { - applyLink(String.valueOf(userId), 0, string.length(), string, accountId, extraId, + applyLink(String.valueOf(userId), 0, string.length(), string, accountKey, extraId, LINK_TYPE_USER_ID, false, highlightOption, listener); } else if (screenName != null) { - applyLink(screenName, 0, string.length(), string, accountId, extraId, + applyLink(screenName, 0, string.length(), string, accountKey, extraId, LINK_TYPE_MENTION, false, highlightOption, listener); } return string; @@ -171,20 +173,20 @@ public final class TwidereLinkify implements Constants { mHighlightOption = style; } - private boolean addCashtagLinks(final Spannable spannable, final long accountId, final long extraId, + private boolean addCashtagLinks(final Spannable spannable, final AccountKey accountKey, final long extraId, final OnLinkClickListener listener, final int highlightOption) { boolean hasMatches = false; for (final Entity entity : mExtractor.extractCashtagsWithIndices(spannable.toString())) { final int start = entity.getStart(); final int end = entity.getEnd(); - applyLink(entity.getValue(), start, end, spannable, accountId, extraId, LINK_TYPE_CASHTAG, + applyLink(entity.getValue(), start, end, spannable, accountKey, extraId, LINK_TYPE_CASHTAG, false, highlightOption, listener); hasMatches = true; } return hasMatches; } - private boolean addHashtagLinks(final Spannable spannable, final long accountId, final long extraId, + private boolean addHashtagLinks(final Spannable spannable, final AccountKey accountId, final long extraId, final OnLinkClickListener listener, final int highlightOption) { boolean hasMatches = false; for (final Entity entity : mExtractor.extractHashtagsWithIndices(spannable.toString())) { @@ -200,15 +202,15 @@ public final class TwidereLinkify implements Constants { /** * Applies a regex to the text of a TextView turning the matches into links. */ - private void addLinks(final SpannableString string, final long accountId, final long extraId, final int type, + private void addLinks(final SpannableString string, final AccountKey accountKey, final long extraId, final int type, final boolean sensitive, final OnLinkClickListener listener, final int highlightOption) { switch (type) { case LINK_TYPE_MENTION: { - addMentionOrListLinks(string, accountId, extraId, highlightOption, listener); + addMentionOrListLinks(string, accountKey, extraId, highlightOption, listener); break; } case LINK_TYPE_HASHTAG: { - addHashtagLinks(string, accountId, extraId, listener, highlightOption); + addHashtagLinks(string, accountKey, extraId, listener, highlightOption); break; } case LINK_TYPE_ENTITY_URL: { @@ -220,7 +222,7 @@ public final class TwidereLinkify implements Constants { continue; } string.removeSpan(span); - applyLink(span.getURL(), start, end, string, accountId, extraId, LINK_TYPE_ENTITY_URL, sensitive, highlightOption, listener); + applyLink(span.getURL(), start, end, string, accountKey, extraId, LINK_TYPE_ENTITY_URL, sensitive, highlightOption, listener); } break; } @@ -232,7 +234,7 @@ public final class TwidereLinkify implements Constants { || string.getSpans(start, end, URLSpan.class).length > 0) { continue; } - applyLink(entity.getValue(), start, end, string, accountId, extraId, LINK_TYPE_ENTITY_URL, sensitive, highlightOption, listener); + applyLink(entity.getValue(), start, end, string, accountKey, extraId, LINK_TYPE_ENTITY_URL, sensitive, highlightOption, listener); } break; } @@ -245,19 +247,19 @@ public final class TwidereLinkify implements Constants { final int end = string.getSpanEnd(span); final String url = matcherGroup(matcher, GROUP_ID_TWITTER_STATUS_STATUS_ID); string.removeSpan(span); - applyLink(url, start, end, string, accountId, extraId, LINK_TYPE_STATUS, sensitive, highlightOption, listener); + applyLink(url, start, end, string, accountKey, extraId, LINK_TYPE_STATUS, sensitive, highlightOption, listener); } } break; } case LINK_TYPE_CASHTAG: { - addCashtagLinks(string, accountId, extraId, listener, highlightOption); + addCashtagLinks(string, accountKey, extraId, listener, highlightOption); break; } } } - private boolean addMentionOrListLinks(final Spannable spannable, final long accountId, + private boolean addMentionOrListLinks(final Spannable spannable, final AccountKey accountKey, final long extraId, final int highlightOption, final OnLinkClickListener listener) { boolean hasMatches = false; // Extract lists from status text @@ -269,11 +271,11 @@ public final class TwidereLinkify implements Constants { final int listEnd = matcherEnd(matcher, Regex.VALID_MENTION_OR_LIST_GROUP_LIST); final String username = matcherGroup(matcher, Regex.VALID_MENTION_OR_LIST_GROUP_USERNAME); final String list = matcherGroup(matcher, Regex.VALID_MENTION_OR_LIST_GROUP_LIST); - applyLink(username, start, username_end, spannable, accountId, extraId, LINK_TYPE_MENTION, + applyLink(username, start, username_end, spannable, accountKey, extraId, LINK_TYPE_MENTION, false, highlightOption, listener); if (listStart >= 0 && listEnd >= 0 && list != null) { applyLink(String.format("%s/%s", username, list.substring(list.startsWith("/") ? 1 : 0)), listStart, - listEnd, spannable, accountId, extraId, LINK_TYPE_LIST, false, highlightOption, listener); + listEnd, spannable, accountKey, extraId, LINK_TYPE_LIST, false, highlightOption, listener); } hasMatches = true; } @@ -287,7 +289,7 @@ public final class TwidereLinkify implements Constants { final String screenName = matcherGroup(m, GROUP_ID_TWITTER_LIST_SCREEN_NAME); final String listName = matcherGroup(m, GROUP_ID_TWITTER_LIST_LIST_NAME); spannable.removeSpan(span); - applyLink(screenName + "/" + listName, start, end, spannable, accountId, extraId, + applyLink(screenName + "/" + listName, start, end, spannable, accountKey, extraId, LINK_TYPE_LIST, false, highlightOption, listener); hasMatches = true; } @@ -296,17 +298,17 @@ public final class TwidereLinkify implements Constants { } private void applyLink(final String url, final String orig, final int start, final int end, - final Spannable text, final long accountId, final long extraId, final int type, final boolean sensitive, + final Spannable text, final AccountKey accountKey, final long extraId, final int type, final boolean sensitive, final int highlightOption, final OnLinkClickListener listener) { - final TwidereURLSpan span = new TwidereURLSpan(url, orig, accountId, extraId, type, sensitive, + final TwidereURLSpan span = new TwidereURLSpan(url, orig, accountKey, extraId, type, sensitive, highlightOption, start, end, listener); text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } private void applyLink(final String url, final int start, final int end, final Spannable text, - final long accountId, final long extraId, final int type, final boolean sensitive, + final AccountKey accountKey, final long extraId, final int type, final boolean sensitive, final int highlightOption, final OnLinkClickListener listener) { - applyLink(url, null, start, end, text, accountId, extraId, type, sensitive, highlightOption, + applyLink(url, null, start, end, text, accountKey, extraId, type, sensitive, highlightOption, listener); } @@ -318,7 +320,7 @@ public final class TwidereLinkify implements Constants { } public interface OnLinkClickListener { - void onLinkClick(String link, String orig, long accountId, long extraId, int type, + void onLinkClick(String link, String orig, AccountKey accountKey, long extraId, int type, boolean sensitive, int start, int end); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 8bf8b56ed..7ba2815af 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -866,7 +866,7 @@ public final class Utils implements Constants { @NonNull public static ParcelableStatus findStatus(final Context context, final AccountKey accountKey, - final String accountHost, final long statusId) + final long statusId) throws TwitterException { if (context == null) throw new NullPointerException(); final ParcelableStatus cached = findStatusInDatabases(context, accountKey, statusId); @@ -1793,23 +1793,24 @@ public final class Utils implements Constants { context.startActivity(intent); } - public static void openStatus(final Context context, final long accountId, final long statusId) { - if (context == null || accountId <= 0 || statusId <= 0) return; - final Uri uri = LinkCreator.getTwidereStatusLink(accountId, statusId); + public static void openStatus(final Context context, final AccountKey accountKey, final long statusId) { + if (context == null || statusId <= 0) return; + final Uri uri = LinkCreator.getTwidereStatusLink(accountKey, statusId); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); context.startActivity(intent); } public static void openStatus(final Context context, final ParcelableStatus status, Bundle activityOptions) { if (context == null || status == null) return; - final long account_id = status.account_id, status_id = status.id; + final AccountKey accountKey = new AccountKey(status.account_id, status.account_host); + final long statusId = status.id; final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_STATUS, status); final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_STATUS); - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id)); - builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(status_id)); + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString()); + builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(statusId)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.setExtrasClassLoader(context.getClassLoader()); intent.putExtras(extras); @@ -1921,7 +1922,7 @@ public final class Utils implements Constants { } - public static void openUserListDetails(final Context context, final long accountId, final long listId, + public static void openUserListDetails(final Context context, final AccountKey accountId, final long listId, final long userId, final String screenName, final String listName) { if (context == null) return; final Uri.Builder builder = new Uri.Builder(); @@ -2505,12 +2506,15 @@ public final class Utils implements Constants { } @Nullable - public static ParcelableUser getUserForConversation(Context context, long accountId, + public static ParcelableUser getUserForConversation(Context context, AccountKey accountKey, long conversationId) { final ContentResolver cr = context.getContentResolver(); - final Expression where = Expression.and(Expression.equals(ConversationEntries.ACCOUNT_ID, accountId), - Expression.equals(ConversationEntries.CONVERSATION_ID, conversationId)); - final Cursor c = cr.query(ConversationEntries.CONTENT_URI, null, where.getSQL(), null, null); + final Expression where = Expression.and(getAccountCompareExpression(), + Expression.equalsArgs(ConversationEntries.CONVERSATION_ID)); + final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost(), + String.valueOf(conversationId)}; + final Cursor c = cr.query(ConversationEntries.CONTENT_URI, null, where.getSQL(), whereArgs, + null); if (c == null) return null; try { if (c.moveToFirst()) return ParcelableUserUtils.fromDirectMessageConversationEntry(c); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java b/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java index a26144f05..ec392e637 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java @@ -1,20 +1,22 @@ package org.mariotaku.twidere.util.media; +import org.mariotaku.twidere.model.AccountKey; + /** * Created by mariotaku on 16/1/28. */ public class MediaExtra { - long accountId; + AccountKey accountKey; boolean useThumbor = true; String fallbackUrl; boolean skipUrlReplacing; - public long getAccountId() { - return accountId; + public AccountKey getAccountKey() { + return accountKey; } - public void setAccountId(long accountId) { - this.accountId = accountId; + public void setAccountKey(AccountKey accountKey) { + this.accountKey = accountKey; } public boolean isUseThumbor() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/media/TwidereMediaDownloader.java b/twidere/src/main/java/org/mariotaku/twidere/util/media/TwidereMediaDownloader.java index b0d5575f9..6963f4d0e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/media/TwidereMediaDownloader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/media/TwidereMediaDownloader.java @@ -118,7 +118,7 @@ public class TwidereMediaDownloader implements MediaDownloader, Constants { final boolean useThumbor; if (extra instanceof MediaExtra) { useThumbor = ((MediaExtra) extra).isUseThumbor(); - account = DataStoreUtils.getCredentials(mContext, ((MediaExtra) extra).getAccountId()); + account = DataStoreUtils.getCredentials(mContext, ((MediaExtra) extra).getAccountKey()); auth = TwitterAPIFactory.getAuthorization(account); } else { useThumbor = true; diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java index d221582b7..ef9ab90e6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java @@ -35,6 +35,7 @@ import android.widget.TextView; import org.apache.commons.lang3.ObjectUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; import org.mariotaku.twidere.util.MediaLoaderWrapper; @@ -90,7 +91,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { public void displayMedia(@Nullable final ParcelableMedia[] mediaArray, @NonNull final MediaLoaderWrapper loader, - final long accountId, final long extraId, + final AccountKey accountId, final long extraId, final OnMediaClickListener mediaClickListener, final MediaLoadingHandler loadingHandler) { displayMedia(mediaArray, loader, accountId, extraId, false, mediaClickListener, @@ -99,7 +100,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { public void displayMedia(@Nullable final ParcelableMedia[] mediaArray, @NonNull final MediaLoaderWrapper loader, - final long accountId, final long extraId, boolean withCredentials, + final AccountKey accountId, final long extraId, boolean withCredentials, final OnMediaClickListener mediaClickListener, final MediaLoadingHandler loadingHandler) { if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) { @@ -300,18 +301,18 @@ public class CardMediaContainer extends ViewGroup implements Constants { } public interface OnMediaClickListener { - void onMediaClick(View view, ParcelableMedia media, long accountId, long id); + void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long id); } private static class ImageGridClickListener implements View.OnClickListener { private final WeakReference mListenerRef; - private final long mAccountId; + private final AccountKey mAccountKey; private final long mExtraId; - ImageGridClickListener(final OnMediaClickListener listener, final long accountId, + ImageGridClickListener(final OnMediaClickListener listener, final AccountKey accountKey, final long extraId) { mListenerRef = new WeakReference<>(listener); - mAccountId = accountId; + mAccountKey = accountKey; mExtraId = extraId; } @@ -319,7 +320,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { public void onClick(final View v) { final OnMediaClickListener listener = mListenerRef.get(); if (listener == null) return; - listener.onMediaClick(v, (ParcelableMedia) v.getTag(), mAccountId, mExtraId); + listener.onMediaClick(v, (ParcelableMedia) v.getTag(), mAccountKey, mExtraId); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java index 09bd2fc86..94eb84cb5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java @@ -27,6 +27,7 @@ import android.widget.ImageView; import org.mariotaku.twidere.adapter.iface.ContentCardClickListener; import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.view.CardMediaContainer; @@ -47,7 +48,7 @@ public interface IStatusViewHolder extends CardMediaContainer.OnMediaClickListen ImageView getProfileTypeView(); @Override - void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId); + void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long extraId); void setStatusClickListener(StatusClickListener listener);