This commit is contained in:
Mariotaku Lee 2016-03-20 12:56:33 +08:00
parent d12e331583
commit 7d83d65724
10 changed files with 29 additions and 30 deletions

View File

@ -634,11 +634,11 @@ public interface TwidereDataStore {
String CONTENT_PATH = Filters.CONTENT_PATH + "/" + CONTENT_PATH_SEGMENT; String CONTENT_PATH = Filters.CONTENT_PATH + "/" + CONTENT_PATH_SEGMENT;
Uri CONTENT_URI = Uri.withAppendedPath(Filters.CONTENT_URI, 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 NAME = "name";
String SCREEN_NAME = "screen_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, String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL,
TYPE_TEXT_NOT_NULL}; TYPE_TEXT_NOT_NULL};

View File

@ -127,7 +127,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment {
} }
} }
final ContentResolver resolver = getContentResolver(); 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.Keywords.CONTENT_URI, Filters.Keywords.VALUE, keywords, null);
ContentResolverUtils.bulkDelete(resolver, Filters.Sources.CONTENT_URI, Filters.Sources.VALUE, sources, null); ContentResolverUtils.bulkDelete(resolver, Filters.Sources.CONTENT_URI, Filters.Sources.VALUE, sources, null);
ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, userValues); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, userValues);
@ -188,7 +188,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment {
private static ContentValues createFilteredUser(UserItem item) { private static ContentValues createFilteredUser(UserItem item) {
if (item == null) return null; if (item == null) return null;
final ContentValues values = new ContentValues(); 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.NAME, item.name);
values.put(Filters.Users.SCREEN_NAME, item.screen_name); values.put(Filters.Users.SCREEN_NAME, item.screen_name);
return values; return values;

View File

@ -406,7 +406,7 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
final ParcelableUser user = data.getParcelableExtra(EXTRA_USER); final ParcelableUser user = data.getParcelableExtra(EXTRA_USER);
final ContentValues values = ContentValuesCreator.createFilteredUser(user); final ContentValues values = ContentValuesCreator.createFilteredUser(user);
final ContentResolver resolver = getContentResolver(); final ContentResolver resolver = getContentResolver();
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()}; final String[] whereArgs = {user.key.toString()};
resolver.delete(Filters.Users.CONTENT_URI, where, whereArgs); resolver.delete(Filters.Users.CONTENT_URI, where, whereArgs);
resolver.insert(Filters.Users.CONTENT_URI, values); resolver.insert(Filters.Users.CONTENT_URI, values);
@ -479,7 +479,7 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
public Cursor swapCursor(final Cursor c) { public Cursor swapCursor(final Cursor c) {
final Cursor old = super.swapCursor(c); final Cursor old = super.swapCursor(c);
if (c != null) { if (c != null) {
mUserIdIdx = c.getColumnIndex(Filters.Users.USER_ID); mUserIdIdx = c.getColumnIndex(Filters.Users.USER_KEY);
mNameIdx = c.getColumnIndex(Filters.Users.NAME); mNameIdx = c.getColumnIndex(Filters.Users.NAME);
mScreenNameIdx = c.getColumnIndex(Filters.Users.SCREEN_NAME); mScreenNameIdx = c.getColumnIndex(Filters.Users.SCREEN_NAME);
} }

View File

@ -99,7 +99,6 @@ import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.TranslationResult; import org.mariotaku.twidere.api.twitter.model.TranslationResult;
import org.mariotaku.twidere.api.twitter.model.User;
import org.mariotaku.twidere.constant.IntentConstants; import org.mariotaku.twidere.constant.IntentConstants;
import org.mariotaku.twidere.fragment.AbsStatusesFragment.DefaultOnLikedListener; import org.mariotaku.twidere.fragment.AbsStatusesFragment.DefaultOnLikedListener;
import org.mariotaku.twidere.loader.ConversationLoader; import org.mariotaku.twidere.loader.ConversationLoader;
@ -774,7 +773,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if (!getUserVisibleHint()) return; if (!getUserVisibleHint() || menuInfo == null) return;
final MenuInflater inflater = new MenuInflater(getContext()); final MenuInflater inflater = new MenuInflater(getContext());
final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo = final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo =
(ExtendedRecyclerView.ContextMenuInfo) menuInfo; (ExtendedRecyclerView.ContextMenuInfo) menuInfo;
@ -2479,9 +2478,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final List<ParcelableUser> retweeters = new ArrayList<>(); final List<ParcelableUser> retweeters = new ArrayList<>();
try { try {
for (Status status : twitter.getRetweets(mStatusId, paging)) { for (Status status : twitter.getRetweets(mStatusId, paging)) {
final User user = status.getUser(); final ParcelableUser user = ParcelableUserUtils.fromUser(status.getUser(), mAccountKey);
if (!DataStoreUtils.isFilteringUser(context, user.getId())) { if (!DataStoreUtils.isFilteringUser(context, user.key.toString())) {
retweeters.add(ParcelableUserUtils.fromUser(user, mAccountKey)); retweeters.add(user);
} }
} }
activitySummary.setRetweeters(retweeters); activitySummary.setRetweeters(retweeters);

View File

@ -1018,7 +1018,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (userRelationship == null) return true; if (userRelationship == null) return true;
final ContentResolver cr = getContentResolver(); final ContentResolver cr = getContentResolver();
if (userRelationship.isFiltering) { 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()}; final String[] whereArgs = {user.key.toString()};
cr.delete(Filters.Users.CONTENT_URI, where, whereArgs); cr.delete(Filters.Users.CONTENT_URI, where, whereArgs);
Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false); Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);

View File

@ -131,7 +131,7 @@ public final class ContentValuesCreator implements TwidereConstants {
public static ContentValues createFilteredUser(final ParcelableStatus status) { public static ContentValues createFilteredUser(final ParcelableStatus status) {
if (status == null) return null; if (status == null) return null;
final ContentValues values = new ContentValues(); 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.NAME, status.user_name);
values.put(Filters.Users.SCREEN_NAME, status.user_screen_name); values.put(Filters.Users.SCREEN_NAME, status.user_screen_name);
return values; return values;
@ -140,7 +140,7 @@ public final class ContentValuesCreator implements TwidereConstants {
public static ContentValues createFilteredUser(final ParcelableUser user) { public static ContentValues createFilteredUser(final ParcelableUser user) {
if (user == null) return null; if (user == null) return null;
final ContentValues values = new ContentValues(); 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.NAME, user.name);
values.put(Filters.Users.SCREEN_NAME, user.screen_name); values.put(Filters.Users.SCREEN_NAME, user.screen_name);
return values; return values;
@ -149,7 +149,7 @@ public final class ContentValuesCreator implements TwidereConstants {
public static ContentValues createFilteredUser(final ParcelableUserMention user) { public static ContentValues createFilteredUser(final ParcelableUserMention user) {
if (user == null) return null; if (user == null) return null;
final ContentValues values = new ContentValues(); 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.NAME, user.name);
values.put(Filters.Users.SCREEN_NAME, user.screen_name); values.put(Filters.Users.SCREEN_NAME, user.screen_name);
return values; return values;

View File

@ -291,7 +291,7 @@ public class DataStoreUtils implements Constants {
public static String[] getFilteredUserIds(Context context) { public static String[] getFilteredUserIds(Context context) {
if (context == null) return new String[0]; if (context == null) return new String[0];
final ContentResolver resolver = context.getContentResolver(); 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); final Cursor cur = resolver.query(Filters.Users.CONTENT_URI, projection, null, null, null);
if (cur == null) return new String[0]; if (cur == null) return new String[0];
try { try {
@ -313,7 +313,7 @@ public class DataStoreUtils implements Constants {
@NonNull @NonNull
public static Expression buildStatusFilterWhereClause(@NonNull final String table, final Expression extraSelection) { public static Expression buildStatusFilterWhereClause(@NonNull final String table, final Expression extraSelection) {
final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder 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)) .from(new Tables(Filters.Users.TABLE_NAME))
.build(); .build();
final Expression filteredUsersWhere = Expression.or( final Expression filteredUsersWhere = Expression.or(
@ -616,7 +616,7 @@ public class DataStoreUtils implements Constants {
@NonNull @NonNull
public static Expression buildActivityFilterWhereClause(@NonNull final String table, final Expression extraSelection) { public static Expression buildActivityFilterWhereClause(@NonNull final String table, final Expression extraSelection) {
final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder 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)) .from(new Tables(Filters.Users.TABLE_NAME))
.build(); .build();
final Expression filteredUsersWhere = Expression.or( final Expression filteredUsersWhere = Expression.or(
@ -790,7 +790,7 @@ public class DataStoreUtils implements Constants {
.orderBy(new OrderBy(Statuses.STATUS_ID, false)) .orderBy(new OrderBy(Statuses.STATUS_ID, false))
.limit(itemLimit); .limit(itemLimit);
final Expression where = Expression.and(Expression.lesserThan(new Column(Statuses._ID), 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); accountWhere);
final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)}; final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)};
resolver.delete(uri, where.getSQL(), whereArgs); resolver.delete(uri, where.getSQL(), whereArgs);
@ -849,11 +849,11 @@ public class DataStoreUtils implements Constants {
sAccountScreenNames.clear(); sAccountScreenNames.clear();
} }
public static boolean isFilteringUser(Context context, String userId) { public static boolean isFilteringUser(Context context, String userKey) {
final ContentResolver cr = context.getContentResolver(); 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()}, 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; if (c == null) return false;
try { try {
if (c.moveToFirst()) { if (c.moveToFirst()) {
@ -1069,7 +1069,7 @@ public class DataStoreUtils implements Constants {
} }
public static int getInteractionsCount(@NonNull final Context context, @Nullable final Bundle extraArgs, 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; Expression extraWhere = null;
String[] extraWhereArgs = null; String[] extraWhereArgs = null;
boolean followingOnly = false; boolean followingOnly = false;

View File

@ -114,21 +114,21 @@ public class InternalTwitterContentUtils {
builder.append(" OR "); builder.append(" OR ");
} }
selectionArgs.add(String.valueOf(userKey)); 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 (retweetedById != null) {
if (!selectionArgs.isEmpty()) { if (!selectionArgs.isEmpty()) {
builder.append(" OR "); builder.append(" OR ");
} }
selectionArgs.add(String.valueOf(retweetedById)); 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 (quotedUserId != null) {
if (!selectionArgs.isEmpty()) { if (!selectionArgs.isEmpty()) {
builder.append(" OR "); builder.append(" OR ");
} }
selectionArgs.add(String.valueOf(quotedUserId)); 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 (source != null) {
if (!selectionArgs.isEmpty()) { if (!selectionArgs.isEmpty()) {

View File

@ -147,7 +147,7 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback,
} }
} }
ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, 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); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, valuesList);
Toast.makeText(mActivity, R.string.message_users_muted, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.message_users_muted, Toast.LENGTH_SHORT).show();
mode.finish(); mode.finish();

View File

@ -151,7 +151,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C
.actions(SQLQueryBuilder.update(OnConflict.REPLACE, filteredUsersTable) .actions(SQLQueryBuilder.update(OnConflict.REPLACE, filteredUsersTable)
.set(new SetValue(new Column(Filters.Users.NAME), new Column(Table.NEW, CachedUsers.NAME)), .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))) 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()) .build())
.buildSQL()); .buildSQL());
@ -273,8 +273,8 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C
private void migrateFilteredUsers(SQLiteDatabase db) { private void migrateFilteredUsers(SQLiteDatabase db) {
db.execSQL(SQLQueryBuilder.update(OnConflict.REPLACE, Filters.Users.TABLE_NAME) db.execSQL(SQLQueryBuilder.update(OnConflict.REPLACE, Filters.Users.TABLE_NAME)
.set(new SetValue(Filters.Users.USER_ID, new RawSQLLang(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_ID))) .where(Expression.notLikeArgs(new Column(Filters.Users.USER_KEY)))
.buildSQL(), .buildSQL(),
new Object[]{"@twitter.com", "%@%"}); new Object[]{"@twitter.com", "%@%"});
} }