1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-01-27 23:19:27 +01:00

migrating account

This commit is contained in:
Mariotaku Lee 2016-03-07 16:44:03 +08:00
parent 28b604dcbd
commit 8add2c32a5
19 changed files with 128 additions and 149 deletions

View File

@ -28,6 +28,8 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import org.mariotaku.twidere.model.util.AccountKeyConverter;
@ParcelablePlease
@JsonObject
public class ParcelableUserList implements Parcelable, Comparable<ParcelableUserList> {
@ -39,11 +41,8 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
@JsonField(name = "subscribers_count")
public long subscribers_count;
@ParcelableThisPlease
@JsonField(name = "account_id")
public long account_id;
@ParcelableThisPlease
@JsonField(name = "account_host")
public String account_host;
@JsonField(name = "account_id", typeConverter = AccountKeyConverter.class)
public AccountKey account_key;
@ParcelableThisPlease
@JsonField(name = "id")
public long id;
@ -78,22 +77,6 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
public ParcelableUserList() {
}
public ParcelableUserList(final Parcel in) {
position = in.readLong();
account_id = in.readLong();
id = in.readLong();
is_public = in.readInt() == 1;
is_following = in.readInt() == 1;
name = in.readString();
description = in.readString();
user_id = in.readLong();
user_name = in.readString();
user_screen_name = in.readString();
user_profile_image_url = in.readString();
members_count = in.readLong();
subscribers_count = in.readLong();
}
@Override
public int compareTo(@NonNull final ParcelableUserList another) {
final long diff = position - another.position;
@ -103,22 +86,21 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
}
@Override
public boolean equals(final Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof ParcelableUserList)) return false;
final ParcelableUserList other = (ParcelableUserList) obj;
if (account_id != other.account_id) return false;
if (id != other.id) return false;
return true;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ParcelableUserList that = (ParcelableUserList) o;
if (id != that.id) return false;
return account_key.equals(that.account_key);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (account_id ^ account_id >>> 32);
result = prime * result + (int) (id ^ id >>> 32);
int result = account_key.hashCode();
result = 31 * result + (int) (id ^ (id >>> 32));
return result;
}
@ -127,8 +109,7 @@ public class ParcelableUserList implements Parcelable, Comparable<ParcelableUser
return "ParcelableUserList{" +
"members_count=" + members_count +
", subscribers_count=" + subscribers_count +
", account_id=" + account_id +
", account_host='" + account_host + '\'' +
", account_key=" + account_key +
", id=" + id +
", user_id=" + user_id +
", position=" + position +

View File

@ -31,7 +31,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
@ -50,8 +49,7 @@ public class DeleteUserListMembersDialogFragment extends BaseSupportDialogFragme
final ParcelableUserList userList = getUserList();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (users == null || userList == null || twitter == null) return;
twitter.deleteUserListMembersAsync(new AccountKey(userList.account_id,
userList.account_host), userList.id, users);
twitter.deleteUserListMembersAsync(userList.account_key, userList.id, users);
break;
default:
break;

View File

@ -28,7 +28,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
@ -44,8 +43,7 @@ public class DestroyUserListDialogFragment extends BaseSupportDialogFragment imp
final ParcelableUserList userList = getUserList();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (userList == null || twitter == null) return;
twitter.destroyUserListAsync(new AccountKey(userList.account_id,
userList.account_host), userList.id);
twitter.destroyUserListAsync(userList.account_key, userList.id);
break;
default:
break;

View File

@ -28,7 +28,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
@ -45,8 +44,7 @@ public class DestroyUserListSubscriptionDialogFragment extends BaseSupportDialog
final ParcelableUserList userList = getUserList();
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (userList == null || twitter == null) return;
twitter.destroyUserListSubscriptionAsync(new AccountKey(userList.account_id,
userList.account_host), userList.id);
twitter.destroyUserListSubscriptionAsync(userList.account_key, userList.id);
break;
default:
break;

View File

@ -22,11 +22,13 @@ package org.mariotaku.twidere.fragment.support;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import org.mariotaku.twidere.adapter.ParcelableUserListsAdapter;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.ParcelableUserList;
import java.util.List;
@ -46,9 +48,10 @@ public abstract class ParcelableUserListsFragment extends AbsUserListsFragment<L
return new ParcelableUserListsAdapter(context, compact);
}
protected long getAccountId() {
@Nullable
protected AccountKey getAccountKey() {
final Bundle args = getArguments();
return args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1;
return args.getParcelable(EXTRA_ACCOUNT_KEY);
}
@Override

View File

@ -19,9 +19,7 @@
package org.mariotaku.twidere.fragment.support;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -56,7 +54,7 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment {
@Override
public void onStop() {
mBus.register(this);
mBus.unregister(this);
super.onStop();
}

View File

@ -170,7 +170,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
if (resultCode != Activity.RESULT_OK || !data.hasExtra(EXTRA_USER) || twitter == null
|| userList == null) return;
final ParcelableUser user = data.getParcelableExtra(EXTRA_USER);
twitter.addUserListMembersAsync(new AccountKey(userList.account_id, userList.account_host), userList.id, user);
twitter.addUserListMembersAsync(userList.account_key, userList.id, user);
return;
}
case REQUEST_SELECT_ACCOUNT: {
@ -256,7 +256,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
MenuUtils.setMenuItemAvailability(menu, R.id.info, userList != null);
menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
if (userList != null) {
final boolean isMyList = userList.user_id == userList.account_id;
final boolean isMyList = userList.user_id == userList.account_key.getId();
final boolean isFollowing = userList.is_following;
MenuUtils.setMenuItemAvailability(menu, R.id.edit, isMyList);
MenuUtils.setMenuItemAvailability(menu, R.id.follow, !isMyList);
@ -289,21 +289,21 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
if (twitter == null || userList == null) return false;
switch (item.getItemId()) {
case R.id.add: {
if (userList.user_id != userList.account_id) return false;
if (userList.user_id != userList.account_key.getId()) return false;
final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
intent.setClass(getActivity(), UserListSelectorActivity.class);
intent.putExtra(EXTRA_ACCOUNT_ID, userList.account_id);
intent.putExtra(EXTRA_ACCOUNT_KEY, userList.account_key);
startActivityForResult(intent, REQUEST_SELECT_USER);
break;
}
case R.id.delete: {
if (userList.user_id != userList.account_id) return false;
if (userList.user_id != userList.account_key.getId()) return false;
DestroyUserListDialogFragment.show(getFragmentManager(), userList);
break;
}
case R.id.edit: {
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, userList.account_id);
args.putParcelable(EXTRA_ACCOUNT_KEY, userList.account_key);
args.putString(EXTRA_LIST_NAME, userList.name);
args.putString(EXTRA_DESCRIPTION, userList.description);
args.putBoolean(EXTRA_IS_PUBLIC, userList.is_public);
@ -317,8 +317,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
if (userList.is_following) {
DestroyUserListSubscriptionDialogFragment.show(getFragmentManager(), userList);
} else {
twitter.createUserListSubscriptionAsync(new AccountKey(userList.account_id,
userList.account_host), userList.id);
twitter.createUserListSubscriptionAsync(userList.account_key, userList.id);
}
return true;
}
@ -354,9 +353,8 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
case R.id.profile_image: {
final ParcelableUserList userList = mUserList;
if (userList == null) return;
IntentUtils.openUserProfile(getActivity(), new AccountKey(userList.account_id,
userList.account_host), userList.user_id, userList.user_screen_name, null,
true, null);
IntentUtils.openUserProfile(getActivity(), userList.account_key, userList.user_id,
userList.user_screen_name, null, true, null);
break;
}
}
@ -406,13 +404,14 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
final Bundle args = getArguments(), tabArgs = new Bundle();
if (args.containsKey(EXTRA_USER_LIST)) {
final ParcelableUserList userList = args.getParcelable(EXTRA_USER_LIST);
tabArgs.putLong(EXTRA_ACCOUNT_ID, userList.account_id);
assert userList != null;
tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, userList.account_key);
tabArgs.putLong(EXTRA_USER_ID, userList.user_id);
tabArgs.putString(EXTRA_SCREEN_NAME, userList.user_screen_name);
tabArgs.putLong(EXTRA_LIST_ID, userList.id);
tabArgs.putString(EXTRA_LIST_NAME, userList.name);
} else {
tabArgs.putLong(EXTRA_ACCOUNT_ID, args.getLong(EXTRA_ACCOUNT_ID, -1));
tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, args.getParcelable(EXTRA_ACCOUNT_KEY));
tabArgs.putLong(EXTRA_USER_ID, args.getLong(EXTRA_USER_ID, -1));
tabArgs.putString(EXTRA_SCREEN_NAME, args.getString(EXTRA_SCREEN_NAME));
tabArgs.putLong(EXTRA_LIST_ID, args.getLong(EXTRA_LIST_ID, -1));

View File

@ -26,6 +26,7 @@ import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
@ -111,13 +112,14 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment {
private class GetUserListTask extends AsyncTask<Object, Object, SingleResponse<ParcelableUserList>> {
@Nullable
private final AccountKey mAccountKey;
private final long mUserId;
private final long mListId;
private final String mScreenName, mListName;
private GetUserListTask(final AccountKey accountKey, final long listId, final String listName, final long userId,
final String screenName) {
private GetUserListTask(@Nullable final AccountKey accountKey, final long listId,
final String listName, final long userId, final String screenName) {
this.mAccountKey = accountKey;
this.mUserId = userId;
this.mListId = listId;
@ -128,6 +130,8 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment {
@Override
@NonNull
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
if (mAccountKey == null)
return SingleResponse.getInstance(new TwitterException("No Account"));
final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getActivity(), mAccountKey, true);
if (twitter == null) return SingleResponse.getInstance();
try {

View File

@ -34,9 +34,9 @@ import org.mariotaku.twidere.adapter.AbsUserListsAdapter;
import org.mariotaku.twidere.loader.support.UserListsLoader;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.model.message.UserListDestroyedEvent;
import org.mariotaku.twidere.util.MenuUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.model.message.UserListDestroyedEvent;
import java.util.List;
@ -68,7 +68,7 @@ public class UserListsFragment extends ParcelableUserListsFragment {
case R.id.new_user_list: {
final DialogFragment f = new CreateUserListDialogFragment();
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, getAccountId());
args.putParcelable(EXTRA_ACCOUNT_KEY, getAccountKey());
f.setArguments(args);
f.show(getFragmentManager(), null);
return true;
@ -80,9 +80,10 @@ public class UserListsFragment extends ParcelableUserListsFragment {
@Override
public void onPrepareOptionsMenu(final Menu menu) {
final MenuItem item = menu.findItem(R.id.new_user_list);
if (item == null) return;
final long accountId = getAccountId(), userId = getUserId();
if (accountId == userId) {
final AccountKey accountId = getAccountKey();
if (accountId == null || item == null) return;
final long userId = getUserId();
if (accountId.getId() == userId) {
MenuUtils.setMenuItemAvailability(menu, R.id.new_user_list, true);
} else {
MenuUtils.setMenuItemAvailability(menu, R.id.new_user_list, Utils.isMyAccount(getActivity(), getScreenName()));

View File

@ -52,18 +52,18 @@ public final class ParcelableUserLoader extends AsyncTaskLoader<SingleResponse<P
private final boolean mOmitIntentExtra, mLoadFromCache;
private final Bundle mExtras;
private final AccountKey mAccountId;
private final AccountKey mAccountKey;
private final long mUserId;
private final String mScreenName;
public ParcelableUserLoader(final Context context, final AccountKey accountId, final long userId,
public ParcelableUserLoader(final Context context, final AccountKey accountKey, final long userId,
final String screenName, final Bundle extras, final boolean omitIntentExtra,
final boolean loadFromCache) {
super(context);
this.mOmitIntentExtra = omitIntentExtra;
this.mLoadFromCache = loadFromCache;
this.mExtras = extras;
this.mAccountId = accountId;
this.mAccountKey = accountKey;
this.mUserId = userId;
this.mScreenName = screenName;
}
@ -72,7 +72,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader<SingleResponse<P
public SingleResponse<ParcelableUser> loadInBackground() {
final Context context = getContext();
final ContentResolver resolver = context.getContentResolver();
final AccountKey accountKey = mAccountId;
final AccountKey accountKey = mAccountKey;
int accountColor = DataStoreUtils.getAccountColor(context, accountKey);
if (!mOmitIntentExtra && mExtras != null) {
final ParcelableUser user = mExtras.getParcelable(EXTRA_USER);
@ -117,7 +117,8 @@ public final class ParcelableUserLoader extends AsyncTaskLoader<SingleResponse<P
final long userId = twitterUser.getId();
resolver.insert(CachedUsers.CONTENT_URI, cachedUserValues);
final ParcelableUser user = ParcelableUserUtils.fromUser(twitterUser, accountKey);
if (Utils.isMyAccount(context, user.id, user.user_host)) {
final AccountKey userAccountKey = new AccountKey(user.id, user.user_host);
if (Utils.isMyAccount(context, userAccountKey)) {
final ContentValues accountValues = new ContentValues();
accountValues.put(Accounts.NAME, user.name);
accountValues.put(Accounts.SCREEN_NAME, user.screen_name);
@ -125,9 +126,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader<SingleResponse<P
accountValues.put(Accounts.PROFILE_BANNER_URL, user.profile_banner_url);
accountValues.put(Accounts.ACCOUNT_USER, JsonSerializer.serialize(user,
ParcelableUser.class));
accountValues.put(Accounts.ACCOUNT_KEY,
String.valueOf(new AccountKey(user.id, user.user_host)));
// TODO update account key
accountValues.put(Accounts.ACCOUNT_KEY, String.valueOf(userAccountKey));
final String accountWhere = Expression.equals(Accounts.ACCOUNT_KEY, userId).getSQL();
resolver.update(Accounts.CONTENT_URI, accountValues, accountWhere, null);
}

View File

@ -28,8 +28,7 @@ public class ParcelableCredentialsUtils {
@Nullable
public static ParcelableCredentials getCredentials(@NonNull final Context context,
@NonNull final AccountKey accountKey) {
final Cursor c = DataStoreUtils.getAccountCursor(context,
Accounts.COLUMNS, accountKey);
final Cursor c = DataStoreUtils.getAccountCursor(context, Accounts.COLUMNS, accountKey);
if (c == null) return null;
try {
final ParcelableCredentialsCursorIndices i = new ParcelableCredentialsCursorIndices(c);

View File

@ -18,8 +18,7 @@ public class ParcelableUserListUtils {
ParcelableUserList obj = new ParcelableUserList();
final User user = list.getUser();
obj.position = position;
obj.account_id = accountKey.getId();
obj.account_host = accountKey.getHost();
obj.account_key = accountKey;
obj.id = list.getId();
obj.is_public = UserList.Mode.PUBLIC.equals(list.getMode());
obj.is_following = isFollowing;

View File

@ -1279,11 +1279,11 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
if (context == null) return;
final Resources resources = context.getResources();
final NotificationManagerWrapper nm = mNotificationManager;
final Expression selection = Expression.and(Utils.getAccountCompareExpression(),
final Expression selection = Expression.and(Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.greaterThan(Statuses.STATUS_ID, position));
final String filteredSelection = DataStoreUtils.buildStatusFilterWhereClause(Statuses.TABLE_NAME,
selection).getSQL();
final String[] selectionArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()};
final String[] selectionArgs = {accountKey.toString()};
final String[] userProjection = {Statuses.USER_ID, Statuses.USER_NAME, Statuses.USER_SCREEN_NAME};
final String[] statusProjection = {Statuses.STATUS_ID};
final Cursor statusCursor = mDatabaseWrapper.query(Statuses.TABLE_NAME, statusProjection,

View File

@ -32,7 +32,6 @@ import org.mariotaku.twidere.util.ErrorInfoStore;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.content.ContentResolverUtils;
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
@ -140,11 +139,12 @@ public abstract class GetActivitiesTask extends AbstractTask<RefreshTaskParam, O
}
if (deleteBound[0] > 0 && deleteBound[1] > 0) {
final Expression where = Expression.and(
Utils.getAccountCompareExpression(),
Expression.greaterEquals(Activities.MIN_POSITION, deleteBound[0]),
Expression.lesserEquals(Activities.MAX_POSITION, deleteBound[1])
Expression.equalsArgs(Activities.ACCOUNT_KEY),
Expression.greaterEqualsArgs(Activities.MIN_POSITION),
Expression.lesserEqualsArgs(Activities.MAX_POSITION)
);
final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()};
final String[] whereArgs = {accountKey.toString(), String.valueOf(deleteBound[0]),
String.valueOf(deleteBound[1])};
int rowsDeleted = cr.delete(getContentUri(), where.getSQL(), whereArgs);
boolean insertGap = valuesList.size() >= loadItemLimit && !noItemsBefore
&& rowsDeleted <= 0;

View File

@ -26,6 +26,7 @@ import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.model.AccountKey;
import org.mariotaku.twidere.model.RefreshTaskParam;
import org.mariotaku.twidere.model.message.GetStatusesTaskEvent;
import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.task.AbstractTask;
import org.mariotaku.twidere.task.CacheUsersStatusesTask;
@ -106,11 +107,11 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
statusIds[i] = id;
}
// Delete all rows conflicting before new data inserted.
final Expression accountWhere = Utils.getAccountCompareExpression();
final Expression accountWhere = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY);
final Expression statusWhere = Expression.in(new Columns.Column(Statuses.STATUS_ID),
new RawItemArray(statusIds));
final String countWhere = Expression.and(accountWhere, statusWhere).getSQL();
String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()};
final String[] whereArgs = {accountKey.toString()};
final String[] projection = {SQLFunctions.COUNT()};
final int rowsDeleted;
final Cursor countCur = resolver.query(uri, projection, countWhere, whereArgs, null);

View File

@ -892,11 +892,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
values.put(Statuses.REPLY_COUNT, status.reply_count);
values.put(Statuses.RETWEET_COUNT, status.retweet_count);
values.put(Statuses.FAVORITE_COUNT, status.favorite_count);
final Expression where = Expression.and(Utils.getAccountCompareExpression(),
Expression.or(Expression.equals(Statuses.STATUS_ID, mStatusId),
Expression.equals(Statuses.RETWEET_ID, mStatusId)));
final String[] whereArgs = {String.valueOf(mAccountKey.getId()), mAccountKey.getHost(),
String.valueOf(mStatusId), String.valueOf(mStatusId)};
final Expression where = Expression.and(
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.or(
Expression.equalsArgs(Statuses.STATUS_ID),
Expression.equalsArgs(Statuses.RETWEET_ID)
)
);
final String[] whereArgs = {mAccountKey.toString(), String.valueOf(mStatusId),
String.valueOf(mStatusId)};
for (final Uri uri : TwidereDataStore.STATUSES_URIS) {
mResolver.update(uri, values, where.getSQL(), whereArgs);
}
@ -1479,12 +1483,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
}
private void deleteMessages(final AccountKey accountKey, final long userId) {
final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost(),
String.valueOf(userId)};
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and(Utils.getAccountCompareExpression(),
Expression.equalsArgs(Inbox.SENDER_ID)).getSQL(), whereArgs);
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, Expression.and(Utils.getAccountCompareExpression(),
Expression.equalsArgs(Outbox.RECIPIENT_ID)).getSQL(), whereArgs);
final String[] whereArgs = {accountKey.toString(), String.valueOf(userId)};
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and(
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.equalsArgs(Inbox.SENDER_ID)
).getSQL(), whereArgs);
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, Expression.and(
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.equalsArgs(Outbox.RECIPIENT_ID)
).getSQL(), whereArgs);
}
private boolean isMessageNotFound(final Exception e) {
@ -1551,11 +1558,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
final ContentValues values = new ContentValues();
values.put(Statuses.IS_FAVORITE, false);
values.put(Statuses.FAVORITE_COUNT, status.favorite_count - 1);
final Expression where = Expression.and(Utils.getAccountCompareExpression(),
final Expression where = Expression.and(Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.or(Expression.equals(Statuses.STATUS_ID, mStatusId),
Expression.equals(Statuses.RETWEET_ID, mStatusId)));
String[] whereArgs = {String.valueOf(mAccountKey.getId()), mAccountKey.getHost(),
String.valueOf(mStatusId), String.valueOf(mStatusId)};
final String[] whereArgs = {mAccountKey.toString(), String.valueOf(mStatusId),
String.valueOf(mStatusId)};
for (final Uri uri : TwidereDataStore.STATUSES_URIS) {
mResolver.update(uri, values, where.getSQL(), whereArgs);
}
@ -1627,11 +1634,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
final User user = twitter.destroyFriendship(mUserId);
// remove user tweets and retweets
Utils.setLastSeen(mContext, user.getId(), -1);
final Expression where = Expression.and(Utils.getAccountCompareExpression(),
Expression.or(Expression.equals(Statuses.USER_ID, mUserId),
Expression.equals(Statuses.RETWEETED_BY_USER_ID, mUserId)));
String[] whereArgs = {String.valueOf(mAccountKey.getId()), mAccountKey.getHost(),
String.valueOf(mUserId), String.valueOf(mUserId)};
final Expression where = Expression.and(
Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY),
Expression.or(
Expression.equalsArgs(Statuses.USER_ID),
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_ID)
)
);
final String[] whereArgs = {mAccountKey.toString(), String.valueOf(mUserId),
String.valueOf(mUserId)};
mResolver.delete(Statuses.CONTENT_URI, where.getSQL(), whereArgs);
return SingleResponse.getInstance(ParcelableUserUtils.fromUser(user, mAccountKey), null);
} catch (final TwitterException e) {

View File

@ -200,37 +200,36 @@ public class DataStoreUtils implements Constants {
@NonNull
public static long[] getNewestMessageIds(@NonNull final Context context, @NonNull final Uri uri,
@NonNull final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys),
DirectMessages.ACCOUNT_KEY, DirectMessages.MESSAGE_ID,
new OrderBy(SQLFunctions.MAX(DirectMessages.MESSAGE_TIMESTAMP)));
return getLongFieldArray(context, uri, accountKeys, DirectMessages.ACCOUNT_KEY,
DirectMessages.MESSAGE_ID, new OrderBy(SQLFunctions.MAX(DirectMessages.MESSAGE_TIMESTAMP)));
}
@NonNull
public static long[] getNewestStatusIds(@NonNull final Context context, @NonNull final Uri uri,
@NonNull final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Statuses.ACCOUNT_KEY, Statuses.STATUS_ID,
new OrderBy(SQLFunctions.MAX(Statuses.STATUS_TIMESTAMP)));
return getLongFieldArray(context, uri, accountKeys, Statuses.ACCOUNT_KEY,
Statuses.STATUS_ID, new OrderBy(SQLFunctions.MAX(Statuses.STATUS_TIMESTAMP)));
}
@NonNull
public static long[] getOldestMessageIds(@NonNull final Context context, @NonNull final Uri uri,
@NonNull final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), DirectMessages.ACCOUNT_KEY,
return getLongFieldArray(context, uri, accountKeys, DirectMessages.ACCOUNT_KEY,
DirectMessages.MESSAGE_ID, new OrderBy(SQLFunctions.MIN(DirectMessages.MESSAGE_TIMESTAMP)));
}
@NonNull
public static long[] getOldestStatusIds(@NonNull final Context context, @NonNull final Uri uri,
@NonNull final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Statuses.ACCOUNT_KEY, Statuses.STATUS_ID,
new OrderBy(SQLFunctions.MIN(Statuses.STATUS_TIMESTAMP)));
return getLongFieldArray(context, uri, accountKeys, Statuses.ACCOUNT_KEY,
Statuses.STATUS_ID, new OrderBy(SQLFunctions.MIN(Statuses.STATUS_TIMESTAMP)));
}
@NonNull
public static long[] getNewestActivityMaxPositions(final Context context, final Uri uri,
final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Activities.ACCOUNT_KEY,
return getLongFieldArray(context, uri, accountKeys, Activities.ACCOUNT_KEY,
Activities.MAX_POSITION, new OrderBy(SQLFunctions.MAX(Activities.TIMESTAMP)));
}
@ -238,19 +237,20 @@ public class DataStoreUtils implements Constants {
public static long[] getOldestActivityMaxPositions(@NonNull final Context context,
@NonNull final Uri uri,
@NonNull final AccountKey[] accountKeys) {
return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Activities.ACCOUNT_KEY,
return getLongFieldArray(context, uri, accountKeys, Activities.ACCOUNT_KEY,
Activities.MAX_POSITION, new OrderBy(SQLFunctions.MIN(Activities.TIMESTAMP)));
}
public static int getStatusCount(final Context context, final Uri uri, final AccountKey accountId) {
final String where = Utils.getAccountCompareExpression().getSQL();
final String[] whereArgs = {String.valueOf(accountId.getId()), accountId.getHost()};
final String where = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).getSQL();
final String[] whereArgs = {accountId.toString()};
return queryCount(context, uri, where, whereArgs);
}
public static int getActivitiesCount(final Context context, final Uri uri, final AccountKey accountKey) {
final String where = Utils.getAccountCompareExpression().getSQL();
return queryCount(context, uri, where, new String[]{String.valueOf(accountKey.getId()), accountKey.getHost()});
public static int getActivitiesCount(@NonNull final Context context, @NonNull final Uri uri,
@NonNull final AccountKey accountKey) {
final String where = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).getSQL();
return queryCount(context, uri, where, new String[]{accountKey.toString()});
}
@ -258,7 +258,8 @@ public class DataStoreUtils implements Constants {
public static long[] getFilteredUserIds(Context context) {
if (context == null) return new long[0];
final ContentResolver resolver = context.getContentResolver();
final Cursor cur = resolver.query(Filters.Users.CONTENT_URI, new String[]{Filters.Users.USER_ID}, null, null, null);
final String[] projection = {Filters.Users.USER_ID};
final Cursor cur = resolver.query(Filters.Users.CONTENT_URI, projection, null, null, null);
if (cur == null) return new long[0];
try {
final long[] ids = new long[cur.getCount()];
@ -344,12 +345,10 @@ public class DataStoreUtils implements Constants {
final String cached = sAccountNames.get(accountKey);
if (!isEmpty(cached)) return cached;
final String[] projection = {Accounts.SCREEN_NAME};
String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()};
final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, projection,
Utils.getAccountCompareExpression().getSQL(), whereArgs, null);
final Cursor cur = getAccountCursor(context, projection, accountKey);
if (cur == null) return null;
try {
if (cur.getCount() > 0 && cur.moveToFirst()) {
if (cur.moveToFirst()) {
final String name = cur.getString(0);
sAccountNames.put(accountKey, name);
return name;
@ -365,12 +364,10 @@ public class DataStoreUtils implements Constants {
final String cached = sAccountScreenNames.get(accountKey);
if (!isEmpty(cached)) return cached;
final String[] projection = {Accounts.SCREEN_NAME};
String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()};
final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, projection,
Utils.getAccountCompareExpression().getSQL(), whereArgs, null);
final Cursor cur = getAccountCursor(context, projection, accountKey);
if (cur == null) return null;
try {
if (cur.getCount() > 0 && cur.moveToFirst()) {
if (cur.moveToFirst()) {
final String name = cur.getString(0);
sAccountScreenNames.put(accountKey, name);
return name;
@ -803,9 +800,9 @@ public class DataStoreUtils implements Constants {
}
@NonNull
static long[] getLongFieldArray(@NonNull Context context, @NonNull Uri uri, @NonNull long[] keys,
@NonNull String keyField, @NonNull String valueField,
@Nullable OrderBy sortExpression) {
static long[] getLongFieldArray(@NonNull Context context, @NonNull Uri uri,
@NonNull AccountKey[] keys, @NonNull String keyField,
@NonNull String valueField, @Nullable OrderBy sortExpression) {
final ContentResolver resolver = context.getContentResolver();
final long[] messageIds = new long[keys.length];
Arrays.fill(messageIds, -1);

View File

@ -524,8 +524,7 @@ public class IntentUtils implements Constants {
final Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_TWIDERE);
builder.authority(AUTHORITY_USER_LIST);
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, new AccountKey(userList.account_id,
userList.account_host).toString());
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, userList.account_key.toString());
builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(userId));
builder.appendQueryParameter(QUERY_PARAM_LIST_ID, String.valueOf(listId));
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());

View File

@ -110,6 +110,7 @@ import org.mariotaku.sqliteqb.library.AllColumns;
import org.mariotaku.sqliteqb.library.Columns;
import org.mariotaku.sqliteqb.library.Columns.Column;
import org.mariotaku.sqliteqb.library.Expression;
import org.mariotaku.sqliteqb.library.SQLFunctions;
import org.mariotaku.sqliteqb.library.Selectable;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;
@ -1584,22 +1585,15 @@ public final class Utils implements Constants {
public static boolean isMyAccount(final Context context, @Nullable final AccountKey accountKey) {
if (context == null || accountKey == null) return false;
return isMyAccount(context, accountKey.getId(), accountKey.getHost());
}
public static boolean isMyAccount(@NonNull final Context context, final long accountId,
final String accountHost) {
final ContentResolver resolver = context.getContentResolver();
final String where = Expression.equalsArgs(Accounts.ACCOUNT_KEY).getSQL();
final String[] projection = new String[]{};
final String[] whereArgs = {String.valueOf(accountId)};
final Cursor cur = resolver.query(Accounts.CONTENT_URI, projection, where, whereArgs, null);
final String[] projection = new String[]{SQLFunctions.COUNT()};
final Cursor cur = DataStoreUtils.getAccountCursor(context, projection, accountKey);
if (cur == null) return false;
try {
return cur.getCount() > 0;
if (cur.moveToFirst()) return cur.getLong(0) > 0;
} finally {
cur.close();
}
return false;
}
public static boolean isMyAccount(final Context context, final String screen_name) {