mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-02 17:56:56 +01:00
activity supports unread syncing
This commit is contained in:
parent
192c455283
commit
5a263a3433
@ -21,8 +21,11 @@ package org.mariotaku.twidere.api.twitter.api;
|
|||||||
|
|
||||||
import org.mariotaku.restfu.annotation.method.GET;
|
import org.mariotaku.restfu.annotation.method.GET;
|
||||||
import org.mariotaku.restfu.annotation.method.POST;
|
import org.mariotaku.restfu.annotation.method.POST;
|
||||||
|
import org.mariotaku.restfu.annotation.param.Body;
|
||||||
|
import org.mariotaku.restfu.annotation.param.Form;
|
||||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||||
import org.mariotaku.restfu.annotation.param.Query;
|
import org.mariotaku.restfu.annotation.param.Query;
|
||||||
|
import org.mariotaku.restfu.http.BodyType;
|
||||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||||
import org.mariotaku.twidere.api.twitter.model.Activity;
|
import org.mariotaku.twidere.api.twitter.model.Activity;
|
||||||
import org.mariotaku.twidere.api.twitter.model.CursorTimestampResponse;
|
import org.mariotaku.twidere.api.twitter.model.CursorTimestampResponse;
|
||||||
@ -42,8 +45,8 @@ public interface PrivateActivityResources extends PrivateResources {
|
|||||||
CursorTimestampResponse getActivitiesAboutMeUnread(@Query("cursor") boolean cursor) throws TwitterException;
|
CursorTimestampResponse getActivitiesAboutMeUnread(@Query("cursor") boolean cursor) throws TwitterException;
|
||||||
|
|
||||||
@POST("/activity/about_me/unread.json")
|
@POST("/activity/about_me/unread.json")
|
||||||
CursorTimestampResponse setActivitiesAboutMeUnread(@Query("cursor") long cursor) throws TwitterException;
|
@Body(BodyType.FORM)
|
||||||
|
CursorTimestampResponse setActivitiesAboutMeUnread(@Form("cursor") long cursor) throws TwitterException;
|
||||||
|
|
||||||
@GET("/activity/by_friends.json")
|
@GET("/activity/by_friends.json")
|
||||||
ResponseList<Activity> getActivitiesByFriends(@Query Paging paging) throws TwitterException;
|
ResponseList<Activity> getActivitiesByFriends(@Query Paging paging) throws TwitterException;
|
||||||
|
@ -125,10 +125,8 @@ public class HotMobiLogger {
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static HotMobiLogger getInstance(Context context) {
|
public static HotMobiLogger getInstance(Context context) {
|
||||||
final DependencyHolder holder = new DependencyHolder(context);
|
return DependencyHolder.get(context).getHotMobiLogger();
|
||||||
return holder.getHotMobiLogger();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LatLng getCachedLatLng(Context context) {
|
public static LatLng getCachedLatLng(Context context) {
|
||||||
|
@ -104,4 +104,6 @@ public interface Constants extends TwidereConstants {
|
|||||||
String KEY_USAGE_STATISTICS = "usage_statistics";
|
String KEY_USAGE_STATISTICS = "usage_statistics";
|
||||||
@Preference(type = STRING, exportable = false)
|
@Preference(type = STRING, exportable = false)
|
||||||
String KEY_DEVICE_SERIAL = "device_serial";
|
String KEY_DEVICE_SERIAL = "device_serial";
|
||||||
|
|
||||||
|
String READ_POSITION_TAG_ACTIVITIES_ABOUT_ME = "activities_about_me";
|
||||||
}
|
}
|
||||||
|
@ -381,40 +381,6 @@ public abstract class AbsActivitiesFragment<Data> extends AbsContentListRecycler
|
|||||||
return ParcelableActivity.getActivityStatus(adapter.getActivity(position));
|
return ParcelableActivity.getActivityStatus(adapter.getActivity(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public boolean onStatusLongClick(IStatusViewHolder holder, int position) {
|
|
||||||
// //TODO handle long click event
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void onStatusMenuClick(IStatusViewHolder holder, View menuView, int position) {
|
|
||||||
// if (mPopupMenu != null) {
|
|
||||||
// mPopupMenu.dismiss();
|
|
||||||
// }
|
|
||||||
// final AbsActivitiesAdapter<Data> adapter = getAdapter();
|
|
||||||
// final PopupMenu popupMenu = new PopupMenu(adapter.getContext(), menuView,
|
|
||||||
// Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
|
|
||||||
// popupMenu.setOnMenuItemClickListener(mOnStatusMenuItemClickListener);
|
|
||||||
// popupMenu.inflate(R.menu.action_status);
|
|
||||||
// final ParcelableActivity activity = adapter.getActivity(position);
|
|
||||||
// Utils.setMenuForStatus(adapter.getContext(), mPreferences, popupMenu.getMenu(), activity, mTwitterWrapper);
|
|
||||||
// popupMenu.show();
|
|
||||||
// mPopupMenu = popupMenu;
|
|
||||||
// mSelecteActivity = activity;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) {
|
|
||||||
// final FragmentActivity activity = getActivity();
|
|
||||||
// final View profileImageView = holder.getProfileImageView();
|
|
||||||
// final View profileTypeView = holder.getProfileTypeView();
|
|
||||||
// final Bundle options = Utils.makeSceneTransitionOption(activity,
|
|
||||||
// new Pair<>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
|
|
||||||
// new Pair<>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
|
|
||||||
// Utils.openUserProfile(activity, status.account_id, status.user_id, status.user_screen_name, options);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@ -526,7 +492,9 @@ public abstract class AbsActivitiesFragment<Data> extends AbsContentListRecycler
|
|||||||
final AbsActivitiesAdapter<Data> adapter = getAdapter();
|
final AbsActivitiesAdapter<Data> adapter = getAdapter();
|
||||||
final ParcelableActivity activity = adapter.getActivity(position);
|
final ParcelableActivity activity = adapter.getActivity(position);
|
||||||
if (activity == null) return;
|
if (activity == null) return;
|
||||||
mReadStateManager.setPosition(readPositionTag, activity.timestamp);
|
if (mReadStateManager.setPosition(readPositionTag, activity.timestamp)) {
|
||||||
|
mTwitterWrapper.setActivitiesAboutMeUnreadAsync(getAccountIds(), activity.timestamp);
|
||||||
|
}
|
||||||
mReadStateManager.setPosition(getCurrentReadPositionTag(), activity.timestamp, true);
|
mReadStateManager.setPosition(getCurrentReadPositionTag(), activity.timestamp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class ActivitiesAboutMeFragment extends CursorActivitiesFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getReadPositionTag() {
|
protected String getReadPositionTag() {
|
||||||
return "activities_about_me";
|
return READ_POSITION_TAG_ACTIVITIES_ABOUT_ME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,7 +32,6 @@ import org.mariotaku.twidere.model.StringLongPair;
|
|||||||
import org.mariotaku.twidere.util.ReadStateManager;
|
import org.mariotaku.twidere.util.ReadStateManager;
|
||||||
import org.mariotaku.twidere.util.UriExtraUtils;
|
import org.mariotaku.twidere.util.UriExtraUtils;
|
||||||
import org.mariotaku.twidere.util.Utils;
|
import org.mariotaku.twidere.util.Utils;
|
||||||
import org.mariotaku.twidere.util.dagger.ApplicationModule;
|
|
||||||
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
||||||
|
|
||||||
import edu.tsinghua.hotmobi.HotMobiLogger;
|
import edu.tsinghua.hotmobi.HotMobiLogger;
|
||||||
@ -50,7 +49,7 @@ public class NotificationReceiver extends BroadcastReceiver implements Constants
|
|||||||
case BROADCAST_NOTIFICATION_DELETED: {
|
case BROADCAST_NOTIFICATION_DELETED: {
|
||||||
final Uri uri = intent.getData();
|
final Uri uri = intent.getData();
|
||||||
if (uri == null) return;
|
if (uri == null) return;
|
||||||
DependencyHolder holder = new DependencyHolder(context);
|
DependencyHolder holder = DependencyHolder.get(context);
|
||||||
final String type = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE);
|
final String type = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE);
|
||||||
final long accountId = NumberUtils.toLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
|
final long accountId = NumberUtils.toLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
|
||||||
final long itemId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_id"), -1);
|
final long itemId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_id"), -1);
|
||||||
|
@ -48,6 +48,7 @@ import org.mariotaku.twidere.api.twitter.Twitter;
|
|||||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||||
import org.mariotaku.twidere.api.twitter.http.HttpResponseCode;
|
import org.mariotaku.twidere.api.twitter.http.HttpResponseCode;
|
||||||
import org.mariotaku.twidere.api.twitter.model.Activity;
|
import org.mariotaku.twidere.api.twitter.model.Activity;
|
||||||
|
import org.mariotaku.twidere.api.twitter.model.CursorTimestampResponse;
|
||||||
import org.mariotaku.twidere.api.twitter.model.DirectMessage;
|
import org.mariotaku.twidere.api.twitter.model.DirectMessage;
|
||||||
import org.mariotaku.twidere.api.twitter.model.FriendshipUpdate;
|
import org.mariotaku.twidere.api.twitter.model.FriendshipUpdate;
|
||||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||||
@ -121,6 +122,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
private final SharedPreferencesWrapper mPreferences;
|
private final SharedPreferencesWrapper mPreferences;
|
||||||
private final Bus mBus;
|
private final Bus mBus;
|
||||||
private final UserColorNameManager mUserColorNameManager;
|
private final UserColorNameManager mUserColorNameManager;
|
||||||
|
private final ReadStateManager mReadStateManager;
|
||||||
|
|
||||||
private int mGetHomeTimelineTaskId, mGetMentionsTaskId;
|
private int mGetHomeTimelineTaskId, mGetMentionsTaskId;
|
||||||
private int mGetReceivedDirectMessagesTaskId, mGetSentDirectMessagesTaskId;
|
private int mGetReceivedDirectMessagesTaskId, mGetSentDirectMessagesTaskId;
|
||||||
@ -133,10 +135,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
|
|
||||||
private CopyOnWriteArraySet<Long> mSendingDraftIds = new CopyOnWriteArraySet<>();
|
private CopyOnWriteArraySet<Long> mSendingDraftIds = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
public AsyncTwitterWrapper(Context context, UserColorNameManager userColorNameManager, Bus bus, SharedPreferencesWrapper preferences, AsyncTaskManager asyncTaskManager) {
|
public AsyncTwitterWrapper(Context context, UserColorNameManager userColorNameManager,
|
||||||
|
ReadStateManager readStateManager, Bus bus,
|
||||||
|
SharedPreferencesWrapper preferences, AsyncTaskManager asyncTaskManager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mResolver = context.getContentResolver();
|
mResolver = context.getContentResolver();
|
||||||
mUserColorNameManager = userColorNameManager;
|
mUserColorNameManager = userColorNameManager;
|
||||||
|
mReadStateManager = readStateManager;
|
||||||
mBus = bus;
|
mBus = bus;
|
||||||
mPreferences = preferences;
|
mPreferences = preferences;
|
||||||
mAsyncTaskManager = asyncTaskManager;
|
mAsyncTaskManager = asyncTaskManager;
|
||||||
@ -492,7 +497,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int updateUserListDetails(final long accountId, final long listId, final UserListUpdate update) {
|
public int updateUserListDetails(final long accountId, final long listId, final UserListUpdate update) {
|
||||||
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(accountId, listId, update);
|
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(mContext, accountId, listId, update);
|
||||||
return mAsyncTaskManager.add(task, true);
|
return mAsyncTaskManager.add(task, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,12 +538,23 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
public void getActivitiesAboutMeAsync(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
public void getActivitiesAboutMeAsync(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||||
mAsyncTaskManager.add(new GetActivitiesTask(this, TASK_TAG_GET_MENTIONS, accountIds, maxIds, sinceIds) {
|
mAsyncTaskManager.add(new GetActivitiesTask(this, TASK_TAG_GET_MENTIONS, accountIds, maxIds, sinceIds) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getReadPosition(long accountId, Twitter twitter) {
|
||||||
|
try {
|
||||||
|
CursorTimestampResponse response = twitter.getActivitiesAboutMeUnread(true);
|
||||||
|
final String tag = Utils.getReadPositionTagWithAccounts(READ_POSITION_TAG_ACTIVITIES_ABOUT_ME, accountIds);
|
||||||
|
mReadStateManager.setPosition(tag, response.getCursor(), false);
|
||||||
|
} catch (TwitterException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException {
|
protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException {
|
||||||
if (Utils.isOfficialKeyAccount(getContext(), accountId)) {
|
if (Utils.isOfficialKeyAccount(getContext(), accountId)) {
|
||||||
return twitter.getActivitiesAboutMe(paging);
|
return twitter.getActivitiesAboutMe(paging);
|
||||||
}
|
}
|
||||||
final ResponseList<Activity> activities = new ResponseList<Activity>();
|
final ResponseList<Activity> activities = new ResponseList<>();
|
||||||
for (org.mariotaku.twidere.api.twitter.model.Status status : twitter.getMentionsTimeline(paging)) {
|
for (org.mariotaku.twidere.api.twitter.model.Status status : twitter.getMentionsTimeline(paging)) {
|
||||||
activities.add(Activity.fromMention(accountId, status));
|
activities.add(Activity.fromMention(accountId, status));
|
||||||
}
|
}
|
||||||
@ -555,6 +571,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
public void getActivitiesByFriendsAsync(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
public void getActivitiesByFriendsAsync(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||||
mAsyncTaskManager.add(new GetActivitiesTask(this, "get_activities_by_friends", accountIds, maxIds, sinceIds) {
|
mAsyncTaskManager.add(new GetActivitiesTask(this, "get_activities_by_friends", accountIds, maxIds, sinceIds) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getReadPosition(long accountId, Twitter twitter) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException {
|
protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException {
|
||||||
return twitter.getActivitiesByFriends(paging);
|
return twitter.getActivitiesByFriends(paging);
|
||||||
@ -567,12 +588,34 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActivitiesAboutMeUnreadAsync(final long[] accountIds, final long cursor) {
|
||||||
|
TaskRunnable<Object, Object, AsyncTwitterWrapper> task = new TaskRunnable<Object, Object, AsyncTwitterWrapper>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object doLongOperation(Object o) throws InterruptedException {
|
||||||
|
for (long accountId : accountIds) {
|
||||||
|
Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountId, false);
|
||||||
|
if (Utils.isOfficialTwitterInstance(mContext, twitter)) continue;
|
||||||
|
try {
|
||||||
|
twitter.setActivitiesAboutMeUnread(cursor);
|
||||||
|
} catch (TwitterException e) {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Log.w(LOGTAG, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
AsyncManager.runBackgroundTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
static abstract class GetActivitiesTask extends ManagedAsyncTask<Object, Object, Object> {
|
static abstract class GetActivitiesTask extends ManagedAsyncTask<Object, Object, Object> {
|
||||||
|
|
||||||
private final AsyncTwitterWrapper twitterWrapper;
|
final AsyncTwitterWrapper twitterWrapper;
|
||||||
private final long[] accountIds;
|
final long[] accountIds;
|
||||||
private final long[] maxIds;
|
final long[] maxIds;
|
||||||
private final long[] sinceIds;
|
final long[] sinceIds;
|
||||||
|
|
||||||
public GetActivitiesTask(AsyncTwitterWrapper twitterWrapper, String tag, long[] accountIds, long[] maxIds, long[] sinceIds) {
|
public GetActivitiesTask(AsyncTwitterWrapper twitterWrapper, String tag, long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||||
super(twitterWrapper.getContext(), tag);
|
super(twitterWrapper.getContext(), tag);
|
||||||
@ -631,6 +674,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContentResolverUtils.bulkInsert(cr, getContentUri(), valuesList);
|
ContentResolverUtils.bulkInsert(cr, getContentUri(), valuesList);
|
||||||
|
getReadPosition(accountId, twitter);
|
||||||
} catch (TwitterException e) {
|
} catch (TwitterException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -638,6 +682,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void getReadPosition(long accountId, Twitter twitter);
|
||||||
|
|
||||||
protected abstract ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException;
|
protected abstract ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2569,25 +2615,28 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
class StoreLocalTrendsTask extends StoreTrendsTask {
|
class StoreLocalTrendsTask extends StoreTrendsTask {
|
||||||
|
|
||||||
public StoreLocalTrendsTask(final ListResponse<Trends> result) {
|
public StoreLocalTrendsTask(final ListResponse<Trends> result) {
|
||||||
super(result, CachedTrends.Local.CONTENT_URI);
|
super(mContext, result, CachedTrends.Local.CONTENT_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StoreTrendsTask extends ManagedAsyncTask<Object, Object, SingleResponse<Boolean>> {
|
static class StoreTrendsTask extends ManagedAsyncTask<Object, Object, SingleResponse<Boolean>> {
|
||||||
|
|
||||||
private final ListResponse<Trends> response;
|
private final ListResponse<Trends> response;
|
||||||
private final Uri uri;
|
private final Uri uri;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
public StoreTrendsTask(final ListResponse<Trends> result, final Uri uri) {
|
public StoreTrendsTask(Context context, final ListResponse<Trends> response, final Uri uri) {
|
||||||
super(mContext, TASK_TAG_STORE_TRENDS);
|
super(context, TASK_TAG_STORE_TRENDS);
|
||||||
response = result;
|
this.response = response;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SingleResponse<Boolean> doInBackground(final Object... args) {
|
protected SingleResponse<Boolean> doInBackground(final Object... args) {
|
||||||
if (response == null) return SingleResponse.getInstance(false);
|
if (response == null) return SingleResponse.getInstance(false);
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
final List<Trends> messages = response.getData();
|
final List<Trends> messages = response.getData();
|
||||||
final ArrayList<String> hashtags = new ArrayList<>();
|
final ArrayList<String> hashtags = new ArrayList<>();
|
||||||
final ArrayList<ContentValues> hashtagValues = new ArrayList<>();
|
final ArrayList<ContentValues> hashtagValues = new ArrayList<>();
|
||||||
@ -2603,10 +2652,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
hashtagValue.put(CachedHashtags.NAME, hashtag);
|
hashtagValue.put(CachedHashtags.NAME, hashtag);
|
||||||
hashtagValues.add(hashtagValue);
|
hashtagValues.add(hashtagValue);
|
||||||
}
|
}
|
||||||
mResolver.delete(uri, null, null);
|
cr.delete(uri, null, null);
|
||||||
ContentResolverUtils.bulkInsert(mResolver, uri, valuesArray);
|
ContentResolverUtils.bulkInsert(cr, uri, valuesArray);
|
||||||
ContentResolverUtils.bulkDelete(mResolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, hashtags, null, true);
|
ContentResolverUtils.bulkDelete(cr, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, hashtags, null, true);
|
||||||
ContentResolverUtils.bulkInsert(mResolver, CachedHashtags.CONTENT_URI,
|
ContentResolverUtils.bulkInsert(cr, CachedHashtags.CONTENT_URI,
|
||||||
hashtagValues.toArray(new ContentValues[hashtagValues.size()]));
|
hashtagValues.toArray(new ContentValues[hashtagValues.size()]));
|
||||||
}
|
}
|
||||||
return SingleResponse.getInstance(true);
|
return SingleResponse.getInstance(true);
|
||||||
@ -2625,17 +2674,19 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateUserListDetailsTask extends ManagedAsyncTask<Object, Object, SingleResponse<ParcelableUserList>> {
|
static class UpdateUserListDetailsTask extends ManagedAsyncTask<Object, Object, SingleResponse<ParcelableUserList>> {
|
||||||
|
|
||||||
private final long accountId;
|
private final long accountId;
|
||||||
private final long listId;
|
private final long listId;
|
||||||
private final UserListUpdate update;
|
private final UserListUpdate update;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
public UpdateUserListDetailsTask(final long accountId, final long listId, UserListUpdate update) {
|
public UpdateUserListDetailsTask(Context context, final long accountId, final long listId, UserListUpdate update) {
|
||||||
super(mContext);
|
super(context);
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.listId = listId;
|
this.listId = listId;
|
||||||
this.update = update;
|
this.update = update;
|
||||||
|
this.mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +149,7 @@ public class ReadStateManager implements Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setPosition(final String key, final long id, boolean acceptOlder) {
|
public boolean setPosition(final String key, final long id, boolean acceptOlder) {
|
||||||
if (TextUtils.isEmpty(key) || !acceptOlder && getPosition(key) > id) return false;
|
if (TextUtils.isEmpty(key) || !acceptOlder && getPosition(key) >= id) return false;
|
||||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||||
editor.putLong(key, id);
|
editor.putLong(key, id);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
@ -55,7 +55,6 @@ import org.mariotaku.twidere.api.twitter.util.TwitterConverter;
|
|||||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||||
import org.mariotaku.twidere.model.RequestType;
|
import org.mariotaku.twidere.model.RequestType;
|
||||||
import org.mariotaku.twidere.util.dagger.ApplicationModule;
|
|
||||||
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
||||||
import org.mariotaku.twidere.util.net.NetworkUsageUtils;
|
import org.mariotaku.twidere.util.net.NetworkUsageUtils;
|
||||||
import org.mariotaku.twidere.util.net.TwidereProxySelector;
|
import org.mariotaku.twidere.util.net.TwidereProxySelector;
|
||||||
@ -228,7 +227,7 @@ public class TwitterAPIFactory implements TwidereConstants {
|
|||||||
} else {
|
} else {
|
||||||
userAgent = getTwidereUserAgent(context);
|
userAgent = getTwidereUserAgent(context);
|
||||||
}
|
}
|
||||||
DependencyHolder holder = new DependencyHolder(context);
|
DependencyHolder holder = DependencyHolder.get(context);
|
||||||
factory.setClient(holder.getRestHttpClient());
|
factory.setClient(holder.getRestHttpClient());
|
||||||
factory.setConverter(new TwitterConverter());
|
factory.setConverter(new TwitterConverter());
|
||||||
factory.setEndpoint(endpoint);
|
factory.setEndpoint(endpoint);
|
||||||
|
@ -175,9 +175,11 @@ public class ApplicationModule implements Constants {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public AsyncTwitterWrapper asyncTwitterWrapper(UserColorNameManager userColorNameManager,
|
public AsyncTwitterWrapper asyncTwitterWrapper(UserColorNameManager userColorNameManager,
|
||||||
|
ReadStateManager readStateManager,
|
||||||
Bus bus, SharedPreferencesWrapper preferences,
|
Bus bus, SharedPreferencesWrapper preferences,
|
||||||
AsyncTaskManager asyncTaskManager) {
|
AsyncTaskManager asyncTaskManager) {
|
||||||
return new AsyncTwitterWrapper(application, userColorNameManager, bus, preferences, asyncTaskManager);
|
return new AsyncTwitterWrapper(application, userColorNameManager, readStateManager, bus,
|
||||||
|
preferences, asyncTaskManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -51,7 +51,7 @@ public class DependencyHolder {
|
|||||||
@Inject
|
@Inject
|
||||||
Dns mDns;
|
Dns mDns;
|
||||||
|
|
||||||
public DependencyHolder(Context context) {
|
DependencyHolder(Context context) {
|
||||||
GeneralComponentHelper.build(context).inject(this);
|
GeneralComponentHelper.build(context).inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,11 @@ package org.mariotaku.twidere.util.net;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.okhttp.Dns;
|
import com.squareup.okhttp.Dns;
|
||||||
|
|
||||||
|
import org.mariotaku.twidere.BuildConfig;
|
||||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -82,6 +84,8 @@ public class TwidereProxySelector extends ProxySelector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectFailed(URI uri, SocketAddress address, IOException failure) {
|
public void connectFailed(URI uri, SocketAddress address, IOException failure) {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Log.w("TwidereProxy", String.format("%s: proxy %s connect failed", uri, address), failure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user