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;
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};

View File

@ -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;

View File

@ -406,7 +406,7 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
final ParcelableUser user = data.getParcelableExtra(EXTRA_USER);
final ContentValues values = ContentValuesCreator.createFilteredUser(user);
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()};
resolver.delete(Filters.Users.CONTENT_URI, where, whereArgs);
resolver.insert(Filters.Users.CONTENT_URI, values);
@ -479,7 +479,7 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment<Sim
public Cursor swapCursor(final Cursor c) {
final Cursor old = super.swapCursor(c);
if (c != null) {
mUserIdIdx = c.getColumnIndex(Filters.Users.USER_ID);
mUserIdIdx = c.getColumnIndex(Filters.Users.USER_KEY);
mNameIdx = c.getColumnIndex(Filters.Users.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.Status;
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.fragment.AbsStatusesFragment.DefaultOnLikedListener;
import org.mariotaku.twidere.loader.ConversationLoader;
@ -774,7 +773,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@Override
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 ExtendedRecyclerView.ContextMenuInfo contextMenuInfo =
(ExtendedRecyclerView.ContextMenuInfo) menuInfo;
@ -2479,9 +2478,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final List<ParcelableUser> 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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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()) {

View File

@ -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();

View File

@ -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", "%@%"});
}