From 7d83d65724ab00f707513278739b9d06aa2e7306 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 20 Mar 2016 12:56:33 +0800 Subject: [PATCH] fixed #467 --- .../twidere/provider/TwidereDataStore.java | 4 ++-- .../fragment/AddStatusFilterDialogFragment.java | 4 ++-- .../twidere/fragment/BaseFiltersFragment.java | 4 ++-- .../twidere/fragment/StatusFragment.java | 9 ++++----- .../mariotaku/twidere/fragment/UserFragment.java | 2 +- .../twidere/util/ContentValuesCreator.java | 6 +++--- .../mariotaku/twidere/util/DataStoreUtils.java | 16 ++++++++-------- .../util/InternalTwitterContentUtils.java | 6 +++--- .../twidere/util/MultiSelectEventHandler.java | 2 +- .../util/content/TwidereSQLiteOpenHelper.java | 6 +++--- 10 files changed, 29 insertions(+), 30 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java index 7cc4b5828..00c6f50c5 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java @@ -634,11 +634,11 @@ public interface TwidereDataStore { String CONTENT_PATH = Filters.CONTENT_PATH + "/" + CONTENT_PATH_SEGMENT; Uri CONTENT_URI = Uri.withAppendedPath(Filters.CONTENT_URI, CONTENT_PATH_SEGMENT); - String USER_ID = "user_id"; + String USER_KEY = "user_id"; String NAME = "name"; String SCREEN_NAME = "screen_name"; - String[] COLUMNS = {_ID, USER_ID, NAME, SCREEN_NAME}; + String[] COLUMNS = {_ID, USER_KEY, NAME, SCREEN_NAME}; String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL}; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.java index b210df116..47c7e9b52 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.java @@ -127,7 +127,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment { } } final ContentResolver resolver = getContentResolver(); - ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, Filters.Users.USER_ID, userKeys, null); + ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, Filters.Users.USER_KEY, userKeys, null); ContentResolverUtils.bulkDelete(resolver, Filters.Keywords.CONTENT_URI, Filters.Keywords.VALUE, keywords, null); ContentResolverUtils.bulkDelete(resolver, Filters.Sources.CONTENT_URI, Filters.Sources.VALUE, sources, null); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, userValues); @@ -188,7 +188,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment { private static ContentValues createFilteredUser(UserItem item) { if (item == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, item.key.toString()); + values.put(Filters.Users.USER_KEY, item.key.toString()); values.put(Filters.Users.NAME, item.name); values.put(Filters.Users.SCREEN_NAME, item.screen_name); return values; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseFiltersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseFiltersFragment.java index 3822a8bfa..6dabffe16 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseFiltersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseFiltersFragment.java @@ -406,7 +406,7 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment retweeters = new ArrayList<>(); try { for (Status status : twitter.getRetweets(mStatusId, paging)) { - final User user = status.getUser(); - if (!DataStoreUtils.isFilteringUser(context, user.getId())) { - retweeters.add(ParcelableUserUtils.fromUser(user, mAccountKey)); + final ParcelableUser user = ParcelableUserUtils.fromUser(status.getUser(), mAccountKey); + if (!DataStoreUtils.isFilteringUser(context, user.key.toString())) { + retweeters.add(user); } } activitySummary.setRetweeters(retweeters); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java index d5f98c231..55b84a8c2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java @@ -1018,7 +1018,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (userRelationship == null) return true; final ContentResolver cr = getContentResolver(); if (userRelationship.isFiltering) { - final String where = Expression.equalsArgs(Filters.Users.USER_ID).getSQL(); + final String where = Expression.equalsArgs(Filters.Users.USER_KEY).getSQL(); final String[] whereArgs = {user.key.toString()}; cr.delete(Filters.Users.CONTENT_URI, where, whereArgs); Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java index e4fb499c6..57c39dd33 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java @@ -131,7 +131,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableStatus status) { if (status == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, status.user_key.toString()); + values.put(Filters.Users.USER_KEY, status.user_key.toString()); values.put(Filters.Users.NAME, status.user_name); values.put(Filters.Users.SCREEN_NAME, status.user_screen_name); return values; @@ -140,7 +140,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableUser user) { if (user == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, user.key.toString()); + values.put(Filters.Users.USER_KEY, user.key.toString()); values.put(Filters.Users.NAME, user.name); values.put(Filters.Users.SCREEN_NAME, user.screen_name); return values; @@ -149,7 +149,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableUserMention user) { if (user == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, user.key.toString()); + values.put(Filters.Users.USER_KEY, user.key.toString()); values.put(Filters.Users.NAME, user.name); values.put(Filters.Users.SCREEN_NAME, user.screen_name); return values; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java index 9371228cc..16d06b3d8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java @@ -291,7 +291,7 @@ public class DataStoreUtils implements Constants { public static String[] getFilteredUserIds(Context context) { if (context == null) return new String[0]; final ContentResolver resolver = context.getContentResolver(); - final String[] projection = {Filters.Users.USER_ID}; + final String[] projection = {Filters.Users.USER_KEY}; final Cursor cur = resolver.query(Filters.Users.CONTENT_URI, projection, null, null, null); if (cur == null) return new String[0]; try { @@ -313,7 +313,7 @@ public class DataStoreUtils implements Constants { @NonNull public static Expression buildStatusFilterWhereClause(@NonNull final String table, final Expression extraSelection) { final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder - .select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_ID)) + .select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_KEY)) .from(new Tables(Filters.Users.TABLE_NAME)) .build(); final Expression filteredUsersWhere = Expression.or( @@ -616,7 +616,7 @@ public class DataStoreUtils implements Constants { @NonNull public static Expression buildActivityFilterWhereClause(@NonNull final String table, final Expression extraSelection) { final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder - .select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_ID)) + .select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_KEY)) .from(new Tables(Filters.Users.TABLE_NAME)) .build(); final Expression filteredUsersWhere = Expression.or( @@ -790,7 +790,7 @@ public class DataStoreUtils implements Constants { .orderBy(new OrderBy(Statuses.STATUS_ID, false)) .limit(itemLimit); final Expression where = Expression.and(Expression.lesserThan(new Column(Statuses._ID), - SQLQueryBuilder.select(SQLFunctions.MIN(new Column(Statuses._ID))).from(qb.build()).build()), + SQLQueryBuilder.select(SQLFunctions.MIN(new Column(Statuses._ID))).from(qb.build()).build()), accountWhere); final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)}; resolver.delete(uri, where.getSQL(), whereArgs); @@ -849,11 +849,11 @@ public class DataStoreUtils implements Constants { sAccountScreenNames.clear(); } - public static boolean isFilteringUser(Context context, String userId) { + public static boolean isFilteringUser(Context context, String userKey) { final ContentResolver cr = context.getContentResolver(); - final Expression where = Expression.equalsArgs(Filters.Users.USER_ID); + final Expression where = Expression.equalsArgs(Filters.Users.USER_KEY); final Cursor c = cr.query(Filters.Users.CONTENT_URI, new String[]{SQLFunctions.COUNT()}, - where.getSQL(), new String[]{userId}, null); + where.getSQL(), new String[]{userKey}, null); if (c == null) return false; try { if (c.moveToFirst()) { @@ -1069,7 +1069,7 @@ public class DataStoreUtils implements Constants { } public static int getInteractionsCount(@NonNull final Context context, @Nullable final Bundle extraArgs, - final UserKey[] accountIds, final long since,final String sinceColumn) { + final UserKey[] accountIds, final long since, final String sinceColumn) { Expression extraWhere = null; String[] extraWhereArgs = null; boolean followingOnly = false; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java index 72e3aaf0e..10c66cb8b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java @@ -114,21 +114,21 @@ public class InternalTwitterContentUtils { builder.append(" OR "); } selectionArgs.add(String.valueOf(userKey)); - builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_KEY).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } if (retweetedById != null) { if (!selectionArgs.isEmpty()) { builder.append(" OR "); } selectionArgs.add(String.valueOf(retweetedById)); - builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_KEY).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } if (quotedUserId != null) { if (!selectionArgs.isEmpty()) { builder.append(" OR "); } selectionArgs.add(String.valueOf(quotedUserId)); - builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_KEY).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } if (source != null) { if (!selectionArgs.isEmpty()) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java index 0c2a449a6..035938112 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java @@ -147,7 +147,7 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback, } } ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, - Filters.Users.USER_ID, userIds, null); + Filters.Users.USER_KEY, userIds, null); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, valuesList); Toast.makeText(mActivity, R.string.message_users_muted, Toast.LENGTH_SHORT).show(); mode.finish(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/content/TwidereSQLiteOpenHelper.java b/twidere/src/main/java/org/mariotaku/twidere/util/content/TwidereSQLiteOpenHelper.java index b21cdb83d..a7d5326c2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/content/TwidereSQLiteOpenHelper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/content/TwidereSQLiteOpenHelper.java @@ -151,7 +151,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C .actions(SQLQueryBuilder.update(OnConflict.REPLACE, filteredUsersTable) .set(new SetValue(new Column(Filters.Users.NAME), new Column(Table.NEW, CachedUsers.NAME)), new SetValue(new Column(Filters.Users.SCREEN_NAME), new Column(Table.NEW, CachedUsers.SCREEN_NAME))) - .where(Expression.equals(new Column(Filters.Users.USER_ID), new Column(Table.NEW, CachedUsers.USER_KEY))) + .where(Expression.equals(new Column(Filters.Users.USER_KEY), new Column(Table.NEW, CachedUsers.USER_KEY))) .build()) .buildSQL()); @@ -273,8 +273,8 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C private void migrateFilteredUsers(SQLiteDatabase db) { db.execSQL(SQLQueryBuilder.update(OnConflict.REPLACE, Filters.Users.TABLE_NAME) - .set(new SetValue(Filters.Users.USER_ID, new RawSQLLang(Filters.Users.USER_ID + "||?"))) - .where(Expression.notLikeArgs(new Column(Filters.Users.USER_ID))) + .set(new SetValue(Filters.Users.USER_KEY, new RawSQLLang(Filters.Users.USER_KEY + "||?"))) + .where(Expression.notLikeArgs(new Column(Filters.Users.USER_KEY))) .buildSQL(), new Object[]{"@twitter.com", "%@%"}); }