mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-12 09:40:50 +01:00
removed some code
This commit is contained in:
parent
7b7ef16fb2
commit
5d6b5ff882
@ -223,11 +223,6 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
|
||||
|
||||
String ICON_SPECIAL_TYPE_CUSTOMIZE = "_customize";
|
||||
|
||||
String TASK_TAG_GET_HOME_TIMELINE = "get_home_tomeline";
|
||||
String TASK_TAG_GET_MENTIONS = "get_mentions";
|
||||
String TASK_TAG_GET_SENT_DIRECT_MESSAGES = "get_sent_direct_messages";
|
||||
String TASK_TAG_GET_RECEIVED_DIRECT_MESSAGES = "get_received_direct_messages";
|
||||
String TASK_TAG_GET_TRENDS = "get_trends";
|
||||
|
||||
String METADATA_KEY_EXTENSION = "org.mariotaku.twidere.extension";
|
||||
String METADATA_KEY_EXTENSION_PERMISSIONS = "org.mariotaku.twidere.extension.permissions";
|
||||
|
@ -92,7 +92,7 @@ public class RefreshService extends Service implements Constants {
|
||||
break;
|
||||
}
|
||||
case BROADCAST_REFRESH_HOME_TIMELINE: {
|
||||
if (isAutoRefreshAllowed() && !isHomeTimelineRefreshing()) {
|
||||
if (isAutoRefreshAllowed()) {
|
||||
mTwitterWrapper.getHomeTimelineAsync(new SimpleRefreshTaskParam() {
|
||||
private UserKey[] accountIds;
|
||||
|
||||
@ -140,7 +140,7 @@ public class RefreshService extends Service implements Constants {
|
||||
break;
|
||||
}
|
||||
case BROADCAST_REFRESH_DIRECT_MESSAGES: {
|
||||
if (isAutoRefreshAllowed() && !isReceivedDirectMessagesRefreshing()) {
|
||||
if (isAutoRefreshAllowed()) {
|
||||
mTwitterWrapper.getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() {
|
||||
private UserKey[] accountIds;
|
||||
|
||||
@ -313,14 +313,6 @@ public class RefreshService extends Service implements Constants {
|
||||
return Math.max(prefValue, 3) * 60 * 1000;
|
||||
}
|
||||
|
||||
private boolean isHomeTimelineRefreshing() {
|
||||
return mTwitterWrapper.isHomeTimelineRefreshing();
|
||||
}
|
||||
|
||||
private boolean isReceivedDirectMessagesRefreshing() {
|
||||
return mTwitterWrapper.isReceivedDirectMessagesRefreshing();
|
||||
}
|
||||
|
||||
private void rescheduleDirectMessagesRefreshing() {
|
||||
mAlarmManager.cancel(mPendingRefreshDirectMessagesIntent);
|
||||
final long refreshInterval = getRefreshInterval();
|
||||
|
@ -32,6 +32,7 @@ import android.support.v4.util.SimpleArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.apache.commons.collections.primitives.ArrayIntList;
|
||||
import org.apache.commons.collections.primitives.ArrayLongList;
|
||||
@ -69,6 +70,8 @@ import org.mariotaku.twidere.model.SingleResponse;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.message.FavoriteTaskEvent;
|
||||
import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent;
|
||||
import org.mariotaku.twidere.model.message.GetMessagesTaskEvent;
|
||||
import org.mariotaku.twidere.model.message.GetStatusesTaskEvent;
|
||||
import org.mariotaku.twidere.model.message.ProfileUpdatedEvent;
|
||||
import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent;
|
||||
import org.mariotaku.twidere.model.message.StatusDestroyedEvent;
|
||||
@ -111,6 +114,7 @@ import org.mariotaku.twidere.task.GetSavedSearchesTask;
|
||||
import org.mariotaku.twidere.task.ManagedAsyncTask;
|
||||
import org.mariotaku.twidere.task.ReportSpamAndBlockTask;
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesTask;
|
||||
import org.mariotaku.twidere.util.collection.CompactHashSet;
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -126,12 +130,12 @@ import edu.tsinghua.hotmobi.model.TweetEvent;
|
||||
|
||||
public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
private final Context mContext;
|
||||
private final ContentResolver mResolver;
|
||||
private final Context context;
|
||||
private final ContentResolver resolver;
|
||||
|
||||
private final AsyncTaskManager mAsyncTaskManager;
|
||||
private final SharedPreferencesWrapper mPreferences;
|
||||
private final Bus mBus;
|
||||
private final AsyncTaskManager asyncTaskManager;
|
||||
private final SharedPreferencesWrapper preferences;
|
||||
private final Bus bus;
|
||||
|
||||
private IntList mCreatingFavoriteIds = new ArrayIntList();
|
||||
private IntList mDestroyingFavoriteIds = new ArrayIntList();
|
||||
@ -139,33 +143,55 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private IntList mDestroyingStatusIds = new ArrayIntList();
|
||||
private IntList mUpdatingRelationshipIds = new ArrayIntList();
|
||||
|
||||
private final LongList mSendingDraftIds = new ArrayLongList();
|
||||
private final LongList sendingDraftIds = new ArrayLongList();
|
||||
|
||||
private final Set<Uri> getMessageTasks = new CompactHashSet<>();
|
||||
private final Set<Uri> getStatusTasks = new CompactHashSet<>();
|
||||
|
||||
public AsyncTwitterWrapper(Context context, Bus bus, SharedPreferencesWrapper preferences,
|
||||
AsyncTaskManager asyncTaskManager) {
|
||||
mContext = context;
|
||||
mResolver = context.getContentResolver();
|
||||
mBus = bus;
|
||||
mPreferences = preferences;
|
||||
mAsyncTaskManager = asyncTaskManager;
|
||||
this.context = context;
|
||||
resolver = context.getContentResolver();
|
||||
this.bus = bus;
|
||||
this.preferences = preferences;
|
||||
this.asyncTaskManager = asyncTaskManager;
|
||||
bus.register(new Object() {
|
||||
@Subscribe
|
||||
public void onGetDirectMessagesTaskEvent(GetMessagesTaskEvent event) {
|
||||
if (event.running) {
|
||||
getMessageTasks.add(event.uri);
|
||||
} else {
|
||||
getMessageTasks.remove(event.uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGetStatusesTaskEvent(GetStatusesTaskEvent event) {
|
||||
if (event.running) {
|
||||
getStatusTasks.add(event.uri);
|
||||
} else {
|
||||
getStatusTasks.remove(event.uri);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void acceptFriendshipAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final AcceptFriendshipTask task = new AcceptFriendshipTask(mContext);
|
||||
final AcceptFriendshipTask task = new AcceptFriendshipTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void addSendingDraftId(long id) {
|
||||
synchronized (mSendingDraftIds) {
|
||||
mSendingDraftIds.add(id);
|
||||
mResolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null);
|
||||
synchronized (sendingDraftIds) {
|
||||
sendingDraftIds.add(id);
|
||||
resolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null);
|
||||
}
|
||||
}
|
||||
|
||||
public int addUserListMembersAsync(final UserKey accountKey, final String listId, @NonNull final ParcelableUser... users) {
|
||||
final AddUserListMembersTask task = new AddUserListMembersTask(accountKey, listId, users);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int cancelRetweetAsync(UserKey accountKey, String statusId, String myRetweetId) {
|
||||
@ -191,116 +217,116 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public void createBlockAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final CreateUserBlockTask task = new CreateUserBlockTask(mContext);
|
||||
final CreateUserBlockTask task = new CreateUserBlockTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int createFavoriteAsync(final UserKey accountKey, final String statusId) {
|
||||
final CreateFavoriteTask task = new CreateFavoriteTask(accountKey, statusId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public void createFriendshipAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final CreateFriendshipTask task = new CreateFriendshipTask(mContext);
|
||||
final CreateFriendshipTask task = new CreateFriendshipTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int createMultiBlockAsync(final UserKey accountKey, final String[] userIds) {
|
||||
final CreateMultiBlockTask task = new CreateMultiBlockTask(accountKey, userIds);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public void createMuteAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final CreateUserMuteTask task = new CreateUserMuteTask(mContext);
|
||||
final CreateUserMuteTask task = new CreateUserMuteTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int createSavedSearchAsync(final UserKey accountKey, final String query) {
|
||||
final CreateSavedSearchTask task = new CreateSavedSearchTask(accountKey, query);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int createUserListAsync(final UserKey accountKey, final String listName, final boolean isPublic,
|
||||
final String description) {
|
||||
final CreateUserListTask task = new CreateUserListTask(mContext, accountKey, listName, isPublic,
|
||||
final CreateUserListTask task = new CreateUserListTask(context, accountKey, listName, isPublic,
|
||||
description);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int createUserListSubscriptionAsync(final UserKey accountKey, final String listId) {
|
||||
final CreateUserListSubscriptionTask task = new CreateUserListSubscriptionTask(accountKey, listId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int deleteUserListMembersAsync(final UserKey accountKey, final String listId, final ParcelableUser... users) {
|
||||
final DeleteUserListMembersTask task = new DeleteUserListMembersTask(accountKey, listId, users);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public void denyFriendshipAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final DenyFriendshipTask task = new DenyFriendshipTask(mContext);
|
||||
final DenyFriendshipTask task = new DenyFriendshipTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void destroyBlockAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final DestroyUserBlockTask task = new DestroyUserBlockTask(mContext);
|
||||
final DestroyUserBlockTask task = new DestroyUserBlockTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int destroyDirectMessageAsync(final UserKey accountKey, final String messageId) {
|
||||
final DestroyDirectMessageTask task = new DestroyDirectMessageTask(accountKey, messageId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyMessageConversationAsync(final UserKey accountKey, final String userId) {
|
||||
final DestroyMessageConversationTask task = new DestroyMessageConversationTask(accountKey, userId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyFavoriteAsync(final UserKey accountKey, final String statusId) {
|
||||
final DestroyFavoriteTask task = new DestroyFavoriteTask(accountKey, statusId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public void destroyFriendshipAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final DestroyFriendshipTask task = new DestroyFriendshipTask(mContext);
|
||||
final DestroyFriendshipTask task = new DestroyFriendshipTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void destroyMuteAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final DestroyUserMuteTask task = new DestroyUserMuteTask(mContext);
|
||||
final DestroyUserMuteTask task = new DestroyUserMuteTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int destroySavedSearchAsync(final UserKey accountKey, final long searchId) {
|
||||
final DestroySavedSearchTask task = new DestroySavedSearchTask(accountKey, searchId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyStatusAsync(final UserKey accountKey, final String statusId) {
|
||||
final DestroyStatusTask task = new DestroyStatusTask(accountKey, statusId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyUserListAsync(final UserKey accountKey, final String listId) {
|
||||
final DestroyUserListTask task = new DestroyUserListTask(mContext, accountKey, listId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
final DestroyUserListTask task = new DestroyUserListTask(context, accountKey, listId);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyUserListSubscriptionAsync(final UserKey accountKey, final String listId) {
|
||||
final DestroyUserListSubscriptionTask task = new DestroyUserListSubscriptionTask(accountKey, listId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
return context;
|
||||
}
|
||||
|
||||
public boolean getHomeTimelineAsync(RefreshTaskParam param) {
|
||||
@ -311,31 +337,31 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public void getLocalTrendsAsync(final UserKey accountId, final int woeid) {
|
||||
final GetLocalTrendsTask task = new GetLocalTrendsTask(mContext, accountId, woeid);
|
||||
final GetLocalTrendsTask task = new GetLocalTrendsTask(context, accountId, woeid);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void getReceivedDirectMessagesAsync(RefreshTaskParam param) {
|
||||
final GetReceivedDirectMessagesTask task = new GetReceivedDirectMessagesTask(mContext);
|
||||
final GetReceivedDirectMessagesTask task = new GetReceivedDirectMessagesTask(context);
|
||||
task.setParams(param);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void getSentDirectMessagesAsync(RefreshTaskParam param) {
|
||||
final GetSentDirectMessagesTask task = new GetSentDirectMessagesTask(mContext);
|
||||
final GetSentDirectMessagesTask task = new GetSentDirectMessagesTask(context);
|
||||
task.setParams(param);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public void getSavedSearchesAsync(UserKey[] accountKeys) {
|
||||
final GetSavedSearchesTask task = new GetSavedSearchesTask(mContext);
|
||||
final GetSavedSearchesTask task = new GetSavedSearchesTask(context);
|
||||
task.setParams(accountKeys);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public long[] getSendingDraftIds() {
|
||||
return mSendingDraftIds.toArray();
|
||||
return sendingDraftIds.toArray();
|
||||
}
|
||||
|
||||
public boolean isCreatingFavorite(@Nullable final UserKey accountId, @Nullable final String statusId) {
|
||||
@ -358,23 +384,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return (accountId == null ? 0 : accountId.hashCode()) ^ (statusId == null ? 0 : statusId.hashCode());
|
||||
}
|
||||
|
||||
public boolean isHomeTimelineRefreshing() {
|
||||
return mAsyncTaskManager.hasRunningTasksForTag(TASK_TAG_GET_HOME_TIMELINE);
|
||||
}
|
||||
|
||||
public boolean isReceivedDirectMessagesRefreshing() {
|
||||
return mAsyncTaskManager.hasRunningTasksForTag(TASK_TAG_GET_RECEIVED_DIRECT_MESSAGES);
|
||||
}
|
||||
|
||||
public boolean isSentDirectMessagesRefreshing() {
|
||||
return mAsyncTaskManager.hasRunningTasksForTag(TASK_TAG_GET_SENT_DIRECT_MESSAGES);
|
||||
public boolean isStatusTimelineRefreshing(Uri uri) {
|
||||
return getStatusTasks.contains(uri);
|
||||
}
|
||||
|
||||
public void refreshAll() {
|
||||
refreshAll(new GetAccountKeysClosure() {
|
||||
@Override
|
||||
public UserKey[] getAccountKeys() {
|
||||
return DataStoreUtils.getActivatedAccountKeys(mContext);
|
||||
return DataStoreUtils.getActivatedAccountKeys(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -400,11 +418,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getSinceIds() {
|
||||
return DataStoreUtils.getNewestStatusIds(mContext, Statuses.CONTENT_URI,
|
||||
return DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI,
|
||||
getAccountKeys());
|
||||
}
|
||||
});
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_MENTIONS)) {
|
||||
if (preferences.getBoolean(KEY_HOME_REFRESH_MENTIONS)) {
|
||||
getActivitiesAboutMeAsync(new SimpleRefreshTaskParam() {
|
||||
@NonNull
|
||||
@Override
|
||||
@ -415,12 +433,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getSinceIds() {
|
||||
return DataStoreUtils.getNewestActivityMaxPositions(mContext,
|
||||
return DataStoreUtils.getNewestActivityMaxPositions(context,
|
||||
Activities.AboutMe.CONTENT_URI, getAccountKeys());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES)) {
|
||||
if (preferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES)) {
|
||||
getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() {
|
||||
@NonNull
|
||||
@Override
|
||||
@ -436,16 +454,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_SAVED_SEARCHES)) {
|
||||
if (preferences.getBoolean(KEY_HOME_REFRESH_SAVED_SEARCHES)) {
|
||||
getSavedSearchesAsync(closure.getAccountKeys());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeSendingDraftId(long id) {
|
||||
synchronized (mSendingDraftIds) {
|
||||
mSendingDraftIds.removeElement(id);
|
||||
mResolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null);
|
||||
synchronized (sendingDraftIds) {
|
||||
sendingDraftIds.removeElement(id);
|
||||
resolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -459,33 +477,33 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public void reportSpamAsync(final UserKey accountKey, final UserKey userKey) {
|
||||
final ReportSpamAndBlockTask task = new ReportSpamAndBlockTask(mContext);
|
||||
final ReportSpamAndBlockTask task = new ReportSpamAndBlockTask(context);
|
||||
task.setup(accountKey, userKey);
|
||||
TaskStarter.execute(task);
|
||||
}
|
||||
|
||||
public int retweetStatusAsync(final UserKey accountKey, final String statusId) {
|
||||
final RetweetStatusTask task = new RetweetStatusTask(accountKey, statusId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int sendDirectMessageAsync(final UserKey accountKey, final String recipientId, final String text,
|
||||
final String imageUri) {
|
||||
final Intent intent = new Intent(mContext, BackgroundOperationService.class);
|
||||
final Intent intent = new Intent(context, BackgroundOperationService.class);
|
||||
intent.setAction(INTENT_ACTION_SEND_DIRECT_MESSAGE);
|
||||
intent.putExtra(EXTRA_ACCOUNT_KEY, accountKey);
|
||||
intent.putExtra(EXTRA_RECIPIENT_ID, recipientId);
|
||||
intent.putExtra(EXTRA_TEXT, text);
|
||||
intent.putExtra(EXTRA_IMAGE_URI, imageUri);
|
||||
mContext.startService(intent);
|
||||
context.startService(intent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int updateUserListDetails(final UserKey accountKey, final String listId,
|
||||
final UserListUpdate update) {
|
||||
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(mContext, accountKey,
|
||||
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(context, accountKey,
|
||||
listId, update);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public static <T extends Response<?>> Exception getException(List<T> responses) {
|
||||
@ -496,12 +514,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public void updateFriendship(final UserKey accountKey, final UserKey userKey, final FriendshipUpdate update) {
|
||||
final Bus bus = mBus;
|
||||
final Bus bus = this.bus;
|
||||
if (bus == null) return;
|
||||
TaskStarter.execute(new AbstractTask<Object, SingleResponse<Relationship>, Bus>() {
|
||||
@Override
|
||||
public SingleResponse<Relationship> doLongOperation(Object param) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, accountKey, true);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountKey, true);
|
||||
try {
|
||||
final Relationship relationship = twitter.updateFriendship(userKey.getId(), update);
|
||||
if (!relationship.isSourceWantRetweetsFromTarget()) {
|
||||
@ -511,7 +529,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)
|
||||
);
|
||||
final String[] selectionArgs = {accountKey.toString(), userKey.toString()};
|
||||
mContext.getContentResolver().delete(Statuses.CONTENT_URI, where.getSQL(), selectionArgs);
|
||||
context.getContentResolver().delete(Statuses.CONTENT_URI, where.getSQL(), selectionArgs);
|
||||
}
|
||||
return SingleResponse.Companion.getInstance(relationship);
|
||||
} catch (MicroBlogException e) {
|
||||
@ -544,8 +562,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
public Object doLongOperation(Object o) {
|
||||
for (UserKey accountId : accountKeys) {
|
||||
MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, accountId, false);
|
||||
if (!Utils.isOfficialCredentials(mContext, accountId)) continue;
|
||||
MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountId, false);
|
||||
if (!Utils.isOfficialCredentials(context, accountId)) continue;
|
||||
try {
|
||||
twitter.setActivitiesAboutMeUnread(cursor);
|
||||
} catch (MicroBlogException e) {
|
||||
@ -635,7 +653,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
public AddUserListMembersTask(@NonNull final UserKey accountKey,
|
||||
final String listId,
|
||||
@NonNull final ParcelableUser[] users) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mListId = listId;
|
||||
this.mUsers = users;
|
||||
@ -643,7 +661,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserKey[] userIds = new UserKey[mUsers.length];
|
||||
@ -668,15 +686,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = mUserColorNameManager.getDisplayName(user.key, user.name,
|
||||
user.screen_name, nameFirst);
|
||||
message = mContext.getString(R.string.added_user_to_list, displayName, result.getData().name);
|
||||
message = context.getString(R.string.added_user_to_list, displayName, result.getData().name);
|
||||
} else {
|
||||
final Resources res = mContext.getResources();
|
||||
final Resources res = context.getResources();
|
||||
message = res.getQuantityString(R.plurals.added_N_users_to_list, mUsers.length, mUsers.length,
|
||||
result.getData().name);
|
||||
}
|
||||
Utils.showOkMessage(mContext, message, false);
|
||||
Utils.showOkMessage(context, message, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_adding_member, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_adding_member, result.getException(), true);
|
||||
}
|
||||
bus.post(new UserListMembersChangedEvent(UserListMembersChangedEvent.Action.ADDED,
|
||||
result.getData(), mUsers));
|
||||
@ -696,7 +714,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(final Object... params) {
|
||||
return clearNotification(mContext, notificationType, accountKey);
|
||||
return clearNotification(context, notificationType, accountKey);
|
||||
}
|
||||
|
||||
}
|
||||
@ -710,7 +728,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(final Object... params) {
|
||||
return clearUnreadCount(mContext, position);
|
||||
return clearUnreadCount(context, position);
|
||||
}
|
||||
|
||||
}
|
||||
@ -721,16 +739,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mStatusId;
|
||||
|
||||
public CreateFavoriteTask(final UserKey accountKey, final String statusId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mStatusId = statusId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext, mAccountKey);
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, credentials, true, true);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final ParcelableStatus result;
|
||||
@ -747,7 +765,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
|
||||
mUserColorNameManager);
|
||||
Utils.setLastSeen(mContext, result.mentions, System.currentTimeMillis());
|
||||
Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(Statuses.IS_FAVORITE, true);
|
||||
values.put(Statuses.REPLY_COUNT, result.reply_count);
|
||||
@ -763,9 +781,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
final String[] statusWhereArgs = {mAccountKey.toString(), String.valueOf(mStatusId),
|
||||
String.valueOf(mStatusId)};
|
||||
for (final Uri uri : TwidereDataStore.STATUSES_URIS) {
|
||||
mResolver.update(uri, values, statusWhere, statusWhereArgs);
|
||||
resolver.update(uri, values, statusWhere, statusWhereArgs);
|
||||
}
|
||||
DataStoreUtils.updateActivityStatus(mResolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
DataStoreUtils.updateActivityStatus(resolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
@Override
|
||||
public void process(ParcelableActivity activity) {
|
||||
ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
|
||||
@ -819,7 +837,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
// END HotMobi
|
||||
} else {
|
||||
taskEvent.setSucceeded(false);
|
||||
Utils.showErrorMessage(mContext, R.string.action_favoriting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_favoriting, result.getException(), true);
|
||||
}
|
||||
bus.post(taskEvent);
|
||||
bus.post(new StatusListChangedEvent());
|
||||
@ -834,7 +852,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String[] mUserIds;
|
||||
|
||||
public CreateMultiBlockTask(final UserKey accountKey, final String[] userIds) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mUserIds = userIds;
|
||||
}
|
||||
@ -853,13 +871,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
values.put(CachedRelationships.FOLLOWED_BY, false);
|
||||
final String where = Expression.inArgs(CachedRelationships.USER_KEY, list.size()).getSQL();
|
||||
final String[] selectionArgs = list.toArray(new String[list.size()]);
|
||||
mResolver.update(CachedRelationships.CONTENT_URI, values, where, selectionArgs);
|
||||
resolver.update(CachedRelationships.CONTENT_URI, values, where, selectionArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListResponse<String> doInBackground(final Object... params) {
|
||||
final List<String> blockedUsers = new ArrayList<>();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter != null) {
|
||||
for (final String userId : mUserIds) {
|
||||
try {
|
||||
@ -878,11 +896,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final ListResponse<String> result) {
|
||||
if (result.hasData()) {
|
||||
Utils.showInfoMessage(mContext, R.string.users_blocked, false);
|
||||
Utils.showInfoMessage(context, R.string.users_blocked, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_blocking, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_blocking, result.getException(), true);
|
||||
}
|
||||
mBus.post(new UsersBlockedEvent(mAccountKey, mUserIds));
|
||||
AsyncTwitterWrapper.this.bus.post(new UsersBlockedEvent(mAccountKey, mUserIds));
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
||||
@ -895,14 +913,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mQuery;
|
||||
|
||||
CreateSavedSearchTask(final UserKey accountKey, final String query) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mQuery = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<SavedSearch> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return null;
|
||||
try {
|
||||
return SingleResponse.Companion.getInstance(twitter.createSavedSearch(mQuery));
|
||||
@ -914,16 +932,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<SavedSearch> result) {
|
||||
if (result.hasData()) {
|
||||
final String message = mContext.getString(R.string.search_name_saved, result.getData().getQuery());
|
||||
Utils.showOkMessage(mContext, message, false);
|
||||
final String message = context.getString(R.string.search_name_saved, result.getData().getQuery());
|
||||
Utils.showOkMessage(context, message, false);
|
||||
} else if (result.hasException()) {
|
||||
final Exception exception = result.getException();
|
||||
// https://github.com/TwidereProject/Twidere-Android/issues/244
|
||||
if (exception instanceof MicroBlogException && ((MicroBlogException) exception).getStatusCode() == 403) {
|
||||
final String desc = mContext.getString(R.string.saved_searches_already_saved_hint);
|
||||
Utils.showErrorMessage(mContext, R.string.action_saving_search, desc, false);
|
||||
final String desc = context.getString(R.string.saved_searches_already_saved_hint);
|
||||
Utils.showErrorMessage(context, R.string.action_saving_search, desc, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_saving_search, exception, false);
|
||||
Utils.showErrorMessage(context, R.string.action_saving_search, exception, false);
|
||||
}
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
@ -937,14 +955,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mListId;
|
||||
|
||||
public CreateUserListSubscriptionTask(final UserKey accountKey, final String listId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mListId = listId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserList userList = twitter.createUserListSubscription(mListId);
|
||||
@ -959,12 +977,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUserList> result) {
|
||||
final boolean succeed = result.hasData();
|
||||
if (succeed) {
|
||||
final String message = mContext.getString(R.string.subscribed_to_list, result.getData().name);
|
||||
Utils.showOkMessage(mContext, message, false);
|
||||
final String message = context.getString(R.string.subscribed_to_list, result.getData().name);
|
||||
Utils.showOkMessage(context, message, false);
|
||||
bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.SUBSCRIBE,
|
||||
result.getData()));
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_subscribing_to_list, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_subscribing_to_list, result.getException(), true);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
@ -1026,7 +1044,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final ParcelableUser[] users;
|
||||
|
||||
public DeleteUserListMembersTask(final UserKey accountKey, final String userListId, final ParcelableUser[] users) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mUserListId = userListId;
|
||||
this.users = users;
|
||||
@ -1034,7 +1052,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserKey[] userIds = new UserKey[users.length];
|
||||
@ -1059,18 +1077,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = mUserColorNameManager.getDisplayName(user.key,
|
||||
user.name, user.screen_name, nameFirst);
|
||||
message = mContext.getString(R.string.deleted_user_from_list, displayName,
|
||||
message = context.getString(R.string.deleted_user_from_list, displayName,
|
||||
result.getData().name);
|
||||
} else {
|
||||
final Resources res = mContext.getResources();
|
||||
final Resources res = context.getResources();
|
||||
message = res.getQuantityString(R.plurals.deleted_N_users_from_list, users.length, users.length,
|
||||
result.getData().name);
|
||||
}
|
||||
bus.post(new UserListMembersChangedEvent(UserListMembersChangedEvent.Action.REMOVED,
|
||||
result.getData(), users));
|
||||
Utils.showInfoMessage(mContext, message, false);
|
||||
Utils.showInfoMessage(context, message, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
@ -1084,7 +1102,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mMessageId;
|
||||
|
||||
public DestroyDirectMessageTask(final UserKey accountKey, final String messageId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mMessageId = messageId;
|
||||
}
|
||||
@ -1093,8 +1111,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
final String where = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(DirectMessages.MESSAGE_ID)).getSQL();
|
||||
final String[] whereArgs = new String[]{mAccountKey.toString(), mMessageId};
|
||||
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, where, whereArgs);
|
||||
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, where, whereArgs);
|
||||
resolver.delete(DirectMessages.Inbox.CONTENT_URI, where, whereArgs);
|
||||
resolver.delete(DirectMessages.Outbox.CONTENT_URI, where, whereArgs);
|
||||
}
|
||||
|
||||
private boolean isMessageNotFound(final Exception e) {
|
||||
@ -1106,7 +1124,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<DirectMessage> doInBackground(final Object... args) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final DirectMessage message = twitter.destroyDirectMessage(mMessageId);
|
||||
@ -1126,9 +1144,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
super.onPostExecute(result);
|
||||
if (result == null) return;
|
||||
if (result.hasData() || isMessageNotFound(result.getException())) {
|
||||
Utils.showInfoMessage(mContext, R.string.direct_message_deleted, false);
|
||||
Utils.showInfoMessage(context, R.string.direct_message_deleted, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1142,18 +1160,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final UserKey mAccountKey;
|
||||
|
||||
public DestroyMessageConversationTask(final UserKey accountKey, final String userId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mUserId = userId;
|
||||
}
|
||||
|
||||
private void deleteMessages(final UserKey accountKey, final String userId) {
|
||||
final String[] whereArgs = {accountKey.toString(), userId};
|
||||
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and(
|
||||
resolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and(
|
||||
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Inbox.SENDER_ID)
|
||||
).getSQL(), whereArgs);
|
||||
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, Expression.and(
|
||||
resolver.delete(DirectMessages.Outbox.CONTENT_URI, Expression.and(
|
||||
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Outbox.RECIPIENT_ID)
|
||||
).getSQL(), whereArgs);
|
||||
@ -1168,7 +1186,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<Void> doInBackground(final Object... args) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
twitter.destroyDirectMessagesConversation(mAccountKey.getId(), mUserId);
|
||||
@ -1188,9 +1206,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
super.onPostExecute(result);
|
||||
if (result == null) return;
|
||||
if (result.hasData() || isMessageNotFound(result.getException())) {
|
||||
Utils.showInfoMessage(mContext, R.string.direct_message_deleted, false);
|
||||
Utils.showInfoMessage(context, R.string.direct_message_deleted, false);
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1205,16 +1223,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mStatusId;
|
||||
|
||||
public DestroyFavoriteTask(@NonNull final UserKey accountKey, final String statusId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mStatusId = statusId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext, mAccountKey);
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, credentials, true, true);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final ParcelableStatus result;
|
||||
@ -1240,10 +1258,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
Expression.equalsArgs(Statuses.RETWEET_ID)));
|
||||
final String[] whereArgs = {mAccountKey.toString(), mStatusId, mStatusId};
|
||||
for (final Uri uri : TwidereDataStore.STATUSES_URIS) {
|
||||
mResolver.update(uri, values, where.getSQL(), whereArgs);
|
||||
resolver.update(uri, values, where.getSQL(), whereArgs);
|
||||
}
|
||||
|
||||
DataStoreUtils.updateActivityStatus(mResolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
DataStoreUtils.updateActivityStatus(resolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
@Override
|
||||
public void process(ParcelableActivity activity) {
|
||||
ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
|
||||
@ -1291,10 +1309,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
tweetEvent.setAction(TweetEvent.Action.UNFAVORITE);
|
||||
HotMobiLogger.getInstance(getContext()).log(mAccountKey, tweetEvent);
|
||||
// END HotMobi
|
||||
Utils.showInfoMessage(mContext, R.string.status_unfavorited, false);
|
||||
Utils.showInfoMessage(context, R.string.status_unfavorited, false);
|
||||
} else {
|
||||
taskEvent.setSucceeded(false);
|
||||
Utils.showErrorMessage(mContext, R.string.action_unfavoriting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_unfavoriting, result.getException(), true);
|
||||
}
|
||||
bus.post(taskEvent);
|
||||
bus.post(new StatusListChangedEvent());
|
||||
@ -1309,14 +1327,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final long mSearchId;
|
||||
|
||||
DestroySavedSearchTask(final UserKey accountKey, final long searchId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mSearchId = searchId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<SavedSearch> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
return SingleResponse.Companion.getInstance(twitter.destroySavedSearch(mSearchId));
|
||||
@ -1328,11 +1346,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<SavedSearch> result) {
|
||||
if (result.hasData()) {
|
||||
final String message = mContext.getString(R.string.search_name_deleted, result.getData().getQuery());
|
||||
Utils.showOkMessage(mContext, message, false);
|
||||
final String message = context.getString(R.string.search_name_deleted, result.getData().getQuery());
|
||||
Utils.showOkMessage(context, message, false);
|
||||
bus.post(new SavedSearchDestroyedEvent(mAccountKey, mSearchId));
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_deleting_search, result.getException(), false);
|
||||
Utils.showErrorMessage(context, R.string.action_deleting_search, result.getException(), false);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
@ -1345,17 +1363,17 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mStatusId;
|
||||
|
||||
public DestroyStatusTask(final UserKey accountKey, final String statusId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mStatusId = statusId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext,
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, credentials, true,
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true,
|
||||
true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
ParcelableStatus status = null;
|
||||
@ -1368,9 +1386,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
} catch (final MicroBlogException e) {
|
||||
exception = e;
|
||||
}
|
||||
if (status != null || (exception != null && exception.getErrorCode() == ErrorInfo.STATUS_NOT_FOUND)) {
|
||||
DataStoreUtils.deleteStatus(mResolver, mAccountKey, mStatusId, status);
|
||||
DataStoreUtils.deleteActivityStatus(mResolver, mAccountKey, mStatusId, status);
|
||||
if (status != null || (exception.getErrorCode() == ErrorInfo.STATUS_NOT_FOUND)) {
|
||||
DataStoreUtils.deleteStatus(resolver, mAccountKey, mStatusId, status);
|
||||
DataStoreUtils.deleteActivityStatus(resolver, mAccountKey, mStatusId, status);
|
||||
}
|
||||
return SingleResponse.Companion.getInstance(status);
|
||||
}
|
||||
@ -1391,13 +1409,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
if (result.hasData()) {
|
||||
final ParcelableStatus status = result.getData();
|
||||
if (status.retweet_id != null) {
|
||||
Utils.showInfoMessage(mContext, R.string.retweet_cancelled, false);
|
||||
Utils.showInfoMessage(context, R.string.retweet_cancelled, false);
|
||||
} else {
|
||||
Utils.showInfoMessage(mContext, R.string.status_deleted, false);
|
||||
Utils.showInfoMessage(context, R.string.status_deleted, false);
|
||||
}
|
||||
bus.post(new StatusDestroyedEvent(status));
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
@ -1410,7 +1428,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mListId;
|
||||
|
||||
public DestroyUserListSubscriptionTask(@NonNull final UserKey accountKey, final String listId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
mAccountKey = accountKey;
|
||||
mListId = listId;
|
||||
}
|
||||
@ -1418,7 +1436,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserList userList = twitter.destroyUserListSubscription(mListId);
|
||||
@ -1433,12 +1451,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUserList> result) {
|
||||
final boolean succeed = result.hasData();
|
||||
if (succeed) {
|
||||
final String message = mContext.getString(R.string.unsubscribed_from_list, result.getData().name);
|
||||
Utils.showOkMessage(mContext, message, false);
|
||||
final String message = context.getString(R.string.unsubscribed_from_list, result.getData().name);
|
||||
Utils.showOkMessage(context, message, false);
|
||||
bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.UNSUBSCRIBE,
|
||||
result.getData()));
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_unsubscribing_from_list, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_unsubscribing_from_list, result.getException(), true);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
@ -1542,7 +1560,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public SharedPreferencesWrapper getPreferences() {
|
||||
return mPreferences;
|
||||
return preferences;
|
||||
}
|
||||
|
||||
final class RemoveUnreadCountsTask extends AsyncTask<Object, Object, Integer> {
|
||||
@ -1556,7 +1574,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(final Object... params) {
|
||||
return removeUnreadCounts(mContext, position, counts);
|
||||
return removeUnreadCounts(context, position, counts);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1567,17 +1585,17 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final String mStatusId;
|
||||
|
||||
public RetweetStatusTask(@NonNull final UserKey accountKey, final String statusId) {
|
||||
super(mContext);
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mStatusId = statusId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext,
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, credentials, true, true);
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) {
|
||||
return SingleResponse.Companion.getInstance();
|
||||
}
|
||||
@ -1586,7 +1604,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
mAccountKey, false);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
|
||||
mUserColorNameManager);
|
||||
Utils.setLastSeen(mContext, result.mentions, System.currentTimeMillis());
|
||||
Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(Statuses.MY_RETWEET_ID, result.id);
|
||||
values.put(Statuses.REPLY_COUNT, result.reply_count);
|
||||
@ -1598,9 +1616,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
);
|
||||
final String[] whereArgs = {mStatusId, mStatusId};
|
||||
for (final Uri uri : TwidereDataStore.STATUSES_URIS) {
|
||||
mResolver.update(uri, values, where.getSQL(), whereArgs);
|
||||
resolver.update(uri, values, where.getSQL(), whereArgs);
|
||||
}
|
||||
DataStoreUtils.updateActivityStatus(mResolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
DataStoreUtils.updateActivityStatus(resolver, mAccountKey, mStatusId, new DataStoreUtils.UpdateActivityAction() {
|
||||
@Override
|
||||
public void process(ParcelableActivity activity) {
|
||||
ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
|
||||
@ -1649,7 +1667,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
bus.post(new StatusRetweetedEvent(status));
|
||||
} else {
|
||||
Utils.showErrorMessage(mContext, R.string.action_retweeting, result.getException(), true);
|
||||
Utils.showErrorMessage(context, R.string.action_retweeting, result.getException(), true);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
@ -232,6 +232,7 @@ public class InternalTwitterContentUtils {
|
||||
|
||||
String text = status.getFullText();
|
||||
CodePointArray source;
|
||||
// Display text range
|
||||
int[] range = null;
|
||||
if (text == null) {
|
||||
text = status.getText();
|
||||
|
@ -27,7 +27,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.WorkerThread;
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
@ -161,50 +160,41 @@ public class UserColorNameManager implements TwidereConstants {
|
||||
new String[]{userKey});
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(final ParcelableUser user, final boolean nameFirst) {
|
||||
return getDisplayName(user.key, user.name, user.screen_name, nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(final User user, final boolean nameFirst) {
|
||||
return getDisplayName(UserKeyUtils.fromUser(user), user.getName(), user.getScreenName(), nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(final ParcelableUserList user, final boolean nameFirst) {
|
||||
return getDisplayName(user.user_key, user.user_name, user.user_screen_name, nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(final ParcelableStatus status, final boolean nameFirst) {
|
||||
return getDisplayName(status.user_key, status.user_name, status.user_screen_name, nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(@NonNull final UserKey userId, final String name,
|
||||
final String screenName, final boolean nameFirst) {
|
||||
return getDisplayName(userId.toString(), name, screenName, nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getDisplayName(@NonNull final String userId, final String name,
|
||||
final String screenName, final boolean nameFirst) {
|
||||
final String nick = getUserNicknameInternal(userId);
|
||||
return decideDisplayName(nick, name, screenName, nameFirst);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public int getUserColor(@NonNull final UserKey userId) {
|
||||
return getUserColor(userId.toString());
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public int getUserColor(@NonNull final String userId) {
|
||||
return mColorPreferences.getInt(userId, Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getUserNickname(@NonNull final UserKey userKey) {
|
||||
final String userKeyString = userKey.toString();
|
||||
if (mNicknamePreferences.contains(userKey.getId())) {
|
||||
@ -218,13 +208,11 @@ public class UserColorNameManager implements TwidereConstants {
|
||||
return mNicknamePreferences.getString(userKeyString, null);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getUserNickname(@NonNull final UserKey userId, final String name) {
|
||||
final String nick = getUserNickname(userId);
|
||||
return decideNickname(nick, name);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public String getUserNickname(@NonNull final String userId, final String name) {
|
||||
final String nick = getUserNicknameInternal(userId);
|
||||
return decideNickname(nick, name);
|
||||
@ -234,7 +222,6 @@ public class UserColorNameManager implements TwidereConstants {
|
||||
return mNicknamePreferences.getAll().entrySet();
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private String getUserNicknameInternal(@NonNull final String userId) {
|
||||
return mNicknamePreferences.getString(userId, null);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
||||
|
||||
protected abstract val errorInfoKey: String
|
||||
|
||||
private var mContentObserver: ContentObserver? = null
|
||||
private var contentObserver: ContentObserver? = null
|
||||
|
||||
abstract val contentUri: Uri
|
||||
|
||||
@ -125,13 +125,13 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val cr = contentResolver
|
||||
mContentObserver = object : ContentObserver(Handler()) {
|
||||
contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
reloadActivities()
|
||||
}
|
||||
}
|
||||
cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver!!)
|
||||
cr.registerContentObserver(Filters.CONTENT_URI, true, mContentObserver!!)
|
||||
cr.registerContentObserver(Accounts.CONTENT_URI, true, contentObserver!!)
|
||||
cr.registerContentObserver(Filters.CONTENT_URI, true, contentObserver!!)
|
||||
updateRefreshState()
|
||||
reloadActivities()
|
||||
}
|
||||
@ -149,7 +149,7 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
||||
|
||||
override fun onStop() {
|
||||
val cr = contentResolver
|
||||
cr.unregisterContentObserver(mContentObserver!!)
|
||||
cr.unregisterContentObserver(contentObserver!!)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,6 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
|
||||
bus.register(this)
|
||||
val adapter = adapter
|
||||
adapter!!.updateReadState()
|
||||
updateRefreshState()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
@ -298,10 +297,6 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
|
||||
return DataStoreUtils.getActivatedAccountKeys(getActivity())
|
||||
}
|
||||
|
||||
protected fun updateRefreshState() {
|
||||
refreshing = twitterWrapper.isReceivedDirectMessagesRefreshing || twitterWrapper.isSentDirectMessagesRefreshing
|
||||
}
|
||||
|
||||
private fun addReadPosition(firstVisibleItem: Int) {
|
||||
if (mFirstVisibleItem != firstVisibleItem) {
|
||||
mReadPositions.add(firstVisibleItem)
|
||||
|
@ -52,7 +52,7 @@ class HomeTimelineFragment : CursorStatusesFragment() {
|
||||
|
||||
override fun updateRefreshState() {
|
||||
val twitter = twitterWrapper
|
||||
refreshing = twitter.isHomeTimelineRefreshing
|
||||
refreshing = twitter.isStatusTimelineRefreshing(contentUri)
|
||||
}
|
||||
|
||||
override fun getStatuses(param: RefreshTaskParam): Boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user