This commit is contained in:
Mariotaku Lee 2015-06-30 09:26:13 +08:00
parent 6b02d12ea3
commit 67f7ed52c9
1 changed files with 29 additions and 21 deletions

View File

@ -1890,7 +1890,7 @@ public final class Utils implements Constants {
final long[] messageIds = new long[accountIds.length]; final long[] messageIds = new long[accountIds.length];
int idx = 0; int idx = 0;
for (final long accountId : accountIds) { for (final long accountId : accountIds) {
final String where = Statuses.ACCOUNT_ID + " = " + accountId; final String where = Expression.equals(DirectMessages.ACCOUNT_ID, accountId).getSQL();
final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null, final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null,
DirectMessages.DEFAULT_SORT_ORDER); DirectMessages.DEFAULT_SORT_ORDER);
if (cur == null) { if (cur == null) {
@ -1912,14 +1912,14 @@ public final class Utils implements Constants {
return getNewestStatusIdsFromDatabase(context, uri, account_ids); return getNewestStatusIdsFromDatabase(context, uri, account_ids);
} }
public static long[] getNewestStatusIdsFromDatabase(final Context context, final Uri uri, final long[] account_ids) { public static long[] getNewestStatusIdsFromDatabase(final Context context, final Uri uri, final long[] accountIds) {
if (context == null || uri == null || account_ids == null) return null; if (context == null || uri == null || accountIds == null) return null;
final String[] cols = new String[]{Statuses.STATUS_ID}; final String[] cols = new String[]{Statuses.STATUS_ID};
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final long[] status_ids = new long[account_ids.length]; final long[] status_ids = new long[accountIds.length];
int idx = 0; int idx = 0;
for (final long account_id : account_ids) { for (final long accountId : accountIds) {
final String where = Statuses.ACCOUNT_ID + " = " + account_id; final String where = Expression.equals(Statuses.ACCOUNT_ID, accountId).getSQL();
final Cursor cur = ContentResolverUtils final Cursor cur = ContentResolverUtils
.query(resolver, uri, cols, where, null, Statuses.DEFAULT_SORT_ORDER); .query(resolver, uri, cols, where, null, Statuses.DEFAULT_SORT_ORDER);
if (cur == null) { if (cur == null) {
@ -1968,14 +1968,14 @@ public final class Utils implements Constants {
return getOldestMessageIdsFromDatabase(context, uri, account_ids); return getOldestMessageIdsFromDatabase(context, uri, account_ids);
} }
public static long[] getOldestMessageIdsFromDatabase(final Context context, final Uri uri, final long[] account_ids) { public static long[] getOldestMessageIdsFromDatabase(final Context context, final Uri uri, final long[] accountIds) {
if (context == null || uri == null) return null; if (context == null || uri == null) return null;
final String[] cols = new String[]{DirectMessages.MESSAGE_ID}; final String[] cols = new String[]{DirectMessages.MESSAGE_ID};
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final long[] status_ids = new long[account_ids.length]; final long[] status_ids = new long[accountIds.length];
int idx = 0; int idx = 0;
for (final long account_id : account_ids) { for (final long accountId : accountIds) {
final String where = Statuses.ACCOUNT_ID + " = " + account_id; final String where = Expression.equals(DirectMessages.ACCOUNT_ID, accountId).getSQL();
final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null, DirectMessages.MESSAGE_ID); final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null, DirectMessages.MESSAGE_ID);
if (cur == null) { if (cur == null) {
continue; continue;
@ -1996,14 +1996,14 @@ public final class Utils implements Constants {
return getOldestStatusIdsFromDatabase(context, uri, account_ids); return getOldestStatusIdsFromDatabase(context, uri, account_ids);
} }
public static long[] getOldestStatusIdsFromDatabase(final Context context, final Uri uri, final long[] account_ids) { public static long[] getOldestStatusIdsFromDatabase(final Context context, final Uri uri, final long[] accountIds) {
if (context == null || uri == null || account_ids == null) return null; if (context == null || uri == null || accountIds == null) return null;
final String[] cols = new String[]{Statuses.STATUS_ID}; final String[] cols = new String[]{Statuses.STATUS_ID};
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final long[] status_ids = new long[account_ids.length]; final long[] status_ids = new long[accountIds.length];
int idx = 0; int idx = 0;
for (final long account_id : account_ids) { for (final long accountId : accountIds) {
final String where = Statuses.ACCOUNT_ID + " = " + account_id; final String where = Expression.equals(Statuses.ACCOUNT_ID, accountId).getSQL();
final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null, Statuses.STATUS_ID); final Cursor cur = ContentResolverUtils.query(resolver, uri, cols, where, null, Statuses.STATUS_ID);
if (cur == null) { if (cur == null) {
continue; continue;
@ -2439,10 +2439,10 @@ public final class Utils implements Constants {
status.retweeted_by_user_id, filter_rts); status.retweeted_by_user_id, filter_rts);
} }
public static boolean isMyAccount(final Context context, final long account_id) { public static boolean isMyAccount(final Context context, final long accountId) {
if (context == null) return false; if (context == null) return false;
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final String where = Accounts.ACCOUNT_ID + " = " + account_id; final String where = Expression.equals(Accounts.ACCOUNT_ID, accountId).getSQL();
final Cursor cur = ContentResolverUtils.query(resolver, Accounts.CONTENT_URI, new String[0], where, null, null); final Cursor cur = ContentResolverUtils.query(resolver, Accounts.CONTENT_URI, new String[0], where, null, null);
try { try {
return cur != null && cur.getCount() > 0; return cur != null && cur.getCount() > 0;
@ -2456,7 +2456,7 @@ public final class Utils implements Constants {
public static boolean isMyAccount(final Context context, final String screen_name) { public static boolean isMyAccount(final Context context, final String screen_name) {
if (context == null) return false; if (context == null) return false;
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final String where = Accounts.SCREEN_NAME + " = ?"; final String where = Expression.equalsArgs(Accounts.SCREEN_NAME).getSQL();
final Cursor cur = ContentResolverUtils.query(resolver, Accounts.CONTENT_URI, new String[0], where, final Cursor cur = ContentResolverUtils.query(resolver, Accounts.CONTENT_URI, new String[0], where,
new String[]{screen_name}, null); new String[]{screen_name}, null);
try { try {
@ -2472,8 +2472,8 @@ public final class Utils implements Constants {
return status != null && isMyRetweet(status.account_id, status.retweeted_by_user_id, status.my_retweet_id); return status != null && isMyRetweet(status.account_id, status.retweeted_by_user_id, status.my_retweet_id);
} }
public static boolean isMyRetweet(final long account_id, final long retweeted_by_id, final long my_retweet_id) { public static boolean isMyRetweet(final long accountId, final long retweetedById, final long myRetweetId) {
return retweeted_by_id == account_id || my_retweet_id > 0; return retweetedById == accountId || myRetweetId > 0;
} }
public static boolean isNetworkAvailable(final Context context) { public static boolean isNetworkAvailable(final Context context) {
@ -3241,7 +3241,7 @@ public final class Utils implements Constants {
final boolean isMyRetweet = isMyRetweet(status); final boolean isMyRetweet = isMyRetweet(status);
final MenuItem delete = menu.findItem(MENU_DELETE); final MenuItem delete = menu.findItem(MENU_DELETE);
if (delete != null) { if (delete != null) {
delete.setVisible(status.account_id == status.user_id && !isMyRetweet); delete.setVisible(isMyStatus(status));
} }
final MenuItem retweet = menu.findItem(MENU_RETWEET); final MenuItem retweet = menu.findItem(MENU_RETWEET);
if (retweet != null) { if (retweet != null) {
@ -3279,6 +3279,14 @@ public final class Utils implements Constants {
} }
private static boolean isMyStatus(ParcelableStatus status) {
if (isMyRetweet(status)) return true;
if (status.is_quote) {
return status.account_id == status.quoted_by_user_id;
}
return status.account_id == status.user_id;
}
public static boolean shouldForceUsingPrivateAPIs(final Context context) { public static boolean shouldForceUsingPrivateAPIs(final Context context) {
if (context == null) return false; if (context == null) return false;
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);