removed some code

This commit is contained in:
Mariotaku Lee 2016-08-28 11:51:46 +08:00
parent 7b7ef16fb2
commit 5d6b5ff882
8 changed files with 187 additions and 199 deletions

View File

@ -223,11 +223,6 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String ICON_SPECIAL_TYPE_CUSTOMIZE = "_customize"; 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 = "org.mariotaku.twidere.extension";
String METADATA_KEY_EXTENSION_PERMISSIONS = "org.mariotaku.twidere.extension.permissions"; String METADATA_KEY_EXTENSION_PERMISSIONS = "org.mariotaku.twidere.extension.permissions";

View File

@ -92,7 +92,7 @@ public class RefreshService extends Service implements Constants {
break; break;
} }
case BROADCAST_REFRESH_HOME_TIMELINE: { case BROADCAST_REFRESH_HOME_TIMELINE: {
if (isAutoRefreshAllowed() && !isHomeTimelineRefreshing()) { if (isAutoRefreshAllowed()) {
mTwitterWrapper.getHomeTimelineAsync(new SimpleRefreshTaskParam() { mTwitterWrapper.getHomeTimelineAsync(new SimpleRefreshTaskParam() {
private UserKey[] accountIds; private UserKey[] accountIds;
@ -140,7 +140,7 @@ public class RefreshService extends Service implements Constants {
break; break;
} }
case BROADCAST_REFRESH_DIRECT_MESSAGES: { case BROADCAST_REFRESH_DIRECT_MESSAGES: {
if (isAutoRefreshAllowed() && !isReceivedDirectMessagesRefreshing()) { if (isAutoRefreshAllowed()) {
mTwitterWrapper.getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() { mTwitterWrapper.getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() {
private UserKey[] accountIds; private UserKey[] accountIds;
@ -313,14 +313,6 @@ public class RefreshService extends Service implements Constants {
return Math.max(prefValue, 3) * 60 * 1000; return Math.max(prefValue, 3) * 60 * 1000;
} }
private boolean isHomeTimelineRefreshing() {
return mTwitterWrapper.isHomeTimelineRefreshing();
}
private boolean isReceivedDirectMessagesRefreshing() {
return mTwitterWrapper.isReceivedDirectMessagesRefreshing();
}
private void rescheduleDirectMessagesRefreshing() { private void rescheduleDirectMessagesRefreshing() {
mAlarmManager.cancel(mPendingRefreshDirectMessagesIntent); mAlarmManager.cancel(mPendingRefreshDirectMessagesIntent);
final long refreshInterval = getRefreshInterval(); final long refreshInterval = getRefreshInterval();

View File

@ -32,6 +32,7 @@ import android.support.v4.util.SimpleArrayMap;
import android.util.Log; import android.util.Log;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import org.apache.commons.collections.primitives.ArrayIntList; import org.apache.commons.collections.primitives.ArrayIntList;
import org.apache.commons.collections.primitives.ArrayLongList; 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.UserKey;
import org.mariotaku.twidere.model.message.FavoriteTaskEvent; import org.mariotaku.twidere.model.message.FavoriteTaskEvent;
import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent; 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.ProfileUpdatedEvent;
import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent; import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent;
import org.mariotaku.twidere.model.message.StatusDestroyedEvent; 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.ManagedAsyncTask;
import org.mariotaku.twidere.task.ReportSpamAndBlockTask; import org.mariotaku.twidere.task.ReportSpamAndBlockTask;
import org.mariotaku.twidere.task.twitter.GetActivitiesTask; import org.mariotaku.twidere.task.twitter.GetActivitiesTask;
import org.mariotaku.twidere.util.collection.CompactHashSet;
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
import java.io.IOException; import java.io.IOException;
@ -126,12 +130,12 @@ import edu.tsinghua.hotmobi.model.TweetEvent;
public class AsyncTwitterWrapper extends TwitterWrapper { public class AsyncTwitterWrapper extends TwitterWrapper {
private final Context mContext; private final Context context;
private final ContentResolver mResolver; private final ContentResolver resolver;
private final AsyncTaskManager mAsyncTaskManager; private final AsyncTaskManager asyncTaskManager;
private final SharedPreferencesWrapper mPreferences; private final SharedPreferencesWrapper preferences;
private final Bus mBus; private final Bus bus;
private IntList mCreatingFavoriteIds = new ArrayIntList(); private IntList mCreatingFavoriteIds = new ArrayIntList();
private IntList mDestroyingFavoriteIds = new ArrayIntList(); private IntList mDestroyingFavoriteIds = new ArrayIntList();
@ -139,33 +143,55 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private IntList mDestroyingStatusIds = new ArrayIntList(); private IntList mDestroyingStatusIds = new ArrayIntList();
private IntList mUpdatingRelationshipIds = 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, public AsyncTwitterWrapper(Context context, Bus bus, SharedPreferencesWrapper preferences,
AsyncTaskManager asyncTaskManager) { AsyncTaskManager asyncTaskManager) {
mContext = context; this.context = context;
mResolver = context.getContentResolver(); resolver = context.getContentResolver();
mBus = bus; this.bus = bus;
mPreferences = preferences; this.preferences = preferences;
mAsyncTaskManager = asyncTaskManager; 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public void addSendingDraftId(long id) { public void addSendingDraftId(long id) {
synchronized (mSendingDraftIds) { synchronized (sendingDraftIds) {
mSendingDraftIds.add(id); sendingDraftIds.add(id);
mResolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null); resolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null);
} }
} }
public int addUserListMembersAsync(final UserKey accountKey, final String listId, @NonNull final ParcelableUser... users) { public int addUserListMembersAsync(final UserKey accountKey, final String listId, @NonNull final ParcelableUser... users) {
final AddUserListMembersTask task = new AddUserListMembersTask(accountKey, listId, 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) { 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int createFavoriteAsync(final UserKey accountKey, final String statusId) { public int createFavoriteAsync(final UserKey accountKey, final String statusId) {
final CreateFavoriteTask task = new CreateFavoriteTask(accountKey, 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int createMultiBlockAsync(final UserKey accountKey, final String[] userIds) { public int createMultiBlockAsync(final UserKey accountKey, final String[] userIds) {
final CreateMultiBlockTask task = new CreateMultiBlockTask(accountKey, 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int createSavedSearchAsync(final UserKey accountKey, final String query) { public int createSavedSearchAsync(final UserKey accountKey, final String query) {
final CreateSavedSearchTask task = new CreateSavedSearchTask(accountKey, 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, public int createUserListAsync(final UserKey accountKey, final String listName, final boolean isPublic,
final String description) { final String description) {
final CreateUserListTask task = new CreateUserListTask(mContext, accountKey, listName, isPublic, final CreateUserListTask task = new CreateUserListTask(context, accountKey, listName, isPublic,
description); description);
return mAsyncTaskManager.add(task, true); return asyncTaskManager.add(task, true);
} }
public int createUserListSubscriptionAsync(final UserKey accountKey, final String listId) { public int createUserListSubscriptionAsync(final UserKey accountKey, final String listId) {
final CreateUserListSubscriptionTask task = new CreateUserListSubscriptionTask(accountKey, 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) { public int deleteUserListMembersAsync(final UserKey accountKey, final String listId, final ParcelableUser... users) {
final DeleteUserListMembersTask task = new DeleteUserListMembersTask(accountKey, listId, 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public void destroyBlockAsync(final UserKey accountKey, final UserKey userKey) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int destroyDirectMessageAsync(final UserKey accountKey, final String messageId) { public int destroyDirectMessageAsync(final UserKey accountKey, final String messageId) {
final DestroyDirectMessageTask task = new DestroyDirectMessageTask(accountKey, 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) { public int destroyMessageConversationAsync(final UserKey accountKey, final String userId) {
final DestroyMessageConversationTask task = new DestroyMessageConversationTask(accountKey, 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) { public int destroyFavoriteAsync(final UserKey accountKey, final String statusId) {
final DestroyFavoriteTask task = new DestroyFavoriteTask(accountKey, 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public void destroyMuteAsync(final UserKey accountKey, final UserKey userKey) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int destroySavedSearchAsync(final UserKey accountKey, final long searchId) { public int destroySavedSearchAsync(final UserKey accountKey, final long searchId) {
final DestroySavedSearchTask task = new DestroySavedSearchTask(accountKey, 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) { public int destroyStatusAsync(final UserKey accountKey, final String statusId) {
final DestroyStatusTask task = new DestroyStatusTask(accountKey, 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) { public int destroyUserListAsync(final UserKey accountKey, final String listId) {
final DestroyUserListTask task = new DestroyUserListTask(mContext, accountKey, listId); final DestroyUserListTask task = new DestroyUserListTask(context, accountKey, listId);
return mAsyncTaskManager.add(task, true); return asyncTaskManager.add(task, true);
} }
public int destroyUserListSubscriptionAsync(final UserKey accountKey, final String listId) { public int destroyUserListSubscriptionAsync(final UserKey accountKey, final String listId) {
final DestroyUserListSubscriptionTask task = new DestroyUserListSubscriptionTask(accountKey, listId); final DestroyUserListSubscriptionTask task = new DestroyUserListSubscriptionTask(accountKey, listId);
return mAsyncTaskManager.add(task, true); return asyncTaskManager.add(task, true);
} }
public Context getContext() { public Context getContext() {
return mContext; return context;
} }
public boolean getHomeTimelineAsync(RefreshTaskParam param) { public boolean getHomeTimelineAsync(RefreshTaskParam param) {
@ -311,31 +337,31 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
} }
public void getLocalTrendsAsync(final UserKey accountId, final int woeid) { 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); TaskStarter.execute(task);
} }
public void getReceivedDirectMessagesAsync(RefreshTaskParam param) { public void getReceivedDirectMessagesAsync(RefreshTaskParam param) {
final GetReceivedDirectMessagesTask task = new GetReceivedDirectMessagesTask(mContext); final GetReceivedDirectMessagesTask task = new GetReceivedDirectMessagesTask(context);
task.setParams(param); task.setParams(param);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public void getSentDirectMessagesAsync(RefreshTaskParam param) { public void getSentDirectMessagesAsync(RefreshTaskParam param) {
final GetSentDirectMessagesTask task = new GetSentDirectMessagesTask(mContext); final GetSentDirectMessagesTask task = new GetSentDirectMessagesTask(context);
task.setParams(param); task.setParams(param);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public void getSavedSearchesAsync(UserKey[] accountKeys) { public void getSavedSearchesAsync(UserKey[] accountKeys) {
final GetSavedSearchesTask task = new GetSavedSearchesTask(mContext); final GetSavedSearchesTask task = new GetSavedSearchesTask(context);
task.setParams(accountKeys); task.setParams(accountKeys);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
@NonNull @NonNull
public long[] getSendingDraftIds() { public long[] getSendingDraftIds() {
return mSendingDraftIds.toArray(); return sendingDraftIds.toArray();
} }
public boolean isCreatingFavorite(@Nullable final UserKey accountId, @Nullable final String statusId) { 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()); return (accountId == null ? 0 : accountId.hashCode()) ^ (statusId == null ? 0 : statusId.hashCode());
} }
public boolean isHomeTimelineRefreshing() { public boolean isStatusTimelineRefreshing(Uri uri) {
return mAsyncTaskManager.hasRunningTasksForTag(TASK_TAG_GET_HOME_TIMELINE); return getStatusTasks.contains(uri);
}
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 void refreshAll() { public void refreshAll() {
refreshAll(new GetAccountKeysClosure() { refreshAll(new GetAccountKeysClosure() {
@Override @Override
public UserKey[] getAccountKeys() { public UserKey[] getAccountKeys() {
return DataStoreUtils.getActivatedAccountKeys(mContext); return DataStoreUtils.getActivatedAccountKeys(context);
} }
}); });
} }
@ -400,11 +418,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Nullable @Nullable
@Override @Override
public String[] getSinceIds() { public String[] getSinceIds() {
return DataStoreUtils.getNewestStatusIds(mContext, Statuses.CONTENT_URI, return DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI,
getAccountKeys()); getAccountKeys());
} }
}); });
if (mPreferences.getBoolean(KEY_HOME_REFRESH_MENTIONS)) { if (preferences.getBoolean(KEY_HOME_REFRESH_MENTIONS)) {
getActivitiesAboutMeAsync(new SimpleRefreshTaskParam() { getActivitiesAboutMeAsync(new SimpleRefreshTaskParam() {
@NonNull @NonNull
@Override @Override
@ -415,12 +433,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Nullable @Nullable
@Override @Override
public String[] getSinceIds() { public String[] getSinceIds() {
return DataStoreUtils.getNewestActivityMaxPositions(mContext, return DataStoreUtils.getNewestActivityMaxPositions(context,
Activities.AboutMe.CONTENT_URI, getAccountKeys()); Activities.AboutMe.CONTENT_URI, getAccountKeys());
} }
}); });
} }
if (mPreferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES)) { if (preferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES)) {
getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() { getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() {
@NonNull @NonNull
@Override @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()); getSavedSearchesAsync(closure.getAccountKeys());
} }
return true; return true;
} }
public void removeSendingDraftId(long id) { public void removeSendingDraftId(long id) {
synchronized (mSendingDraftIds) { synchronized (sendingDraftIds) {
mSendingDraftIds.removeElement(id); sendingDraftIds.removeElement(id);
mResolver.notifyChange(Drafts.CONTENT_URI_UNSENT, null); 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) { 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); task.setup(accountKey, userKey);
TaskStarter.execute(task); TaskStarter.execute(task);
} }
public int retweetStatusAsync(final UserKey accountKey, final String statusId) { public int retweetStatusAsync(final UserKey accountKey, final String statusId) {
final RetweetStatusTask task = new RetweetStatusTask(accountKey, 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, public int sendDirectMessageAsync(final UserKey accountKey, final String recipientId, final String text,
final String imageUri) { 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.setAction(INTENT_ACTION_SEND_DIRECT_MESSAGE);
intent.putExtra(EXTRA_ACCOUNT_KEY, accountKey); intent.putExtra(EXTRA_ACCOUNT_KEY, accountKey);
intent.putExtra(EXTRA_RECIPIENT_ID, recipientId); intent.putExtra(EXTRA_RECIPIENT_ID, recipientId);
intent.putExtra(EXTRA_TEXT, text); intent.putExtra(EXTRA_TEXT, text);
intent.putExtra(EXTRA_IMAGE_URI, imageUri); intent.putExtra(EXTRA_IMAGE_URI, imageUri);
mContext.startService(intent); context.startService(intent);
return 0; return 0;
} }
public int updateUserListDetails(final UserKey accountKey, final String listId, public int updateUserListDetails(final UserKey accountKey, final String listId,
final UserListUpdate update) { final UserListUpdate update) {
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(mContext, accountKey, final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(context, accountKey,
listId, update); listId, update);
return mAsyncTaskManager.add(task, true); return asyncTaskManager.add(task, true);
} }
public static <T extends Response<?>> Exception getException(List<T> responses) { 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) { 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; if (bus == null) return;
TaskStarter.execute(new AbstractTask<Object, SingleResponse<Relationship>, Bus>() { TaskStarter.execute(new AbstractTask<Object, SingleResponse<Relationship>, Bus>() {
@Override @Override
public SingleResponse<Relationship> doLongOperation(Object param) { public SingleResponse<Relationship> doLongOperation(Object param) {
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, accountKey, true); final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountKey, true);
try { try {
final Relationship relationship = twitter.updateFriendship(userKey.getId(), update); final Relationship relationship = twitter.updateFriendship(userKey.getId(), update);
if (!relationship.isSourceWantRetweetsFromTarget()) { if (!relationship.isSourceWantRetweetsFromTarget()) {
@ -511,7 +529,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY) Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)
); );
final String[] selectionArgs = {accountKey.toString(), userKey.toString()}; 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); return SingleResponse.Companion.getInstance(relationship);
} catch (MicroBlogException e) { } catch (MicroBlogException e) {
@ -544,8 +562,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
public Object doLongOperation(Object o) { public Object doLongOperation(Object o) {
for (UserKey accountId : accountKeys) { for (UserKey accountId : accountKeys) {
MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, accountId, false); MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountId, false);
if (!Utils.isOfficialCredentials(mContext, accountId)) continue; if (!Utils.isOfficialCredentials(context, accountId)) continue;
try { try {
twitter.setActivitiesAboutMeUnread(cursor); twitter.setActivitiesAboutMeUnread(cursor);
} catch (MicroBlogException e) { } catch (MicroBlogException e) {
@ -635,7 +653,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
public AddUserListMembersTask(@NonNull final UserKey accountKey, public AddUserListMembersTask(@NonNull final UserKey accountKey,
final String listId, final String listId,
@NonNull final ParcelableUser[] users) { @NonNull final ParcelableUser[] users) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mListId = listId; this.mListId = listId;
this.mUsers = users; this.mUsers = users;
@ -643,7 +661,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final UserKey[] userIds = new UserKey[mUsers.length]; 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 boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
final String displayName = mUserColorNameManager.getDisplayName(user.key, user.name, final String displayName = mUserColorNameManager.getDisplayName(user.key, user.name,
user.screen_name, nameFirst); 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 { } 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, message = res.getQuantityString(R.plurals.added_N_users_to_list, mUsers.length, mUsers.length,
result.getData().name); result.getData().name);
} }
Utils.showOkMessage(mContext, message, false); Utils.showOkMessage(context, message, false);
} else { } 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, bus.post(new UserListMembersChangedEvent(UserListMembersChangedEvent.Action.ADDED,
result.getData(), mUsers)); result.getData(), mUsers));
@ -696,7 +714,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected Integer doInBackground(final Object... params) { 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 @Override
protected Integer doInBackground(final Object... params) { 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; private final String mStatusId;
public CreateFavoriteTask(final UserKey accountKey, final String statusId) { public CreateFavoriteTask(final UserKey accountKey, final String statusId) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mStatusId = statusId; this.mStatusId = statusId;
} }
@Override @Override
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) { 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(); 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final ParcelableStatus result; final ParcelableStatus result;
@ -747,7 +765,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
} }
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials, ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
mUserColorNameManager); mUserColorNameManager);
Utils.setLastSeen(mContext, result.mentions, System.currentTimeMillis()); Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(Statuses.IS_FAVORITE, true); values.put(Statuses.IS_FAVORITE, true);
values.put(Statuses.REPLY_COUNT, result.reply_count); 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), final String[] statusWhereArgs = {mAccountKey.toString(), String.valueOf(mStatusId),
String.valueOf(mStatusId)}; String.valueOf(mStatusId)};
for (final Uri uri : TwidereDataStore.STATUSES_URIS) { 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 @Override
public void process(ParcelableActivity activity) { public void process(ParcelableActivity activity) {
ParcelableStatus[][] statusesMatrix = {activity.target_statuses, ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
@ -819,7 +837,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
// END HotMobi // END HotMobi
} else { } else {
taskEvent.setSucceeded(false); 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(taskEvent);
bus.post(new StatusListChangedEvent()); bus.post(new StatusListChangedEvent());
@ -834,7 +852,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String[] mUserIds; private final String[] mUserIds;
public CreateMultiBlockTask(final UserKey accountKey, final String[] userIds) { public CreateMultiBlockTask(final UserKey accountKey, final String[] userIds) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mUserIds = userIds; this.mUserIds = userIds;
} }
@ -853,13 +871,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
values.put(CachedRelationships.FOLLOWED_BY, false); values.put(CachedRelationships.FOLLOWED_BY, false);
final String where = Expression.inArgs(CachedRelationships.USER_KEY, list.size()).getSQL(); final String where = Expression.inArgs(CachedRelationships.USER_KEY, list.size()).getSQL();
final String[] selectionArgs = list.toArray(new String[list.size()]); 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 @Override
protected ListResponse<String> doInBackground(final Object... params) { protected ListResponse<String> doInBackground(final Object... params) {
final List<String> blockedUsers = new ArrayList<>(); 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) { if (twitter != null) {
for (final String userId : mUserIds) { for (final String userId : mUserIds) {
try { try {
@ -878,11 +896,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected void onPostExecute(final ListResponse<String> result) { protected void onPostExecute(final ListResponse<String> result) {
if (result.hasData()) { if (result.hasData()) {
Utils.showInfoMessage(mContext, R.string.users_blocked, false); Utils.showInfoMessage(context, R.string.users_blocked, false);
} else { } 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); super.onPostExecute(result);
} }
@ -895,14 +913,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String mQuery; private final String mQuery;
CreateSavedSearchTask(final UserKey accountKey, final String query) { CreateSavedSearchTask(final UserKey accountKey, final String query) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mQuery = query; mQuery = query;
} }
@Override @Override
protected SingleResponse<SavedSearch> doInBackground(final Object... params) { 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; if (twitter == null) return null;
try { try {
return SingleResponse.Companion.getInstance(twitter.createSavedSearch(mQuery)); return SingleResponse.Companion.getInstance(twitter.createSavedSearch(mQuery));
@ -914,16 +932,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected void onPostExecute(final SingleResponse<SavedSearch> result) { protected void onPostExecute(final SingleResponse<SavedSearch> result) {
if (result.hasData()) { if (result.hasData()) {
final String message = mContext.getString(R.string.search_name_saved, result.getData().getQuery()); final String message = context.getString(R.string.search_name_saved, result.getData().getQuery());
Utils.showOkMessage(mContext, message, false); Utils.showOkMessage(context, message, false);
} else if (result.hasException()) { } else if (result.hasException()) {
final Exception exception = result.getException(); final Exception exception = result.getException();
// https://github.com/TwidereProject/Twidere-Android/issues/244 // https://github.com/TwidereProject/Twidere-Android/issues/244
if (exception instanceof MicroBlogException && ((MicroBlogException) exception).getStatusCode() == 403) { if (exception instanceof MicroBlogException && ((MicroBlogException) exception).getStatusCode() == 403) {
final String desc = mContext.getString(R.string.saved_searches_already_saved_hint); final String desc = context.getString(R.string.saved_searches_already_saved_hint);
Utils.showErrorMessage(mContext, R.string.action_saving_search, desc, false); Utils.showErrorMessage(context, R.string.action_saving_search, desc, false);
} else { } else {
Utils.showErrorMessage(mContext, R.string.action_saving_search, exception, false); Utils.showErrorMessage(context, R.string.action_saving_search, exception, false);
} }
} }
super.onPostExecute(result); super.onPostExecute(result);
@ -937,14 +955,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String mListId; private final String mListId;
public CreateUserListSubscriptionTask(final UserKey accountKey, final String listId) { public CreateUserListSubscriptionTask(final UserKey accountKey, final String listId) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mListId = listId; this.mListId = listId;
} }
@Override @Override
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final UserList userList = twitter.createUserListSubscription(mListId); final UserList userList = twitter.createUserListSubscription(mListId);
@ -959,12 +977,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
protected void onPostExecute(final SingleResponse<ParcelableUserList> result) { protected void onPostExecute(final SingleResponse<ParcelableUserList> result) {
final boolean succeed = result.hasData(); final boolean succeed = result.hasData();
if (succeed) { if (succeed) {
final String message = mContext.getString(R.string.subscribed_to_list, result.getData().name); final String message = context.getString(R.string.subscribed_to_list, result.getData().name);
Utils.showOkMessage(mContext, message, false); Utils.showOkMessage(context, message, false);
bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.SUBSCRIBE, bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.SUBSCRIBE,
result.getData())); result.getData()));
} else { } 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); super.onPostExecute(result);
} }
@ -1026,7 +1044,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final ParcelableUser[] users; private final ParcelableUser[] users;
public DeleteUserListMembersTask(final UserKey accountKey, final String userListId, final ParcelableUser[] users) { public DeleteUserListMembersTask(final UserKey accountKey, final String userListId, final ParcelableUser[] users) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mUserListId = userListId; mUserListId = userListId;
this.users = users; this.users = users;
@ -1034,7 +1052,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final UserKey[] userIds = new UserKey[users.length]; 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 boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
final String displayName = mUserColorNameManager.getDisplayName(user.key, final String displayName = mUserColorNameManager.getDisplayName(user.key,
user.name, user.screen_name, nameFirst); 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); result.getData().name);
} else { } 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, message = res.getQuantityString(R.plurals.deleted_N_users_from_list, users.length, users.length,
result.getData().name); result.getData().name);
} }
bus.post(new UserListMembersChangedEvent(UserListMembersChangedEvent.Action.REMOVED, bus.post(new UserListMembersChangedEvent(UserListMembersChangedEvent.Action.REMOVED,
result.getData(), users)); result.getData(), users));
Utils.showInfoMessage(mContext, message, false); Utils.showInfoMessage(context, message, false);
} else { } else {
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true); Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
} }
super.onPostExecute(result); super.onPostExecute(result);
} }
@ -1084,7 +1102,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String mMessageId; private final String mMessageId;
public DestroyDirectMessageTask(final UserKey accountKey, final String messageId) { public DestroyDirectMessageTask(final UserKey accountKey, final String messageId) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mMessageId = messageId; mMessageId = messageId;
} }
@ -1093,8 +1111,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
final String where = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY), final String where = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY),
Expression.equalsArgs(DirectMessages.MESSAGE_ID)).getSQL(); Expression.equalsArgs(DirectMessages.MESSAGE_ID)).getSQL();
final String[] whereArgs = new String[]{mAccountKey.toString(), mMessageId}; final String[] whereArgs = new String[]{mAccountKey.toString(), mMessageId};
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, where, whereArgs); resolver.delete(DirectMessages.Inbox.CONTENT_URI, where, whereArgs);
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, where, whereArgs); resolver.delete(DirectMessages.Outbox.CONTENT_URI, where, whereArgs);
} }
private boolean isMessageNotFound(final Exception e) { private boolean isMessageNotFound(final Exception e) {
@ -1106,7 +1124,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected SingleResponse<DirectMessage> doInBackground(final Object... args) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final DirectMessage message = twitter.destroyDirectMessage(mMessageId); final DirectMessage message = twitter.destroyDirectMessage(mMessageId);
@ -1126,9 +1144,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
super.onPostExecute(result); super.onPostExecute(result);
if (result == null) return; if (result == null) return;
if (result.hasData() || isMessageNotFound(result.getException())) { 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 { } 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; private final UserKey mAccountKey;
public DestroyMessageConversationTask(final UserKey accountKey, final String userId) { public DestroyMessageConversationTask(final UserKey accountKey, final String userId) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mUserId = userId; mUserId = userId;
} }
private void deleteMessages(final UserKey accountKey, final String userId) { private void deleteMessages(final UserKey accountKey, final String userId) {
final String[] whereArgs = {accountKey.toString(), 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(AccountSupportColumns.ACCOUNT_KEY),
Expression.equalsArgs(Inbox.SENDER_ID) Expression.equalsArgs(Inbox.SENDER_ID)
).getSQL(), whereArgs); ).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(AccountSupportColumns.ACCOUNT_KEY),
Expression.equalsArgs(Outbox.RECIPIENT_ID) Expression.equalsArgs(Outbox.RECIPIENT_ID)
).getSQL(), whereArgs); ).getSQL(), whereArgs);
@ -1168,7 +1186,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected SingleResponse<Void> doInBackground(final Object... args) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
twitter.destroyDirectMessagesConversation(mAccountKey.getId(), mUserId); twitter.destroyDirectMessagesConversation(mAccountKey.getId(), mUserId);
@ -1188,9 +1206,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
super.onPostExecute(result); super.onPostExecute(result);
if (result == null) return; if (result == null) return;
if (result.hasData() || isMessageNotFound(result.getException())) { 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 { } 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; private final String mStatusId;
public DestroyFavoriteTask(@NonNull final UserKey accountKey, final String statusId) { public DestroyFavoriteTask(@NonNull final UserKey accountKey, final String statusId) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mStatusId = statusId; this.mStatusId = statusId;
} }
@Override @Override
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) { 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(); 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final ParcelableStatus result; final ParcelableStatus result;
@ -1240,10 +1258,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
Expression.equalsArgs(Statuses.RETWEET_ID))); Expression.equalsArgs(Statuses.RETWEET_ID)));
final String[] whereArgs = {mAccountKey.toString(), mStatusId, mStatusId}; final String[] whereArgs = {mAccountKey.toString(), mStatusId, mStatusId};
for (final Uri uri : TwidereDataStore.STATUSES_URIS) { 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 @Override
public void process(ParcelableActivity activity) { public void process(ParcelableActivity activity) {
ParcelableStatus[][] statusesMatrix = {activity.target_statuses, ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
@ -1291,10 +1309,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
tweetEvent.setAction(TweetEvent.Action.UNFAVORITE); tweetEvent.setAction(TweetEvent.Action.UNFAVORITE);
HotMobiLogger.getInstance(getContext()).log(mAccountKey, tweetEvent); HotMobiLogger.getInstance(getContext()).log(mAccountKey, tweetEvent);
// END HotMobi // END HotMobi
Utils.showInfoMessage(mContext, R.string.status_unfavorited, false); Utils.showInfoMessage(context, R.string.status_unfavorited, false);
} else { } else {
taskEvent.setSucceeded(false); 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(taskEvent);
bus.post(new StatusListChangedEvent()); bus.post(new StatusListChangedEvent());
@ -1309,14 +1327,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final long mSearchId; private final long mSearchId;
DestroySavedSearchTask(final UserKey accountKey, final long searchId) { DestroySavedSearchTask(final UserKey accountKey, final long searchId) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mSearchId = searchId; mSearchId = searchId;
} }
@Override @Override
protected SingleResponse<SavedSearch> doInBackground(final Object... params) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
return SingleResponse.Companion.getInstance(twitter.destroySavedSearch(mSearchId)); return SingleResponse.Companion.getInstance(twitter.destroySavedSearch(mSearchId));
@ -1328,11 +1346,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected void onPostExecute(final SingleResponse<SavedSearch> result) { protected void onPostExecute(final SingleResponse<SavedSearch> result) {
if (result.hasData()) { if (result.hasData()) {
final String message = mContext.getString(R.string.search_name_deleted, result.getData().getQuery()); final String message = context.getString(R.string.search_name_deleted, result.getData().getQuery());
Utils.showOkMessage(mContext, message, false); Utils.showOkMessage(context, message, false);
bus.post(new SavedSearchDestroyedEvent(mAccountKey, mSearchId)); bus.post(new SavedSearchDestroyedEvent(mAccountKey, mSearchId));
} else { } 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); super.onPostExecute(result);
} }
@ -1345,17 +1363,17 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String mStatusId; private final String mStatusId;
public DestroyStatusTask(final UserKey accountKey, final String statusId) { public DestroyStatusTask(final UserKey accountKey, final String statusId) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mStatusId = statusId; this.mStatusId = statusId;
} }
@Override @Override
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) { protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext, final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
mAccountKey); mAccountKey);
if (credentials == null) return SingleResponse.Companion.getInstance(); if (credentials == null) return SingleResponse.Companion.getInstance();
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, credentials, true, final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true,
true); true);
if (twitter == null) return SingleResponse.Companion.getInstance(); if (twitter == null) return SingleResponse.Companion.getInstance();
ParcelableStatus status = null; ParcelableStatus status = null;
@ -1368,9 +1386,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
} catch (final MicroBlogException e) { } catch (final MicroBlogException e) {
exception = e; exception = e;
} }
if (status != null || (exception != null && exception.getErrorCode() == ErrorInfo.STATUS_NOT_FOUND)) { if (status != null || (exception.getErrorCode() == ErrorInfo.STATUS_NOT_FOUND)) {
DataStoreUtils.deleteStatus(mResolver, mAccountKey, mStatusId, status); DataStoreUtils.deleteStatus(resolver, mAccountKey, mStatusId, status);
DataStoreUtils.deleteActivityStatus(mResolver, mAccountKey, mStatusId, status); DataStoreUtils.deleteActivityStatus(resolver, mAccountKey, mStatusId, status);
} }
return SingleResponse.Companion.getInstance(status); return SingleResponse.Companion.getInstance(status);
} }
@ -1391,13 +1409,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
if (result.hasData()) { if (result.hasData()) {
final ParcelableStatus status = result.getData(); final ParcelableStatus status = result.getData();
if (status.retweet_id != null) { if (status.retweet_id != null) {
Utils.showInfoMessage(mContext, R.string.retweet_cancelled, false); Utils.showInfoMessage(context, R.string.retweet_cancelled, false);
} else { } else {
Utils.showInfoMessage(mContext, R.string.status_deleted, false); Utils.showInfoMessage(context, R.string.status_deleted, false);
} }
bus.post(new StatusDestroyedEvent(status)); bus.post(new StatusDestroyedEvent(status));
} else { } else {
Utils.showErrorMessage(mContext, R.string.action_deleting, result.getException(), true); Utils.showErrorMessage(context, R.string.action_deleting, result.getException(), true);
} }
super.onPostExecute(result); super.onPostExecute(result);
} }
@ -1410,7 +1428,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final String mListId; private final String mListId;
public DestroyUserListSubscriptionTask(@NonNull final UserKey accountKey, final String listId) { public DestroyUserListSubscriptionTask(@NonNull final UserKey accountKey, final String listId) {
super(mContext); super(context);
mAccountKey = accountKey; mAccountKey = accountKey;
mListId = listId; mListId = listId;
} }
@ -1418,7 +1436,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) { 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(); if (twitter == null) return SingleResponse.Companion.getInstance();
try { try {
final UserList userList = twitter.destroyUserListSubscription(mListId); final UserList userList = twitter.destroyUserListSubscription(mListId);
@ -1433,12 +1451,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
protected void onPostExecute(final SingleResponse<ParcelableUserList> result) { protected void onPostExecute(final SingleResponse<ParcelableUserList> result) {
final boolean succeed = result.hasData(); final boolean succeed = result.hasData();
if (succeed) { if (succeed) {
final String message = mContext.getString(R.string.unsubscribed_from_list, result.getData().name); final String message = context.getString(R.string.unsubscribed_from_list, result.getData().name);
Utils.showOkMessage(mContext, message, false); Utils.showOkMessage(context, message, false);
bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.UNSUBSCRIBE, bus.post(new UserListSubscriptionEvent(UserListSubscriptionEvent.Action.UNSUBSCRIBE,
result.getData())); result.getData()));
} else { } 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); super.onPostExecute(result);
} }
@ -1542,7 +1560,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
} }
public SharedPreferencesWrapper getPreferences() { public SharedPreferencesWrapper getPreferences() {
return mPreferences; return preferences;
} }
final class RemoveUnreadCountsTask extends AsyncTask<Object, Object, Integer> { final class RemoveUnreadCountsTask extends AsyncTask<Object, Object, Integer> {
@ -1556,7 +1574,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected Integer doInBackground(final Object... params) { 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; private final String mStatusId;
public RetweetStatusTask(@NonNull final UserKey accountKey, final String statusId) { public RetweetStatusTask(@NonNull final UserKey accountKey, final String statusId) {
super(mContext); super(context);
this.mAccountKey = accountKey; this.mAccountKey = accountKey;
this.mStatusId = statusId; this.mStatusId = statusId;
} }
@Override @Override
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) { protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext, final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
mAccountKey); mAccountKey);
if (credentials == null) return SingleResponse.Companion.getInstance(); 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) { if (twitter == null) {
return SingleResponse.Companion.getInstance(); return SingleResponse.Companion.getInstance();
} }
@ -1586,7 +1604,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
mAccountKey, false); mAccountKey, false);
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials, ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
mUserColorNameManager); mUserColorNameManager);
Utils.setLastSeen(mContext, result.mentions, System.currentTimeMillis()); Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(Statuses.MY_RETWEET_ID, result.id); values.put(Statuses.MY_RETWEET_ID, result.id);
values.put(Statuses.REPLY_COUNT, result.reply_count); values.put(Statuses.REPLY_COUNT, result.reply_count);
@ -1598,9 +1616,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
); );
final String[] whereArgs = {mStatusId, mStatusId}; final String[] whereArgs = {mStatusId, mStatusId};
for (final Uri uri : TwidereDataStore.STATUSES_URIS) { 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 @Override
public void process(ParcelableActivity activity) { public void process(ParcelableActivity activity) {
ParcelableStatus[][] statusesMatrix = {activity.target_statuses, ParcelableStatus[][] statusesMatrix = {activity.target_statuses,
@ -1649,7 +1667,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
bus.post(new StatusRetweetedEvent(status)); bus.post(new StatusRetweetedEvent(status));
} else { } else {
Utils.showErrorMessage(mContext, R.string.action_retweeting, result.getException(), true); Utils.showErrorMessage(context, R.string.action_retweeting, result.getException(), true);
} }
super.onPostExecute(result); super.onPostExecute(result);
} }

View File

@ -232,6 +232,7 @@ public class InternalTwitterContentUtils {
String text = status.getFullText(); String text = status.getFullText();
CodePointArray source; CodePointArray source;
// Display text range
int[] range = null; int[] range = null;
if (text == null) { if (text == null) {
text = status.getText(); text = status.getText();

View File

@ -27,7 +27,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.WorkerThread;
import org.mariotaku.microblog.library.twitter.model.User; import org.mariotaku.microblog.library.twitter.model.User;
import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.sqliteqb.library.Expression;
@ -161,50 +160,41 @@ public class UserColorNameManager implements TwidereConstants {
new String[]{userKey}); new String[]{userKey});
} }
@WorkerThread
public String getDisplayName(final ParcelableUser user, final boolean nameFirst) { public String getDisplayName(final ParcelableUser user, final boolean nameFirst) {
return getDisplayName(user.key, user.name, user.screen_name, nameFirst); return getDisplayName(user.key, user.name, user.screen_name, nameFirst);
} }
@WorkerThread
public String getDisplayName(final User user, final boolean nameFirst) { public String getDisplayName(final User user, final boolean nameFirst) {
return getDisplayName(UserKeyUtils.fromUser(user), user.getName(), user.getScreenName(), nameFirst); return getDisplayName(UserKeyUtils.fromUser(user), user.getName(), user.getScreenName(), nameFirst);
} }
@WorkerThread
public String getDisplayName(final ParcelableUserList user, final boolean nameFirst) { public String getDisplayName(final ParcelableUserList user, final boolean nameFirst) {
return getDisplayName(user.user_key, user.user_name, user.user_screen_name, nameFirst); return getDisplayName(user.user_key, user.user_name, user.user_screen_name, nameFirst);
} }
@WorkerThread
public String getDisplayName(final ParcelableStatus status, final boolean nameFirst) { public String getDisplayName(final ParcelableStatus status, final boolean nameFirst) {
return getDisplayName(status.user_key, status.user_name, status.user_screen_name, 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, public String getDisplayName(@NonNull final UserKey userId, final String name,
final String screenName, final boolean nameFirst) { final String screenName, final boolean nameFirst) {
return getDisplayName(userId.toString(), name, screenName, nameFirst); return getDisplayName(userId.toString(), name, screenName, nameFirst);
} }
@WorkerThread
public String getDisplayName(@NonNull final String userId, final String name, public String getDisplayName(@NonNull final String userId, final String name,
final String screenName, final boolean nameFirst) { final String screenName, final boolean nameFirst) {
final String nick = getUserNicknameInternal(userId); final String nick = getUserNicknameInternal(userId);
return decideDisplayName(nick, name, screenName, nameFirst); return decideDisplayName(nick, name, screenName, nameFirst);
} }
@WorkerThread
public int getUserColor(@NonNull final UserKey userId) { public int getUserColor(@NonNull final UserKey userId) {
return getUserColor(userId.toString()); return getUserColor(userId.toString());
} }
@WorkerThread
public int getUserColor(@NonNull final String userId) { public int getUserColor(@NonNull final String userId) {
return mColorPreferences.getInt(userId, Color.TRANSPARENT); return mColorPreferences.getInt(userId, Color.TRANSPARENT);
} }
@WorkerThread
public String getUserNickname(@NonNull final UserKey userKey) { public String getUserNickname(@NonNull final UserKey userKey) {
final String userKeyString = userKey.toString(); final String userKeyString = userKey.toString();
if (mNicknamePreferences.contains(userKey.getId())) { if (mNicknamePreferences.contains(userKey.getId())) {
@ -218,13 +208,11 @@ public class UserColorNameManager implements TwidereConstants {
return mNicknamePreferences.getString(userKeyString, null); return mNicknamePreferences.getString(userKeyString, null);
} }
@WorkerThread
public String getUserNickname(@NonNull final UserKey userId, final String name) { public String getUserNickname(@NonNull final UserKey userId, final String name) {
final String nick = getUserNickname(userId); final String nick = getUserNickname(userId);
return decideNickname(nick, name); return decideNickname(nick, name);
} }
@WorkerThread
public String getUserNickname(@NonNull final String userId, final String name) { public String getUserNickname(@NonNull final String userId, final String name) {
final String nick = getUserNicknameInternal(userId); final String nick = getUserNicknameInternal(userId);
return decideNickname(nick, name); return decideNickname(nick, name);
@ -234,7 +222,6 @@ public class UserColorNameManager implements TwidereConstants {
return mNicknamePreferences.getAll().entrySet(); return mNicknamePreferences.getAll().entrySet();
} }
@WorkerThread
private String getUserNicknameInternal(@NonNull final String userId) { private String getUserNicknameInternal(@NonNull final String userId) {
return mNicknamePreferences.getString(userId, null); return mNicknamePreferences.getString(userId, null);
} }

View File

@ -71,7 +71,7 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
protected abstract val errorInfoKey: String protected abstract val errorInfoKey: String
private var mContentObserver: ContentObserver? = null private var contentObserver: ContentObserver? = null
abstract val contentUri: Uri abstract val contentUri: Uri
@ -125,13 +125,13 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
val cr = contentResolver val cr = contentResolver
mContentObserver = object : ContentObserver(Handler()) { contentObserver = object : ContentObserver(Handler()) {
override fun onChange(selfChange: Boolean) { override fun onChange(selfChange: Boolean) {
reloadActivities() reloadActivities()
} }
} }
cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver!!) cr.registerContentObserver(Accounts.CONTENT_URI, true, contentObserver!!)
cr.registerContentObserver(Filters.CONTENT_URI, true, mContentObserver!!) cr.registerContentObserver(Filters.CONTENT_URI, true, contentObserver!!)
updateRefreshState() updateRefreshState()
reloadActivities() reloadActivities()
} }
@ -149,7 +149,7 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
override fun onStop() { override fun onStop() {
val cr = contentResolver val cr = contentResolver
cr.unregisterContentObserver(mContentObserver!!) cr.unregisterContentObserver(contentObserver!!)
super.onStop() super.onStop()
} }

View File

@ -235,7 +235,6 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
bus.register(this) bus.register(this)
val adapter = adapter val adapter = adapter
adapter!!.updateReadState() adapter!!.updateReadState()
updateRefreshState()
} }
override fun onStop() { override fun onStop() {
@ -298,10 +297,6 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
return DataStoreUtils.getActivatedAccountKeys(getActivity()) return DataStoreUtils.getActivatedAccountKeys(getActivity())
} }
protected fun updateRefreshState() {
refreshing = twitterWrapper.isReceivedDirectMessagesRefreshing || twitterWrapper.isSentDirectMessagesRefreshing
}
private fun addReadPosition(firstVisibleItem: Int) { private fun addReadPosition(firstVisibleItem: Int) {
if (mFirstVisibleItem != firstVisibleItem) { if (mFirstVisibleItem != firstVisibleItem) {
mReadPositions.add(firstVisibleItem) mReadPositions.add(firstVisibleItem)

View File

@ -52,7 +52,7 @@ class HomeTimelineFragment : CursorStatusesFragment() {
override fun updateRefreshState() { override fun updateRefreshState() {
val twitter = twitterWrapper val twitter = twitterWrapper
refreshing = twitter.isHomeTimelineRefreshing refreshing = twitter.isStatusTimelineRefreshing(contentUri)
} }
override fun getStatuses(param: RefreshTaskParam): Boolean { override fun getStatuses(param: RefreshTaskParam): Boolean {