diff --git a/twidere.component.common/src/main/aidl/org/mariotaku/twidere/IStatusShortener.aidl b/twidere.component.common/src/main/aidl/org/mariotaku/twidere/IStatusShortener.aidl index a12ec6b42..2cc981215 100644 --- a/twidere.component.common/src/main/aidl/org/mariotaku/twidere/IStatusShortener.aidl +++ b/twidere.component.common/src/main/aidl/org/mariotaku/twidere/IStatusShortener.aidl @@ -20,7 +20,7 @@ package org.mariotaku.twidere; interface IStatusShortener { - String shorten(String statusJson, long currentAccountId, String overrideStatusText); + String shorten(String statusJson, String currentAccountId, String overrideStatusText); boolean callback(String resultJson, String statusJson); diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/AccountKey.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/AccountKey.java index de161b4ee..0fffc203d 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/AccountKey.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/AccountKey.java @@ -45,11 +45,6 @@ public class AccountKey implements Comparable, Parcelable { this.host = host; } - public AccountKey(ParcelableAccount account) { - this.id = account.account_id; - this.host = account.account_host; - } - AccountKey() { } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java index adf0c593a..87cb4914c 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableAccount.java @@ -30,6 +30,8 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorObject; +import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.AccountKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -43,6 +45,11 @@ public class ParcelableAccount implements Parcelable { @CursorField(value = Accounts._ID, excludeWrite = true) public long id; + @ParcelableThisPlease + @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) + @CursorField(value = Accounts.ACCOUNT_KEY, converter = AccountKeyCursorFieldConverter.class) + public AccountKey account_key; + @ParcelableThisPlease @JsonField(name = "screen_name") @CursorField(Accounts.SCREEN_NAME) @@ -53,6 +60,12 @@ public class ParcelableAccount implements Parcelable { @CursorField(Accounts.NAME) public String name; + @Nullable + @ParcelableThisPlease + @JsonField(name = "account_type") + @CursorField(Accounts.ACCOUNT_TYPE) + public String account_type; + @ParcelableThisPlease @JsonField(name = "profile_image_url") @CursorField(Accounts.PROFILE_IMAGE_URL) @@ -63,11 +76,6 @@ public class ParcelableAccount implements Parcelable { @CursorField(Accounts.PROFILE_BANNER_URL) public String profile_banner_url; - @ParcelableThisPlease - @JsonField(name = "account_id") - @CursorField(Accounts.ACCOUNT_ID) - public long account_id; - @ParcelableThisPlease @JsonField(name = "color") @CursorField(Accounts.COLOR) @@ -77,18 +85,6 @@ public class ParcelableAccount implements Parcelable { @JsonField(name = "is_activated") @CursorField(Accounts.IS_ACTIVATED) public boolean is_activated; - - @Nullable - @ParcelableThisPlease - @JsonField(name = "account_type") - @CursorField(Accounts.ACCOUNT_TYPE) - public String account_type; - - @ParcelableThisPlease - @JsonField(name = "account_host") - @CursorField(Accounts.ACCOUNT_HOST) - public String account_host; - @Nullable @ParcelableThisPlease @JsonField(name = "account_user") @@ -121,15 +117,15 @@ public class ParcelableAccount implements Parcelable { @Override public String toString() { return "ParcelableAccount{" + - "screen_name='" + screen_name + '\'' + + "id=" + id + + ", account_key=" + account_key + + ", screen_name='" + screen_name + '\'' + ", name='" + name + '\'' + + ", account_type='" + account_type + '\'' + ", profile_image_url='" + profile_image_url + '\'' + ", profile_banner_url='" + profile_banner_url + '\'' + - ", account_id=" + account_id + ", color=" + color + ", is_activated=" + is_activated + - ", account_type='" + account_type + '\'' + - ", account_host='" + account_host + '\'' + ", account_user=" + account_user + ", is_dummy=" + is_dummy + '}'; @@ -142,16 +138,13 @@ public class ParcelableAccount implements Parcelable { ParcelableAccount account = (ParcelableAccount) o; - if (id != account.id) return false; - return !(account_host != null ? !account_host.equals(account.account_host) : account.account_host != null); + return account_key.equals(account.account_key); } @Override public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (account_host != null ? account_host.hashCode() : 0); - return result; + return account_key.hashCode(); } @Override diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableActivity.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableActivity.java index 8781207bf..5802573bc 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableActivity.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableActivity.java @@ -32,6 +32,8 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorObject; import org.mariotaku.twidere.api.twitter.model.Activity; +import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.AccountKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.model.util.LongArrayConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -59,13 +61,9 @@ public class ParcelableActivity implements Comparable, Parce @CursorField(value = Activities._ID, excludeWrite = true) public long _id; @ParcelableThisPlease - @JsonField(name = "account_id") - @CursorField(value = Activities.ACCOUNT_ID) - public long account_id; - @ParcelableThisPlease - @JsonField(name = "account_host") - @CursorField(value = Activities.ACCOUNT_HOST) - public String account_host; + @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) + @CursorField(value = Activities.ACCOUNT_KEY, converter = AccountKeyCursorFieldConverter.class) + public AccountKey account_key; @ParcelableThisPlease @JsonField(name = "timestamp") @CursorField(value = Activities.TIMESTAMP) @@ -144,22 +142,24 @@ public class ParcelableActivity implements Comparable, Parce return null; } - public static int calculateHashCode(long account_id, long timestamp, long max_position, long min_position) { - int result = (int) (account_id ^ (account_id >>> 32)); + public static int calculateHashCode(AccountKey accountKey, long timestamp, long maxPosition, long minPosition) { + int result = accountKey.hashCode(); result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); - result = 31 * result + (int) (max_position ^ (max_position >>> 32)); - result = 31 * result + (int) (min_position ^ (min_position >>> 32)); + result = 31 * result + (int) (maxPosition ^ (maxPosition >>> 32)); + result = 31 * result + (int) (minPosition ^ (minPosition >>> 32)); return result; } @Override public String toString() { return "ParcelableActivity{" + - "account_id=" + account_id + + "_id=" + _id + + ", account_key=" + account_key + ", timestamp=" + timestamp + ", max_position=" + max_position + ", min_position=" + min_position + - ", action=" + action + + ", action='" + action + '\'' + + ", source_ids=" + Arrays.toString(source_ids) + ", sources=" + Arrays.toString(sources) + ", target_users=" + Arrays.toString(target_users) + ", target_statuses=" + Arrays.toString(target_statuses) + @@ -168,12 +168,15 @@ public class ParcelableActivity implements Comparable, Parce ", target_object_statuses=" + Arrays.toString(target_object_statuses) + ", target_object_users=" + Arrays.toString(target_object_users) + ", is_gap=" + is_gap + + ", status_user_following=" + status_user_following + + ", after_filtered_source_ids=" + Arrays.toString(after_filtered_source_ids) + + ", after_filtered_sources=" + Arrays.toString(after_filtered_sources) + '}'; } @Override public int hashCode() { - return calculateHashCode(account_id, timestamp, max_position, min_position); + return calculateHashCode(account_key, timestamp, max_position, min_position); } @Override diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java index 0f174d5f5..6cbb55516 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableDirectMessage.java @@ -30,6 +30,8 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorObject; +import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.AccountKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; @@ -53,13 +55,9 @@ public class ParcelableDirectMessage implements Parcelable, Comparable>> 32); - result = prime * result + (int) (id ^ id >>> 32); + int result = account_key.hashCode(); + result = 31 * result + (int) (id ^ (id >>> 32)); return result; } @Override public String toString() { return "ParcelableDirectMessage{" + - "account_id=" + account_id + + "account_key=" + account_key + ", id=" + id + ", timestamp=" + timestamp + ", sender_id=" + sender_id + diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java index 7dc5c6d51..ecfb60888 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java @@ -34,6 +34,8 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; import org.mariotaku.library.objectcursor.annotation.AfterCursorObjectCreated; import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorObject; +import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.AccountKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; @@ -60,13 +62,9 @@ public class ParcelableStatus implements Parcelable, Comparable>> 32)); - result = 31 * result + (int) (accountId ^ (accountId >>> 32)); - result = 31 * result + (accountHost != null ? accountHost.hashCode() : 0); + result = 31 * result + account_key.hashCode(); return result; } @@ -361,7 +357,7 @@ public class ParcelableStatus implements Parcelable, Comparable { public ParcelableUser() { } - public ParcelableUser(final long account_id, final long id, final String name, + public ParcelableUser(final AccountKey account_key, final long id, final String name, final String screen_name, final String profile_image_url) { - this.account_id = account_id; + this.account_key = account_key; this.id = id; this.name = name; this.screen_name = screen_name; @@ -231,25 +229,32 @@ public class ParcelableUser implements Parcelable, Comparable { } @Override - public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof ParcelableUser)) return false; - final ParcelableUser other = (ParcelableUser) 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; + + ParcelableUser user = (ParcelableUser) o; + + if (id != user.id) return false; + return account_key.equals(user.account_key); + } @Override public int hashCode() { - return calculateHashCode(account_id, id); + return calculateHashCode(account_key, id); + } + + public static int calculateHashCode(AccountKey account_key, long id) { + int result = account_key.hashCode(); + result = 31 * result + (int) (id ^ (id >>> 32)); + return result; } @Override public String toString() { return "ParcelableUser{" + - "account_id=" + account_id + + "account_id=" + account_key + ", account_color=" + account_color + ", id=" + id + ", created_at=" + created_at + diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyConverter.java new file mode 100644 index 000000000..491605e05 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyConverter.java @@ -0,0 +1,28 @@ +package org.mariotaku.twidere.model.util; + +import android.content.ContentValues; +import android.database.Cursor; + +import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter; + +import org.mariotaku.library.objectcursor.converter.CursorFieldConverter; +import org.mariotaku.twidere.model.AccountKey; + +import java.lang.reflect.ParameterizedType; + +/** + * Created by mariotaku on 16/3/7. + */ +public class AccountKeyConverter extends StringBasedTypeConverter { + + @Override + public AccountKey getFromString(String string) { + return AccountKey.valueOf(string); + } + + @Override + public String convertToString(AccountKey object) { + if (object == null) return null; + return object.toString(); + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyCursorFieldConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyCursorFieldConverter.java new file mode 100644 index 000000000..b986ac5ee --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyCursorFieldConverter.java @@ -0,0 +1,26 @@ +package org.mariotaku.twidere.model.util; + +import android.content.ContentValues; +import android.database.Cursor; + +import org.mariotaku.library.objectcursor.converter.CursorFieldConverter; +import org.mariotaku.twidere.model.AccountKey; + +import java.lang.reflect.ParameterizedType; + +/** + * Created by mariotaku on 16/3/7. + */ +public class AccountKeyCursorFieldConverter implements CursorFieldConverter { + @Override + public AccountKey parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) { + return AccountKey.valueOf(cursor.getString(columnIndex)); + } + + @Override + public void writeField(ContentValues values, AccountKey object, String columnName, ParameterizedType fieldType) { + if (object == null) return; + values.put(columnName, object.toString()); + } + +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeysCursorFieldConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeysCursorFieldConverter.java index 0fc01219d..c6856066b 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeysCursorFieldConverter.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeysCursorFieldConverter.java @@ -7,7 +7,6 @@ import org.mariotaku.twidere.model.AccountKey; */ public class AccountKeysCursorFieldConverter extends AbsObjectArrayConverter { - @Override protected AccountKey[] newArray(int size) { return new AccountKey[size]; 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 c4c603bb0..f35bc5db8 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 @@ -73,8 +73,7 @@ public interface TwidereDataStore { interface AccountSupportColumns { - String ACCOUNT_ID = "account_id"; - String ACCOUNT_HOST = "account_host"; + String ACCOUNT_KEY = "account_id"; } @@ -155,17 +154,16 @@ public interface TwidereDataStore { String ACCOUNT_USER = "account_user"; - String[] COLUMNS_NO_CREDENTIALS = {_ID, NAME, SCREEN_NAME, ACCOUNT_ID, PROFILE_IMAGE_URL, - PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_USER, - ACCOUNT_HOST}; + String[] COLUMNS_NO_CREDENTIALS = {_ID, NAME, SCREEN_NAME, ACCOUNT_KEY, PROFILE_IMAGE_URL, + PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_USER}; - String[] COLUMNS = {_ID, NAME, SCREEN_NAME, ACCOUNT_ID, AUTH_TYPE, BASIC_AUTH_USERNAME, + String[] COLUMNS = {_ID, NAME, SCREEN_NAME, ACCOUNT_KEY, AUTH_TYPE, BASIC_AUTH_USERNAME, BASIC_AUTH_PASSWORD, OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET, API_URL_FORMAT, SAME_OAUTH_SIGNING_URL, NO_VERSION_SUFFIX, PROFILE_IMAGE_URL, PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_EXTRAS, - ACCOUNT_USER, ACCOUNT_HOST}; + ACCOUNT_USER}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_INT, + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_BOOLEAN, TYPE_BOOLEAN, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_BOOLEAN, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT}; @@ -405,7 +403,7 @@ public interface TwidereDataStore { String MEDIA_JSON = "media_json"; - String[] COLUMNS = {_ID, ACCOUNT_ID, MESSAGE_ID, MESSAGE_TIMESTAMP, + String[] COLUMNS = {_ID, ACCOUNT_KEY, MESSAGE_ID, MESSAGE_TIMESTAMP, SENDER_ID, RECIPIENT_ID, CONVERSATION_ID, IS_OUTGOING, TEXT_HTML, TEXT_PLAIN, TEXT_UNESCAPED, SENDER_NAME, RECIPIENT_NAME, SENDER_SCREEN_NAME, RECIPIENT_SCREEN_NAME, SENDER_PROFILE_IMAGE_URL, RECIPIENT_PROFILE_IMAGE_URL, MEDIA_JSON, INSERTED_DATE}; @@ -443,8 +441,7 @@ public interface TwidereDataStore { Uri CONTENT_URI = Uri.withAppendedPath(DirectMessages.CONTENT_URI, CONTENT_PATH_SEGMENT); String MESSAGE_ID = DirectMessages.MESSAGE_ID; - String ACCOUNT_ID = DirectMessages.ACCOUNT_ID; - String ACCOUNT_HOST = DirectMessages.ACCOUNT_HOST; + String ACCOUNT_KEY = DirectMessages.ACCOUNT_KEY; String IS_OUTGOING = DirectMessages.IS_OUTGOING; String MESSAGE_TIMESTAMP = DirectMessages.MESSAGE_TIMESTAMP; String NAME = "name"; @@ -456,14 +453,13 @@ public interface TwidereDataStore { int IDX__ID = 0; int IDX_MESSAGE_TIMESTAMP = 1; int IDX_MESSAGE_ID = 2; - int IDX_ACCOUNT_ID = 3; - int IDX_ACCOUNT_HOST = 4; - int IDX_IS_OUTGOING = 5; - int IDX_NAME = 6; - int IDX_SCREEN_NAME = 7; - int IDX_PROFILE_IMAGE_URL = 8; - int IDX_TEXT = 9; - int IDX_CONVERSATION_ID = 10; + int IDX_ACCOUNT_KEY = 3; + int IDX_IS_OUTGOING = 4; + int IDX_NAME = 5; + int IDX_SCREEN_NAME = 6; + int IDX_PROFILE_IMAGE_URL = 7; + int IDX_TEXT = 8; + int IDX_CONVERSATION_ID = 9; } interface Inbox extends DirectMessages { @@ -536,8 +532,8 @@ public interface TwidereDataStore { String NAME = "name"; String CREATED_AT = "created_at"; - String[] COLUMNS = {_ID, ACCOUNT_ID, ACCOUNT_HOST, SEARCH_ID, CREATED_AT, QUERY, NAME}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_TEXT, + String[] COLUMNS = {_ID, ACCOUNT_KEY, SEARCH_ID, CREATED_AT, QUERY, NAME}; + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT}; String DEFAULT_SORT_ORDER = CREATED_AT + " DESC"; } @@ -875,7 +871,7 @@ public interface TwidereDataStore { String EXTRAS = "extras"; - String[] COLUMNS = {_ID, ACCOUNT_ID, ACCOUNT_HOST, STATUS_ID, USER_ID, STATUS_TIMESTAMP, + String[] COLUMNS = {_ID, ACCOUNT_KEY, STATUS_ID, USER_ID, STATUS_TIMESTAMP, TEXT_HTML, TEXT_PLAIN, TEXT_UNESCAPED, USER_NAME, USER_SCREEN_NAME, USER_PROFILE_IMAGE_URL, IN_REPLY_TO_STATUS_ID, IN_REPLY_TO_USER_ID, IN_REPLY_TO_USER_NAME, IN_REPLY_TO_USER_SCREEN_NAME, SOURCE, LOCATION, RETWEET_COUNT, FAVORITE_COUNT, REPLY_COUNT, @@ -889,7 +885,7 @@ public interface TwidereDataStore { PLACE_FULL_NAME, LANG, RETWEETED, QUOTED_LOCATION, QUOTED_PLACE_FULL_NAME, INSERTED_DATE, EXTRAS}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_INT, + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, @@ -930,13 +926,13 @@ public interface TwidereDataStore { String TARGET_OBJECT_USER_LISTS = "target_object_user_lists"; String TARGET_OBJECT_USERS = "target_object_users"; - String[] COLUMNS = {_ID, ACCOUNT_ID, ACCOUNT_HOST, ACTION, TIMESTAMP, STATUS_ID, STATUS_USER_ID, + String[] COLUMNS = {_ID, ACCOUNT_KEY, ACTION, TIMESTAMP, STATUS_ID, STATUS_USER_ID, STATUS_RETWEETED_BY_USER_ID, STATUS_QUOTED_USER_ID, STATUS_SOURCE, STATUS_QUOTE_SOURCE, STATUS_TEXT_PLAIN, STATUS_QUOTE_TEXT_PLAIN, STATUS_TEXT_HTML, STATUS_QUOTE_TEXT_HTML, IS_GAP, MIN_POSITION, MAX_POSITION, SOURCES, SOURCE_IDS, TARGET_STATUSES, TARGET_USERS, TARGET_USER_LISTS, TARGET_OBJECT_STATUSES, TARGET_OBJECT_USER_LISTS, TARGET_OBJECT_USERS, STATUS_RETWEET_ID, STATUS_USER_FOLLOWING, INSERTED_DATE}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_INT, + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_BOOLEAN, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_BOOLEAN, INSERTED_DATE_TYPE}; @@ -1009,10 +1005,10 @@ public interface TwidereDataStore { String RETWEET_ENABLED = "retweet_enabled"; - String[] COLUMNS = {_ID, ACCOUNT_ID, ACCOUNT_HOST, USER_ID, FOLLOWING, FOLLOWED_BY, BLOCKING, + String[] COLUMNS = {_ID, ACCOUNT_KEY, USER_ID, FOLLOWING, FOLLOWED_BY, BLOCKING, BLOCKED_BY, MUTING, RETWEET_ENABLED}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT, TYPE_TEXT, TYPE_INT, TYPE_BOOLEAN_DEFAULT_FALSE, + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_BOOLEAN_DEFAULT_FALSE, TYPE_BOOLEAN_DEFAULT_FALSE, TYPE_BOOLEAN_DEFAULT_FALSE, TYPE_BOOLEAN_DEFAULT_FALSE, TYPE_BOOLEAN_DEFAULT_FALSE, TYPE_BOOLEAN_DEFAULT_TRUE}; } diff --git a/twidere.component.common/src/main/res/values/values.xml b/twidere.component.common/src/main/res/values/values.xml index 5072f4ab0..576e3d34c 100644 --- a/twidere.component.common/src/main/res/values/values.xml +++ b/twidere.component.common/src/main/res/values/values.xml @@ -1,5 +1,5 @@ - 2 + 3 2 \ No newline at end of file diff --git a/twidere.extension.shortener.gist/src/main/java/org/mariotaku/twidere/extension/shortener/gist/GistStatusShortenerService.java b/twidere.extension.shortener.gist/src/main/java/org/mariotaku/twidere/extension/shortener/gist/GistStatusShortenerService.java index 881e8338f..e15312f55 100644 --- a/twidere.extension.shortener.gist/src/main/java/org/mariotaku/twidere/extension/shortener/gist/GistStatusShortenerService.java +++ b/twidere.extension.shortener.gist/src/main/java/org/mariotaku/twidere/extension/shortener/gist/GistStatusShortenerService.java @@ -22,6 +22,7 @@ package org.mariotaku.twidere.extension.shortener.gist; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; @@ -34,7 +35,7 @@ import org.mariotaku.twidere.service.StatusShortenerService; public class GistStatusShortenerService extends StatusShortenerService { @Override - protected StatusShortenResult shorten(ParcelableStatusUpdate status, long currentAccountId, String overrideStatusText) { + protected StatusShortenResult shorten(ParcelableStatusUpdate status, AccountKey currentAccountKey, String overrideStatusText) { final Github github = GithubFactory.getInstance(getApiKey()); final NewGist newGist = new NewGist(); newGist.setDescription("long tweet"); diff --git a/twidere.extension.twitlonger/src/main/java/org/mariotaku/twidere/extension/twitlonger/TwitLongerStatusShortenerService.java b/twidere.extension.twitlonger/src/main/java/org/mariotaku/twidere/extension/twitlonger/TwitLongerStatusShortenerService.java index de6a6ea40..e91f6c4b2 100644 --- a/twidere.extension.twitlonger/src/main/java/org/mariotaku/twidere/extension/twitlonger/TwitLongerStatusShortenerService.java +++ b/twidere.extension.twitlonger/src/main/java/org/mariotaku/twidere/extension/twitlonger/TwitLongerStatusShortenerService.java @@ -9,6 +9,7 @@ import android.support.annotation.Nullable; import android.util.Log; import org.mariotaku.twidere.Twidere; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; @@ -30,7 +31,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp */ @Override protected StatusShortenResult shorten(final ParcelableStatusUpdate status, - final long currentAccountId, + final AccountKey currentAccountKey, final String overrideStatusText) { final int granted = Twidere.isPermissionGranted(this); if (granted == Twidere.Permission.DENIED) { @@ -56,7 +57,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp } final ParcelableCredentials credentials; try { - credentials = getOAuthCredentials(currentAccountId); + credentials = getOAuthCredentials(currentAccountKey); } catch (SecurityException e) { if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); @@ -98,7 +99,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp if (result.extra == null) return false; final ParcelableCredentials credentials; try { - credentials = getOAuthCredentials(status.account_id); + credentials = getOAuthCredentials(status.account_key); } catch (SecurityException e) { if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); @@ -118,7 +119,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp } @Nullable - private ParcelableCredentials getOAuthCredentials(long accountId) { + private ParcelableCredentials getOAuthCredentials(AccountKey accountId) { ParcelableCredentials credentials = Twidere.getCredentials(this, accountId); if (credentials == null) return null; switch (credentials.auth_type) { diff --git a/twidere.library.extension/src/main/java/org/mariotaku/twidere/Twidere.java b/twidere.library.extension/src/main/java/org/mariotaku/twidere/Twidere.java index ab8a85869..d6cfd9fc0 100644 --- a/twidere.library.extension/src/main/java/org/mariotaku/twidere/Twidere.java +++ b/twidere.library.extension/src/main/java/org/mariotaku/twidere/Twidere.java @@ -33,6 +33,7 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ComposingStatus; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices; @@ -232,11 +233,13 @@ public final class Twidere implements TwidereConstants { } @Nullable - public static ParcelableCredentials getCredentials(final Context context, final long accountId) throws SecurityException { - if (context == null || accountId < 0) return null; - final String selection = Accounts.ACCOUNT_ID + " = ?"; + public static ParcelableCredentials getCredentials(@NonNull final Context context, + @NonNull final AccountKey accountId) + throws SecurityException { + final String selection = Accounts.ACCOUNT_KEY + " = ?"; final String[] selectionArgs = {String.valueOf(accountId)}; - Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, selection, selectionArgs, null); + Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, + selection, selectionArgs, null); if (cur == null) return null; try { if (cur.moveToFirst()) { diff --git a/twidere.library.extension/src/main/java/org/mariotaku/twidere/service/StatusShortenerService.java b/twidere.library.extension/src/main/java/org/mariotaku/twidere/service/StatusShortenerService.java index babd40cc9..a26d8e84f 100644 --- a/twidere.library.extension/src/main/java/org/mariotaku/twidere/service/StatusShortenerService.java +++ b/twidere.library.extension/src/main/java/org/mariotaku/twidere/service/StatusShortenerService.java @@ -7,6 +7,7 @@ import android.os.IBinder; import android.os.RemoteException; import org.mariotaku.twidere.IStatusShortener; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.StatusShortenResult; @@ -28,7 +29,7 @@ public abstract class StatusShortenerService extends Service { } protected abstract StatusShortenResult shorten(ParcelableStatusUpdate status, - long currentAccountId, + AccountKey currentAccountKey, String overrideStatusText); protected abstract boolean callback(StatusShortenResult result, ParcelableStatus status); @@ -47,13 +48,15 @@ public abstract class StatusShortenerService extends Service { } @Override - public String shorten(final String statusJson, final long currentAccountId, + public String shorten(final String statusJson, final String currentAccountIdStr, final String overrideStatusText) throws RemoteException { try { final ParcelableStatusUpdate statusUpdate = LoganSquareMapperFinder.mapperFor(ParcelableStatusUpdate.class) .parse(statusJson); - final StatusShortenResult shorten = mService.get().shorten(statusUpdate, currentAccountId, overrideStatusText); + final AccountKey currentAccountId = AccountKey.valueOf(currentAccountIdStr); + final StatusShortenResult shorten = mService.get().shorten(statusUpdate, currentAccountId, + overrideStatusText); return LoganSquareMapperFinder.mapperFor(StatusShortenResult.class).serialize(shorten); } catch (IOException e) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java index 263896e22..415018d78 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java @@ -24,6 +24,8 @@ import android.support.annotation.NonNull; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; +import org.mariotaku.twidere.model.AccountKey; + /** * Created by mariotaku on 15/8/8. */ @@ -33,6 +35,8 @@ public class ScrollRecord implements LogModel { long id; @JsonField(name = "account_id") long accountId; + @JsonField(name = "account_host") + String accountHost; @JsonField(name = "timestamp") long timestamp; @JsonField(name = "time_offset") @@ -40,10 +44,11 @@ public class ScrollRecord implements LogModel { @JsonField(name = "scroll_state") int scrollState; - public static ScrollRecord create(long id, long accountId, long timestamp, long timeOffset, int scrollState) { + public static ScrollRecord create(long id, AccountKey accountKey, long timestamp, long timeOffset, int scrollState) { final ScrollRecord record = new ScrollRecord(); record.setId(id); - record.setAccountId(accountId); + record.setAccountId(accountKey.getId()); + record.setAccountHost(accountKey.getHost()); record.setTimestamp(timestamp); record.setTimeOffset(timeOffset); record.setScrollState(scrollState); @@ -54,6 +59,10 @@ public class ScrollRecord implements LogModel { this.accountId = accountId; } + public void setAccountHost(String accountHost) { + accountHost = accountHost; + } + public void setTimeOffset(long timeOffset) { this.timeOffset = timeOffset; } diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java index 3ddabe82d..313f49979 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java @@ -83,8 +83,8 @@ public class TweetEvent extends BaseEvent implements Parcelable { final TweetEvent event = new TweetEvent(); event.markStart(context); event.setId(status.id); - event.setAccountId(status.account_id); - event.setAccountHost(status.account_host); + event.setAccountId(status.account_key.getId()); + event.setAccountHost(status.account_key.getHost()); event.setUserId(status.user_id); event.setTimelineType(timelineType); event.setTweetType(TwidereDataUtils.getTweetType(status)); diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java index a40ced34f..39aaa5376 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java @@ -25,6 +25,9 @@ public class UserEvent extends BaseEvent implements Parcelable { @JsonField(name = "account_id") long accountId; @ParcelableThisPlease + @JsonField(name = "account_host") + String accountHost; + @ParcelableThisPlease @JsonField(name = "user_id") long userId; @ParcelableThisPlease @@ -61,7 +64,8 @@ public class UserEvent extends BaseEvent implements Parcelable { } public void setUser(@NonNull ParcelableUser user) { - accountId = user.account_id; + accountId = user.account_key.getId(); + accountHost = user.account_key.getHost(); userId = user.id; statusCount = user.statuses_count; followerCount = user.followers_count; @@ -87,7 +91,8 @@ public class UserEvent extends BaseEvent implements Parcelable { @Override public String toString() { return "UserEvent{" + - "mAccountKey=" + accountId + + "accountId=" + accountId + + ", accountHost='" + accountHost + '\'' + ", userId=" + userId + ", statusCount=" + statusCount + ", followerCount=" + followerCount + diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountSelectorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountSelectorActivity.java index 93c1eeae5..9276c4f70 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountSelectorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/AccountSelectorActivity.java @@ -38,7 +38,6 @@ import android.widget.Toast; import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.AccountsAdapter; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -122,8 +121,8 @@ public class AccountSelectorActivity extends BaseSupportDialogActivity implement public void onItemClick(final AdapterView parent, final View view, final int position, final long id) { final Intent data = new Intent(); final ParcelableAccount account = mAdapter.getAccount(position); - data.putExtra(EXTRA_ID, account.account_id); - data.putExtra(EXTRA_KEY, new AccountKey(account.account_id, account.account_host)); + data.putExtra(EXTRA_ID, account.account_key.getId()); + data.putExtra(EXTRA_KEY, account.account_key); setResult(RESULT_OK, data); finish(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java index cbee5fb58..02e076836 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java @@ -1023,13 +1023,12 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte private boolean handleMentionIntent(final ParcelableUser user) { if (user == null || user.id <= 0) return false; - final String accountScreenName = DataStoreUtils.getAccountScreenName(this, - new AccountKey(user.account_id, user.account_host)); + final String accountScreenName = DataStoreUtils.getAccountScreenName(this, user.account_key); if (TextUtils.isEmpty(accountScreenName)) return false; mEditText.setText(String.format("@%s ", user.screen_name)); final int selection_end = mEditText.length(); mEditText.setSelection(selection_end); - mAccountsAdapter.setSelectedAccountIds(new AccountKey(user.account_id, user.account_host)); + mAccountsAdapter.setSelectedAccountIds(user.account_key); return true; } @@ -1037,7 +1036,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte if (status == null || status.id <= 0) return false; mEditText.setText(Utils.getQuoteStatus(this, status.id, status.user_screen_name, status.text_plain)); mEditText.setSelection(0); - mAccountsAdapter.setSelectedAccountIds(new AccountKey(status.account_id, status.account_host)); + mAccountsAdapter.setSelectedAccountIds(status.account_key); showQuoteLabel(status); return true; } @@ -1071,13 +1070,12 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte private boolean handleReplyIntent(final ParcelableStatus status) { if (status == null || status.id <= 0) return false; - final String myScreenName = DataStoreUtils.getAccountScreenName(this, - new AccountKey(status.account_id, status.account_host)); + final String myScreenName = DataStoreUtils.getAccountScreenName(this, status.account_key); if (TextUtils.isEmpty(myScreenName)) return false; int selectionStart = 0; mEditText.append("@" + status.user_screen_name + " "); // If replying status from current user, just exclude it's screen name from selection. - if (status.account_id != status.user_id) { + if (status.account_key.getId() != status.user_id) { selectionStart = mEditText.length(); } if (status.is_retweet) { @@ -1099,7 +1097,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } final int selectionEnd = mEditText.length(); mEditText.setSelection(selectionStart, selectionEnd); - mAccountsAdapter.setSelectedAccountIds(new AccountKey(status.account_id, status.account_host)); + mAccountsAdapter.setSelectedAccountIds(status.account_key); showReplyLabel(status); return true; } @@ -1130,8 +1128,9 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } private boolean isQuotingProtectedStatus() { - if (!isQuote() || mInReplyToStatus == null) return false; - return mInReplyToStatus.user_is_protected && mInReplyToStatus.account_id != mInReplyToStatus.user_id; + final ParcelableStatus status = mInReplyToStatus; + if (!isQuote() || status == null) return false; + return status.user_is_protected && status.account_key.getId() != status.user_id; } private boolean noReplyContent(final String text) { @@ -1147,7 +1146,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte if (ArrayUtils.isEmpty(accounts)) { mEditText.setAccountKey(Utils.getDefaultAccountKey(this)); } else { - mEditText.setAccountKey(new AccountKey(accounts[0])); + mEditText.setAccountKey(accounts[0].account_key); } mSendTextCountView.setMaxLength(TwidereValidator.getTextLimit(accounts)); setMenu(); @@ -1501,7 +1500,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte @Override public long getItemId(int position) { - return mAccounts[position].account_id; + return System.identityHashCode(mAccounts[position]); } @NonNull @@ -1510,8 +1509,8 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte final AccountKey[] temp = new AccountKey[mAccounts.length]; int selectedCount = 0; for (ParcelableAccount account : mAccounts) { - if (Boolean.TRUE.equals(mSelection.get(new AccountKey(account.account_id, account.account_host)))) { - temp[selectedCount++] = new AccountKey(account.account_id, account.account_host); + if (Boolean.TRUE.equals(mSelection.get(account.account_key))) { + temp[selectedCount++] = account.account_key; } } final AccountKey[] result = new AccountKey[selectedCount]; @@ -1535,7 +1534,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte final ParcelableCredentials[] temp = new ParcelableCredentials[mAccounts.length]; int selectedCount = 0; for (ParcelableCredentials account : mAccounts) { - if (Boolean.TRUE.equals(mSelection.get(new AccountKey(account.account_id, account.account_host)))) { + if (Boolean.TRUE.equals(mSelection.get(account.account_key))) { temp[selectedCount++] = account; } } @@ -1557,7 +1556,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte @Override public void onBindViewHolder(AccountIconViewHolder holder, int position) { final ParcelableAccount account = mAccounts[position]; - final boolean isSelected = Boolean.TRUE.equals(mSelection.get(new AccountKey(account.account_id, account.account_host))); + final boolean isSelected = Boolean.TRUE.equals(mSelection.get(account.account_key)); holder.showAccount(this, account, isSelected); } @@ -1574,8 +1573,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte private void toggleSelection(int position) { if (mAccounts == null) return; final ParcelableCredentials account = mAccounts[position]; - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); - mSelection.put(accountKey, !Boolean.TRUE.equals(mSelection.get(accountKey))); + mSelection.put(account.account_key, !Boolean.TRUE.equals(mSelection.get(account.account_key))); mActivity.notifyAccountSelectionChanged(); notifyDataSetChanged(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java index 7bee9daba..195d5f47d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/CustomTabEditorActivity.java @@ -396,7 +396,7 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement final int pos = mAccountSpinner.getSelectedItemPosition(); if (mAccountSpinner.getCount() > pos && pos >= 0) { ParcelableCredentials credentials = mAccountsAdapter.getItem(pos); - return new AccountKey(credentials.account_id, credentials.account_host); + return credentials.account_key; } return null; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java index a917a19f6..a58366147 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java @@ -294,7 +294,8 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On private AccountKey getSelectedAccountKey() { final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem(); - return new AccountKey(account.account_id, account.account_host); + if (account == null) return null; + return account.account_key; } private void updateWindowAttributes() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java index bbfae419c..0c3ee33e8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java @@ -92,7 +92,6 @@ import org.mariotaku.twidere.model.TwitterAccountExtra; import org.mariotaku.twidere.model.util.ParcelableUserUtils; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.util.AsyncTaskUtils; -import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.JsonSerializer; import org.mariotaku.twidere.util.OAuthPasswordAuthenticator; import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.AuthenticationException; @@ -104,6 +103,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TwidereActionModeForChildListener; import org.mariotaku.twidere.util.TwitterAPIFactory; +import org.mariotaku.twidere.util.TwitterContentUtils; import org.mariotaku.twidere.util.UserAgentUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.support.ViewSupport; @@ -115,7 +115,6 @@ import org.mariotaku.twidere.view.iface.TintedStatusLayout; import java.lang.ref.WeakReference; import static android.text.TextUtils.isEmpty; -import static org.mariotaku.twidere.util.ContentValuesCreator.createAccount; import static org.mariotaku.twidere.util.DataStoreUtils.getActivatedAccountKeys; import static org.mariotaku.twidere.util.Utils.getNonEmptyString; import static org.mariotaku.twidere.util.Utils.isUserLoggedIn; @@ -452,7 +451,7 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList if (result.alreadyLoggedIn) { final ContentValues values = result.toContentValues(); if (values != null) { - mResolver.update(Accounts.CONTENT_URI, values, Expression.equals(Accounts.ACCOUNT_ID, + mResolver.update(Accounts.CONTENT_URI, values, Expression.equals(Accounts.ACCOUNT_KEY, result.user.getId()).getSQL(), null); } Toast.makeText(this, R.string.error_already_logged_in, Toast.LENGTH_SHORT).show(); @@ -991,7 +990,7 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList public final User user; public final int authType, color; public final String apiUrlFormat; - public final boolean sameOauthSigningUrl, noVersionSuffix; + public final boolean sameOAuthSigningUrl, noVersionSuffix; public final Pair accountType; public SignInResponse(final boolean alreadyLoggedIn, final boolean succeed, @@ -1004,7 +1003,7 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList final Exception exception, final String basicUsername, final String basicPassword, final OAuthAuthorization oauth, final User user, final int authType, final int color, - final String apiUrlFormat, final boolean sameOauthSigningUrl, + final String apiUrlFormat, final boolean sameOAuthSigningUrl, final boolean noVersionSuffix, final Pair accountType) { this.alreadyLoggedIn = alreadyLoggedIn; this.succeed = succeed; @@ -1016,17 +1015,17 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList this.authType = authType; this.color = color; this.apiUrlFormat = apiUrlFormat; - this.sameOauthSigningUrl = sameOauthSigningUrl; + this.sameOAuthSigningUrl = sameOAuthSigningUrl; this.noVersionSuffix = noVersionSuffix; this.accountType = accountType; } public SignInResponse(final boolean alreadyLoggedIn, final OAuthAuthorization oauth, final User user, final int authType, final int color, - final String apiUrlFormat, final boolean sameOauthSigningUrl, + final String apiUrlFormat, final boolean sameOAuthSigningUrl, final boolean noVersionSuffix, final Pair accountType) { this(alreadyLoggedIn, true, null, null, null, oauth, user, authType, color, apiUrlFormat, - sameOauthSigningUrl, noVersionSuffix, accountType); + sameOAuthSigningUrl, noVersionSuffix, accountType); } public SignInResponse(final boolean alreadyLoggedIn, final String basicUsername, @@ -1047,34 +1046,57 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList } private ContentValues toContentValues() { + if (user == null || user.getId() <= 0) return null; final ContentValues values; switch (authType) { case ParcelableCredentials.AUTH_TYPE_BASIC: { - values = createAccount(basicUsername, basicPassword, user, color, apiUrlFormat, - noVersionSuffix); + values = new ContentValues(); + values.put(Accounts.BASIC_AUTH_USERNAME, basicUsername); + values.put(Accounts.BASIC_AUTH_PASSWORD, basicPassword); + values.put(Accounts.AUTH_TYPE, ParcelableCredentials.AUTH_TYPE_BASIC); break; } case ParcelableCredentials.AUTH_TYPE_TWIP_O_MODE: { - values = ContentValuesCreator.createAccount(user, color, apiUrlFormat, noVersionSuffix); + values = new ContentValues(); + values.put(Accounts.AUTH_TYPE, ParcelableCredentials.AUTH_TYPE_TWIP_O_MODE); break; } case ParcelableCredentials.AUTH_TYPE_OAUTH: case ParcelableCredentials.AUTH_TYPE_XAUTH: { - values = ContentValuesCreator.createAccount(oauth, user, authType, color, apiUrlFormat, - sameOauthSigningUrl, noVersionSuffix); + values = new ContentValues(); + final OAuthToken accessToken = oauth.getOauthToken(); + values.put(Accounts.OAUTH_TOKEN, accessToken.getOauthToken()); + values.put(Accounts.OAUTH_TOKEN_SECRET, accessToken.getOauthTokenSecret()); + values.put(Accounts.CONSUMER_KEY, oauth.getConsumerKey()); + values.put(Accounts.CONSUMER_SECRET, oauth.getConsumerSecret()); + values.put(Accounts.AUTH_TYPE, authType); break; } default: { - values = null; + return null; } } - if (values != null && accountType != null) { + + values.put(Accounts.ACCOUNT_KEY, user.getId()); + values.put(Accounts.SCREEN_NAME, user.getScreenName()); + values.put(Accounts.NAME, user.getName()); + values.put(Accounts.PROFILE_IMAGE_URL, TwitterContentUtils.getProfileImageUrl(user)); + values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); + + values.put(Accounts.COLOR, color); + values.put(Accounts.IS_ACTIVATED, 1); + + + values.put(Accounts.API_URL_FORMAT, apiUrlFormat); + values.put(Accounts.SAME_OAUTH_SIGNING_URL, sameOAuthSigningUrl); + values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); + + if (accountType != null) { values.put(Accounts.ACCOUNT_TYPE, accountType.first); values.put(Accounts.ACCOUNT_EXTRAS, accountType.second); final AccountKey accountKey = new AccountKey(user.getId(), ParcelableUserUtils.getUserHost(user.getOstatusUri())); final ParcelableUser parcelableUser = ParcelableUserUtils.fromUser(user, accountKey); - values.put(Accounts.ACCOUNT_HOST, ParcelableUserUtils.getUserHost(parcelableUser)); values.put(Accounts.ACCOUNT_USER, JsonSerializer.serialize(parcelableUser, ParcelableUser.class)); } return values; diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java index eff053259..1aca56904 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java @@ -36,7 +36,6 @@ import org.mariotaku.twidere.adapter.iface.IActivitiesAdapter; import org.mariotaku.twidere.api.twitter.model.Activity; import org.mariotaku.twidere.fragment.support.CursorActivitiesFragment; import org.mariotaku.twidere.fragment.support.UserFragment; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; @@ -439,9 +438,8 @@ public abstract class AbsActivitiesAdapter extends LoadMoreSupportAdapter< final ParcelableActivity activity = adapter.getActivity(position); final ParcelableStatus status = ParcelableActivity.getActivityStatus(activity); assert status != null; - IntentUtils.openUserProfile(context, new AccountKey(status.account_id, - status.account_host), status.user_id, status.user_screen_name, null, true, - UserFragment.Referral.TIMELINE_STATUS); + IntentUtils.openUserProfile(context, status.account_key, status.user_id, + status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java index 3f830bd09..9d8c6759e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java @@ -24,6 +24,7 @@ import android.database.Cursor; import android.support.v7.widget.RecyclerView; import org.mariotaku.library.objectcursor.ObjectCursor; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusCursorIndices; @@ -65,10 +66,9 @@ public abstract class AbsParcelableStatusesAdapter extends AbsStatusesAdapter
  • = getStatusCount()) return RecyclerView.NO_ID; + if (dataPosition < 0 || dataPosition >= getStatusCount()) return null; if (mData instanceof ObjectCursor) { final Cursor cursor = ((ObjectCursor) mData).getCursor(dataPosition); final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData).getIndices(); - return cursor.getLong(indices.account_id); + return AccountKey.valueOf(cursor.getString(indices.account_key)); } - return mData.get(dataPosition).account_id; + return mData.get(dataPosition).account_key; } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java index a90eb892e..000b8d26d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java @@ -12,6 +12,7 @@ import android.view.ViewGroup; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.MediaLoadingHandler; @@ -282,9 +283,11 @@ public abstract class AbsStatusesAdapter extends LoadMoreSupportAdapter, } @Override - public long getAccountId(int position) { - return 0; + @Nullable + public AccountKey getAccountKey(int position) { + return null; } @Nullable @Override - public ParcelableStatus findStatusById(long accountId, long statusId) { + public ParcelableStatus findStatusById(AccountKey accountId, long statusId) { return null; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java index 07e666bc7..5c5fe2867 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java @@ -168,9 +168,9 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter im private boolean isUnread(Cursor c) { if (mPositionPairs == null) return true; - final long accountId = c.getLong(ConversationEntries.IDX_ACCOUNT_ID); + final long accountId = c.getLong(ConversationEntries.IDX_ACCOUNT_KEY); final long conversationId = c.getLong(ConversationEntries.IDX_CONVERSATION_ID); final long messageId = c.getLong(ConversationEntries.IDX_MESSAGE_ID); final String key = accountId + "-" + conversationId; @@ -241,14 +242,12 @@ public class MessageEntriesAdapter extends LoadMoreSupportAdapter im public static class DirectMessageEntry { - public final long account_id; - public final String account_host; + public final AccountKey account_key; public final long conversation_id; public final String screen_name, name; DirectMessageEntry(Cursor cursor) { - account_id = cursor.getLong(ConversationEntries.IDX_ACCOUNT_ID); - account_host = cursor.getString(ConversationEntries.IDX_ACCOUNT_HOST); + account_key = AccountKey.valueOf(cursor.getString(ConversationEntries.IDX_ACCOUNT_KEY)); conversation_id = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID); screen_name = cursor.getString(ConversationEntries.IDX_SCREEN_NAME); name = cursor.getString(ConversationEntries.IDX_NAME); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java index 3a2b75a03..7ce704adf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java @@ -25,6 +25,7 @@ import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import org.mariotaku.library.objectcursor.ObjectCursor; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityCursorIndices; import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder; @@ -58,12 +59,11 @@ public class ParcelableActivitiesAdapter extends AbsActivitiesAdapter } public int findPosition(AccountKey accountKey, long userId) { - return findPosition(accountKey.getId(), accountKey.getHost(), userId); - } - - public int findPosition(long accountId, String accountHost, long userId) { if (mData == null) return RecyclerView.NO_POSITION; for (int i = getUserStartIndex(), j = i + getUserCount(); i < j; i++) { final ParcelableUser user = mData.get(i); - if (user.account_id == accountId && user.id == userId) { + if (user.account_key.equals(accountKey) && user.id == userId) { return i; } } return RecyclerView.NO_POSITION; } + } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java index 2bd81bb80..118105d8b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java @@ -101,8 +101,7 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse mediaImageView.setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(firstMedia.type)); loader.displayProfileImage(mediaProfileImageView, status.user_profile_image_url); loader.displayPreviewImageWithCredentials(mediaImageView, firstMedia.preview_url, - new AccountKey(status.account_id, status.account_host), - adapter.getMediaLoadingHandler()); + status.account_key, adapter.getMediaLoadingHandler()); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IStatusesAdapter.java index ef00da321..fcc06ecb5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/iface/IStatusesAdapter.java @@ -3,6 +3,7 @@ package org.mariotaku.twidere.adapter.iface; import android.support.annotation.Nullable; import android.view.View; +import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.MediaLoadingHandler; @@ -25,10 +26,11 @@ public interface IStatusesAdapter extends IContentCardAdapter, IGapSupport long getStatusId(int position); - long getAccountId(int position); + @Nullable + AccountKey getAccountKey(int position); @Nullable - ParcelableStatus findStatusById(long accountId, long statusId); + ParcelableStatus findStatusById(AccountKey accountKey, long statusId); int getStatusCount(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java index 04d669a66..156862edd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java @@ -49,7 +49,7 @@ public abstract class BaseAccountPreferenceFragment extends BasePreferenceFragme final PreferenceManager pm = getPreferenceManager(); final ParcelableAccount account = getArguments().getParcelable(EXTRA_ACCOUNT); final String preferenceName = ACCOUNT_PREFERENCES_NAME_PREFIX - + (account != null ? account.account_id : "unknown"); + + (account != null ? account.account_key : "unknown"); pm.setSharedPreferencesName(preferenceName); addPreferencesFromResource(getPreferencesResource()); final SharedPreferences prefs = pm.getSharedPreferences(); @@ -58,8 +58,8 @@ public abstract class BaseAccountPreferenceFragment extends BasePreferenceFragme final Intent intent = activity.getIntent(); if (account != null && intent.hasExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT)) { final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST, true); - final String name = mUserColorNameManager.getDisplayName(account.account_id, account.name, - account.screen_name, nameFirst, false); + final String name = mUserColorNameManager.getDisplayName(account.account_key.getId(), + account.name, account.screen_name, nameFirst, false); activity.setTitle(name); } updatePreferenceScreen(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java index ba6af34fb..88c16a3b1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java @@ -90,7 +90,8 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler private final OnScrollListener mHotMobiScrollTracker = new OnScrollListener() { public List mRecords; - private long mFirstVisibleTimestamp = -1, mFirstVisibleAccountId = -1; + private long mFirstVisibleTimestamp = -1; + private AccountKey mFirstVisibleAccountId = null; private int mFirstVisiblePosition = -1; private int mScrollState; @@ -103,15 +104,16 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler final AbsActivitiesAdapter adapter = (AbsActivitiesAdapter) recyclerView.getAdapter(); final ParcelableActivity activity = adapter.getActivity(firstVisiblePosition); if (activity != null) { - final long timestamp = activity.timestamp, accountId = activity.account_id; - if (timestamp != mFirstVisibleTimestamp || accountId != mFirstVisibleAccountId) { + final long timestamp = activity.timestamp; + final AccountKey accountKey = activity.account_key; + if (timestamp != mFirstVisibleTimestamp || !accountKey.equals(mFirstVisibleAccountId)) { if (mRecords == null) mRecords = new ArrayList<>(); final long time = System.currentTimeMillis(); - mRecords.add(ScrollRecord.create(timestamp, accountId, time, + mRecords.add(ScrollRecord.create(timestamp, accountKey, time, TimeZone.getDefault().getOffset(time), mScrollState)); } mFirstVisibleTimestamp = timestamp; - mFirstVisibleAccountId = accountId; + mFirstVisibleAccountId = accountKey; } } mFirstVisiblePosition = firstVisiblePosition; @@ -190,8 +192,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler case ACTION_STATUS_FAVORITE: { final AsyncTwitterWrapper twitter = mTwitterWrapper; if (status.is_favorite) { - twitter.destroyFavoriteAsync(new AccountKey(activity.account_id, - activity.account_host), status.id); + twitter.destroyFavoriteAsync(status.account_key, status.id); } else { final IStatusViewHolder holder = (IStatusViewHolder) recyclerView.findViewHolderForLayoutPosition(position); @@ -339,7 +340,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler public void onGapClick(GapViewHolder holder, int position) { final AbsActivitiesAdapter adapter = getAdapter(); final ParcelableActivity activity = adapter.getActivity(position); - final AccountKey[] accountIds = {new AccountKey(activity.account_id, activity.account_host)}; + final AccountKey[] accountIds = {activity.account_key}; final long[] maxIds = {activity.min_position}; getActivities(new BaseRefreshTaskParam(accountIds, maxIds, null)); } @@ -353,8 +354,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler // BEGIN HotMobi final MediaEvent event = MediaEvent.create(getActivity(), status, media, getTimelineType(), adapter.isMediaPreviewEnabled()); - HotMobiLogger.getInstance(getActivity()).log(new AccountKey(status.account_id, - status.account_host), event); + HotMobiLogger.getInstance(getActivity()).log(status.account_key, event); // END HotMobi } @@ -383,8 +383,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler final AsyncTwitterWrapper twitter = mTwitterWrapper; if (twitter == null) return; if (status.is_favorite) { - twitter.destroyFavoriteAsync(new AccountKey(status.account_id, - status.account_host), status.id); + twitter.destroyFavoriteAsync(status.account_key, status.id); } else { holder.playLikeAnimation(new DefaultOnLikedListener(twitter, status)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index 5da0bfd9c..de49a55ef 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -89,7 +89,8 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi private final OnScrollListener mHotMobiScrollTracker = new OnScrollListener() { public List mRecords; - private long mFirstVisibleId = -1, mFirstVisibleAccountId = -1; + private long mFirstVisibleId = -1; + private AccountKey mFirstVisibleAccountId = null; private int mFirstVisiblePosition = -1; private int mScrollState; @@ -102,8 +103,9 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi final AbsStatusesAdapter adapter = (AbsStatusesAdapter) recyclerView.getAdapter(); final ParcelableStatus status = adapter.getStatus(firstVisiblePosition); if (status != null) { - final long id = status.id, accountId = status.account_id; - if (id != mFirstVisibleId || accountId != mFirstVisibleAccountId) { + final long id = status.id; + final AccountKey accountId = status.account_key; + if (id != mFirstVisibleId || !accountId.equals(mFirstVisibleAccountId)) { if (mRecords == null) mRecords = new ArrayList<>(); final long time = System.currentTimeMillis(); mRecords.add(ScrollRecord.create(id, accountId, time, @@ -187,8 +189,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi case ACTION_STATUS_FAVORITE: { final AsyncTwitterWrapper twitter = mTwitterWrapper; if (status.is_favorite) { - twitter.destroyFavoriteAsync(new AccountKey(status.account_id, - status.account_host), status.id); + twitter.destroyFavoriteAsync(status.account_key, status.id); } else { final IStatusViewHolder holder = (IStatusViewHolder) recyclerView.findViewHolderForLayoutPosition(position); @@ -320,7 +321,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi final AbsStatusesAdapter adapter = getAdapter(); final ParcelableStatus status = adapter.getStatus(position); if (status == null) return; - final AccountKey[] accountIds = {new AccountKey(status.account_id, status.account_host)}; + final AccountKey[] accountIds = {status.account_key}; final long[] maxIds = {status.id}; getStatuses(new BaseRefreshTaskParam(accountIds, maxIds, null)); } @@ -334,8 +335,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi // BEGIN HotMobi final MediaEvent event = MediaEvent.create(getActivity(), status, media, getTimelineType(), adapter.isMediaPreviewEnabled()); - HotMobiLogger.getInstance(getActivity()).log(new AccountKey(status.account_id, - status.account_host), event); + HotMobiLogger.getInstance(getActivity()).log(status.account_key, event); // END HotMobi } @@ -372,8 +372,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi final AsyncTwitterWrapper twitter = mTwitterWrapper; if (twitter == null) return; if (status.is_favorite) { - twitter.destroyFavoriteAsync(new AccountKey(status.account_id, - status.account_host), status.id); + twitter.destroyFavoriteAsync(status.account_key, status.id); } else { holder.playLikeAnimation(new DefaultOnLikedListener(twitter, status)); } @@ -406,9 +405,8 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi @Override public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) { final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, new AccountKey(status.account_id, status.account_host), - status.user_id, status.user_screen_name, null, true, - UserFragment.Referral.TIMELINE_STATUS); + IntentUtils.openUserProfile(activity, status.account_key, status.user_id, + status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } @Override @@ -597,8 +595,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi public boolean onLiked() { final ParcelableStatus status = mStatus; if (status.is_favorite) return false; - mTwitter.createFavoriteAsync(new AccountKey(status.account_id, status.account_host), - status.id); + mTwitter.createFavoriteAsync(status.account_key, status.id); return true; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java index 9a24bfe5f..51ec119e9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java @@ -34,7 +34,6 @@ import org.mariotaku.twidere.adapter.AbsUsersAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserAdapterListener; import org.mariotaku.twidere.loader.iface.IExtendedLoader; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.util.IntentUtils; import org.mariotaku.twidere.util.KeyboardShortcutsHandler; @@ -113,8 +112,8 @@ abstract class AbsUsersFragment extends AbsContentListRecyclerViewFragment public void onUserClick(UserViewHolder holder, int position) { final ParcelableUser user = getAdapter().getUser(position); final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, new AccountKey(user.account_id, user.account_host), - user.id, user.screen_name, null, true, getUserReferral()); + IntentUtils.openUserProfile(activity, user.account_key, user.id, user.screen_name, null, + true, getUserReferral()); } @UserFragment.Referral diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java index 480d7f304..c22b2feeb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java @@ -76,6 +76,7 @@ import com.commonsware.cwac.merge.MergeAdapter; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; +import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.SettingsActivity; @@ -247,8 +248,8 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final ParcelableAccount account = mAccountsAdapter.getSelectedAccount(); if (account == null) return; final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, new AccountKey(account.account_id, - account.account_host), account.account_id, account.screen_name, null, true, + IntentUtils.openUserProfile(activity, account.account_key, + account.account_key.getId(), account.screen_name, null, true, UserFragment.Referral.SELF_PROFILE); break; } @@ -280,7 +281,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo AccountKey defaultId = null; for (ParcelableAccount account : accounts) { if (account.is_activated) { - defaultId = new AccountKey(account.account_id, account.account_host); + defaultId = account.account_key; break; } } @@ -291,7 +292,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo if (accountKey == null) { accountKey = defaultId; } - mAccountsAdapter.setSelectedAccountId(accountKey); + mAccountsAdapter.setSelectedAccountKey(accountKey); mAccountOptionsAdapter.setSelectedAccount(mAccountsAdapter.getSelectedAccount()); @@ -316,11 +317,10 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final ParcelableAccount account = mAccountsAdapter.getSelectedAccount(); if (account == null || !(item instanceof OptionItem)) return; final OptionItem option = (OptionItem) item; - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); switch (option.id) { case R.id.search: { final Intent intent = new Intent(getActivity(), QuickSearchBarActivity.class); - intent.putExtra(EXTRA_ACCOUNT_KEY, accountKey); + intent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key); startActivity(intent); closeAccountsDrawer(); break; @@ -328,28 +328,30 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo case R.id.compose: { final Intent composeIntent = new Intent(INTENT_ACTION_COMPOSE); composeIntent.setClass(getActivity(), ComposeActivity.class); - composeIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey); + composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key); startActivity(composeIntent); break; } case R.id.favorites: { - IntentUtils.openUserFavorites(getActivity(), accountKey, account.account_id, account.screen_name); + IntentUtils.openUserFavorites(getActivity(), account.account_key, + account.account_key.getId(), account.screen_name); break; } case R.id.lists: { - IntentUtils.openUserLists(getActivity(), accountKey, account.account_id, account.screen_name); + IntentUtils.openUserLists(getActivity(), account.account_key, + account.account_key.getId(), account.screen_name); break; } case R.id.messages: { - IntentUtils.openDirectMessages(getActivity(), accountKey); + IntentUtils.openDirectMessages(getActivity(), account.account_key); break; } case R.id.interactions: { - IntentUtils.openInteractions(getActivity(), accountKey); + IntentUtils.openInteractions(getActivity(), account.account_key); break; } case R.id.edit: { - Utils.openProfileEditor(getActivity(), accountKey); + Utils.openProfileEditor(getActivity(), account.account_key); break; } } @@ -463,8 +465,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo if (account == null) return true; final Intent composeIntent = new Intent(INTENT_ACTION_COMPOSE); composeIntent.setClass(getActivity(), ComposeActivity.class); - composeIntent.putExtra(EXTRA_ACCOUNT_KEY, - new AccountKey(account.account_id, account.account_host)); + composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key); startActivity(composeIntent); return true; } @@ -475,10 +476,11 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final ParcelableAccount account = accounts[item.getOrder()]; final ContentValues values = new ContentValues(); final boolean newActivated = !account.is_activated; - mAccountActionProvider.setAccountActivated(account.account_id, newActivated); + mAccountActionProvider.setAccountActivated(account.account_key, newActivated); values.put(Accounts.IS_ACTIVATED, newActivated); - final String where = Expression.equals(Accounts.ACCOUNT_ID, account.account_id).getSQL(); - mResolver.update(Accounts.CONTENT_URI, values, where, null); + final String where = Expression.equalsArgs(Accounts.ACCOUNT_KEY).getSQL(); + final String[] whereArgs = {account.account_key.toString()}; + mResolver.update(Accounts.CONTENT_URI, values, where, whereArgs); return true; } }); @@ -545,13 +547,13 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo switch (tab.type) { case CustomTabType.DIRECT_MESSAGES: { if (!hasDmTab) { - hasDmTab = hasAccountInTab(tab, account.account_id, account.is_activated); + hasDmTab = hasAccountInTab(tab, account.account_key, account.is_activated); } break; } case CustomTabType.NOTIFICATIONS_TIMELINE: { if (!hasInteractionsTab) { - hasInteractionsTab = hasAccountInTab(tab, account.account_id, account.is_activated); + hasInteractionsTab = hasAccountInTab(tab, account.account_key, account.is_activated); } break; } @@ -578,14 +580,11 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo mAccountOptionsAdapter.add(new OptionItem(R.string.lists, R.drawable.ic_action_list, R.id.lists)); } - private boolean hasAccountInTab(SupportTabSpec tab, long accountId, boolean isActivated) { + private boolean hasAccountInTab(SupportTabSpec tab, AccountKey accountId, boolean isActivated) { if (tab.args == null) return false; final AccountKey[] accountKeys = Utils.getAccountKeys(tab.args); if (accountKeys == null) return isActivated; - for (AccountKey accountKey : accountKeys) { - if (accountId == accountKey.getId()) return true; - } - return false; + return ArrayUtils.contains(accountKeys, accountId); } private void closeAccountsDrawer() { @@ -683,10 +682,9 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo private void finishAnimation() { final Editor editor = mPreferences.edit(); - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); - editor.putString(KEY_DEFAULT_ACCOUNT_KEY, accountKey.toString()); + editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString()); editor.apply(); - mAccountsAdapter.setSelectedAccountId(accountKey); + mAccountsAdapter.setSelectedAccountKey(account.account_key); mAccountOptionsAdapter.setSelectedAccount(account); updateAccountActions(); updateAccountOptionsSeparatorLabel(clickedDrawable); @@ -800,9 +798,9 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo setHasStableIds(true); } - private static int indexOfAccount(List accounts, long accountId) { + private static int indexOfAccount(List accounts, AccountKey accountId) { for (int i = 0, j = accounts.size(); i < j; i++) { - if (accounts.get(i).account_id == accountId) return i; + if (accounts.get(i).account_key.equals(accountId)) return i; } return -1; } @@ -823,16 +821,16 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo } @Nullable - public AccountKey getSelectedAccountId() { + public AccountKey getSelectedAccountKey() { final ParcelableAccount selectedAccount = getSelectedAccount(); if (selectedAccount == null) return null; - return new AccountKey(selectedAccount.account_id, selectedAccount.account_host); + return selectedAccount.account_key; } - public void setSelectedAccountId(@Nullable AccountKey accountKey) { + public void setSelectedAccountKey(@Nullable AccountKey accountKey) { final ParcelableAccount selectedAccount = getSelectedAccount(); if (selectedAccount == null || accountKey == null) return; - swap(accountKey, new AccountKey(selectedAccount.account_id, selectedAccount.account_host)); + swap(accountKey, selectedAccount.account_key); } @Override @@ -850,7 +848,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo @Override public long getItemId(int position) { - return getAdapterAccount(position).account_id; + return System.identityHashCode(getAdapterAccount(position)); } @Override @@ -868,7 +866,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo Collections.addAll(tempList, accounts); if (previousAccounts != null) { for (ParcelableAccount previousAccount : previousAccounts) { - final int idx = indexOfAccount(tempList, previousAccount.account_id); + final int idx = indexOfAccount(tempList, previousAccount.account_key); if (idx >= 0) { mInternalAccounts[tempIdx++] = tempList.remove(idx); } @@ -895,10 +893,10 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo int fromIdx = -1, toIdx = -1; for (int i = 0, j = mInternalAccounts.length; i < j; i++) { final ParcelableAccount account = mInternalAccounts[i]; - if (fromId.isAccount(account.account_id, account.account_host)) { + if (fromId.equals(account.account_key)) { fromIdx = i; } - if (toId.isAccount(account.account_id, account.account_host)) { + if (toId.equals(account.account_key)) { toIdx = i; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java index a4e13ff06..6eb475d78 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsManagerFragment.java @@ -19,7 +19,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; -import android.support.v4.util.LongSparseArray; +import android.support.v4.util.SimpleArrayMap; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -37,9 +37,9 @@ import android.widget.TextView; import com.mobeta.android.dslv.DragSortListView; import com.mobeta.android.dslv.DragSortListView.DropListener; +import org.mariotaku.sqliteqb.library.ArgsArray; import org.mariotaku.sqliteqb.library.Columns; import org.mariotaku.sqliteqb.library.Expression; -import org.mariotaku.sqliteqb.library.RawItemArray; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.support.ColorPickerDialogActivity; import org.mariotaku.twidere.activity.support.SignInActivity; @@ -53,6 +53,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Mentions; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; import org.mariotaku.twidere.util.IntentUtils; import org.mariotaku.twidere.util.ThemeUtils; +import org.mariotaku.twidere.util.TwidereCollectionUtils; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.collection.CompactHashSet; @@ -69,7 +70,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load private AccountsAdapter mAdapter; private ParcelableAccount mSelectedAccount; - private LongSparseArray mActivatedState = new LongSparseArray<>(); + private SimpleArrayMap mActivatedState = new SimpleArrayMap<>(); private DragSortListView mListView; private View mEmptyView; @@ -104,9 +105,10 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load return; final ContentValues values = new ContentValues(); values.put(Accounts.COLOR, data.getIntExtra(EXTRA_COLOR, Color.WHITE)); - final Expression where = Expression.equals(Accounts.ACCOUNT_ID, mSelectedAccount.account_id); + final Expression where = Expression.equalsArgs(Accounts.ACCOUNT_KEY); + final String[] whereArgs = {mSelectedAccount.account_key.toString()}; final ContentResolver cr = getContentResolver(); - cr.update(Accounts.CONTENT_URI, values, where.getSQL(), null); + cr.update(Accounts.CONTENT_URI, values, where.getSQL(), whereArgs); return; } } @@ -137,7 +139,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load case R.id.delete: { final AccountDeletionDialogFragment f = new AccountDeletionDialogFragment(); final Bundle args = new Bundle(); - args.putParcelable(EXTRA_ACCOUNT_KEY, new AccountKey(account.account_id, account.account_host)); + args.putParcelable(EXTRA_ACCOUNT_KEY, account.account_key); f.setArguments(args); f.show(getChildFragmentManager(), FRAGMENT_TAG_ACCOUNT_DELETION); break; @@ -149,9 +151,8 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load @Override public void onItemClick(AdapterView parent, View view, int position, long id) { final ParcelableAccount account = mAdapter.getAccount(position); - IntentUtils.openUserProfile(getActivity(), new AccountKey(account.account_id, - account.account_host), account.account_id, account.screen_name, null, true, - UserFragment.Referral.SELF_PROFILE); + IntentUtils.openUserProfile(getActivity(), account.account_key, account.account_key.getId(), + account.screen_name, null, true, UserFragment.Referral.SELF_PROFILE); } @Override @@ -161,7 +162,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load } private void saveActivatedState() { - final Set trueIds = new CompactHashSet<>(), falseIds = new CompactHashSet<>(); + final Set trueIds = new CompactHashSet<>(), falseIds = new CompactHashSet<>(); for (int i = 0, j = mActivatedState.size(); i < j; i++) { if (mActivatedState.valueAt(i)) { trueIds.add(mActivatedState.keyAt(i)); @@ -172,16 +173,18 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load final ContentResolver cr = getContentResolver(); final ContentValues values = new ContentValues(); values.put(Accounts.IS_ACTIVATED, true); - Expression where = Expression.in(new Columns.Column(Accounts.ACCOUNT_ID), new RawItemArray(trueIds.toArray())); - cr.update(Accounts.CONTENT_URI, values, where.getSQL(), null); + Expression where = Expression.in(new Columns.Column(Accounts.ACCOUNT_KEY), new ArgsArray(trueIds.size())); + String[] whereArgs = TwidereCollectionUtils.toStringArray(trueIds); + cr.update(Accounts.CONTENT_URI, values, where.getSQL(), whereArgs); values.put(Accounts.IS_ACTIVATED, false); - where = Expression.in(new Columns.Column(Accounts.ACCOUNT_ID), new RawItemArray(falseIds.toArray())); - cr.update(Accounts.CONTENT_URI, values, where.getSQL(), null); + where = Expression.in(new Columns.Column(Accounts.ACCOUNT_KEY), new ArgsArray(falseIds.size())); + whereArgs = TwidereCollectionUtils.toStringArray(falseIds); + cr.update(Accounts.CONTENT_URI, values, where.getSQL(), whereArgs); } @Override - public void onAccountToggle(long accountId, boolean state) { - mActivatedState.append(accountId, state); + public void onAccountToggle(AccountKey accountId, boolean state) { + mActivatedState.put(accountId, state); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserBlockDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserBlockDialogFragment.java index d9410cbc2..efc6a3266 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserBlockDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserBlockDialogFragment.java @@ -45,7 +45,7 @@ public class CreateUserBlockDialogFragment extends BaseSupportDialogFragment imp final ParcelableUser user = getUser(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (user == null || twitter == null) return; - twitter.createBlockAsync(new AccountKey(user.account_id, user.account_host), user.id); + twitter.createBlockAsync(user.account_key, user.id); break; default: break; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserMuteDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserMuteDialogFragment.java index 7feabbdc1..41e45aba1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserMuteDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CreateUserMuteDialogFragment.java @@ -29,7 +29,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.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.ThemeUtils; @@ -45,8 +44,7 @@ public class CreateUserMuteDialogFragment extends BaseSupportDialogFragment impl final ParcelableUser user = getUser(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (user == null || twitter == null) return; - twitter.createMuteAsync(new AccountKey(user.account_id, user.account_host), - user.id); + twitter.createMuteAsync(user.account_key, user.id); break; default: break; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java index 1bb654ff7..f12b2a9c0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java @@ -105,7 +105,7 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment> mUnreadCountsToRemove = new LongSparseArray<>(); + private final SimpleArrayMap> mUnreadCountsToRemove = new SimpleArrayMap<>(); private final Set mReadPositions = Collections.synchronizedSet(new HashSet()); private int mFirstVisibleItem; @@ -120,7 +120,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment> getUnreadCountsToRemove() { + public final SimpleArrayMap> getUnreadCountsToRemove() { return mUnreadCountsToRemove; } @@ -153,7 +153,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment onCreateLoader(final int id, final Bundle args) { final Uri uri = DirectMessages.ConversationEntries.CONTENT_URI; final AccountKey[] accountIds = getAccountKeys(); - final Expression account_where = Expression.in(new Column(Statuses.ACCOUNT_ID), new RawItemArray(accountIds)); + final Expression account_where = Expression.in(new Column(Statuses.ACCOUNT_KEY), new RawItemArray(accountIds)); return new CursorLoader(getActivity(), uri, null, account_where.getSQL(), null, null); } @@ -195,14 +195,13 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment counts = new HashSet<>(); counts.add(id); @@ -429,8 +428,9 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.acceptFriendshipAsync(new AccountKey(user.account_id, user.account_host), - user.id); + mTwitterWrapper.acceptFriendshipAsync(user.account_key, user.id); } @Override @@ -82,8 +81,7 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment final AbsUsersAdapter> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.denyFriendshipAsync(new AccountKey(user.account_id, user.account_host), - user.id); + mTwitterWrapper.denyFriendshipAsync(user.account_key, user.id); } @Subscribe diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java index 37ce14577..7cb90681a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java @@ -318,7 +318,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements } showConversation(account, recipient); if (account != null && recipient != null) { - final String key = getDraftsTextKey(account.account_id, recipient.id); + final String key = getDraftsTextKey(account.account_key, recipient.id); mEditText.setText(mMessageDrafts.getString(key, null)); } } @@ -372,7 +372,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final ParcelableCredentials account = mAccount; final ParcelableUser recipient = mRecipient; if (account != null && recipient != null) { - final String key = getDraftsTextKey(account.account_id, recipient.id); + final String key = getDraftsTextKey(account.account_key, recipient.id); final SharedPreferences.Editor editor = mMessageDrafts.edit(); final String text = ParseUtils.parseString(mEditText.getText()); if (TextUtils.isEmpty(text)) { @@ -404,8 +404,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements case R.id.delete_all: { final ParcelableCredentials account = mAccount; if (account == null || mRecipient == null) return true; - mTwitterWrapper.destroyMessageConversationAsync(new AccountKey(account.account_id, - account.account_host), mRecipient.id); + mTwitterWrapper.destroyMessageConversationAsync(account.account_key, mRecipient.id); return true; } } @@ -459,7 +458,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements } case R.id.query_button: { final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); - searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false); + searchUsers(account.account_key, ParseUtils.parseString(mEditUserQuery.getText()), false); break; } } @@ -496,8 +495,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (message != null) { switch (item.getItemId()) { case R.id.delete: { - mTwitterWrapper.destroyDirectMessageAsync(new AccountKey(message.account_id, - message.account_host), message.id); + mTwitterWrapper.destroyDirectMessageAsync(message.account_key, message.id); break; } case R.id.copy: { @@ -567,7 +565,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (account == null || recipient == null) return; final LoaderManager lm = getLoaderManager(); final Bundle args = new Bundle(); - args.putLong(EXTRA_ACCOUNT_ID, account.account_id); + args.putParcelable(EXTRA_ACCOUNT_KEY, account.account_key); args.putLong(EXTRA_RECIPIENT_ID, recipient.id); if (mLoaderInitialized) { lm.restartLoader(0, args, this); @@ -585,13 +583,13 @@ public class MessagesConversationFragment extends BaseSupportFragment implements return mConversationContainer.getVisibility() == View.VISIBLE; } - private String getDraftsTextKey(long accountId, long userId) { - return String.format(Locale.ROOT, "text_%d_to_%d", accountId, userId); + private String getDraftsTextKey(AccountKey accountKey, long userId) { + return String.format(Locale.ROOT, "text_%s_to_%d", accountKey, userId); } - private void searchUsers(long accountId, String query, boolean fromCache) { + private void searchUsers(AccountKey accountKey, String query, boolean fromCache) { final Bundle args = new Bundle(); - args.putLong(EXTRA_ACCOUNT_ID, accountId); + args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); args.putString(EXTRA_QUERY, query); args.putBoolean(EXTRA_FROM_CACHE, fromCache); final LoaderManager lm = getLoaderManager(); @@ -639,8 +637,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (TextUtils.isEmpty(message)) { mEditText.setError(getString(R.string.error_message_no_content)); } else { - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); - mTwitterWrapper.sendDirectMessageAsync(accountKey, recipient.id, message, mImageUri); + mTwitterWrapper.sendDirectMessageAsync(account.account_key, recipient.id, message, + mImageUri); mEditText.setText(null); mImageUri = null; updateAddImageButton(); @@ -663,8 +661,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (((BaseAppCompatActivity) activity).getKeyMetaState() != 0) return false; final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); if (account == null) return false; - mEditText.setAccountKey(new AccountKey(account.account_id, account.account_host)); - searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false); + mEditText.setAccountKey(account.account_key); + searchUsers(account.account_key, ParseUtils.parseString(mEditUserQuery.getText()), false); return true; } }, true); @@ -682,8 +680,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements public void afterTextChanged(Editable s) { final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); if (account == null) return; - mEditText.setAccountKey(new AccountKey(account.account_id, account.account_host)); - searchUsers(account.account_id, ParseUtils.parseString(s), true); + mEditText.setAccountKey(account.account_key); + searchUsers(account.account_key, ParseUtils.parseString(s), true); } }); mEditUserQuery.addTextChangedListener(new TextWatcher() { @@ -748,7 +746,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final Menu menu = mPopupMenu.getMenu(); final MenuItem view_profile_item = menu.findItem(R.id.view_profile); if (view_profile_item != null && dm != null) { - view_profile_item.setVisible(dm.account_id != dm.sender_id); + view_profile_item.setVisible(dm.account_key.getId() != dm.sender_id); } mPopupMenu.setOnMenuItemClickListener(this); mPopupMenu.show(); @@ -903,8 +901,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final ParcelableUser user = args.getParcelable(EXTRA_USER); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (account == null || user == null || twitter == null) return; - twitter.destroyMessageConversationAsync(new AccountKey(account.account_id, - account.account_host), user.id); + twitter.destroyMessageConversationAsync(account.account_key, user.id); break; } } @@ -931,18 +928,21 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final ContentResolver resolver = mContext.getContentResolver(); final String[] projection = {ConversationEntries.MESSAGE_ID}; final String selection = Expression.and( - Expression.equals(ConversationEntries.ACCOUNT_ID, mAccount.account_id), - Expression.equals(ConversationEntries.CONVERSATION_ID, mRecipient.id) + Expression.equalsArgs(ConversationEntries.ACCOUNT_KEY), + Expression.equalsArgs(ConversationEntries.CONVERSATION_ID) ).getSQL(); + final String[] selectionArgs = {String.valueOf(mAccount.account_key), + String.valueOf(mRecipient.id)}; final String orderBy = new OrderBy(ConversationEntries.MESSAGE_ID, false).getSQL(); - return resolver.query(ConversationEntries.CONTENT_URI, projection, selection, null, orderBy); + return resolver.query(ConversationEntries.CONTENT_URI, projection, selection, + selectionArgs, orderBy); } @Override protected void onPostExecute(Cursor cursor) { if (cursor.moveToFirst()) { final int messageIdIdx = cursor.getColumnIndex(ConversationEntries.MESSAGE_ID); - final String key = mAccount.account_id + "-" + mRecipient.id; + final String key = mAccount.account_key + "-" + mRecipient.id; mReadStateManager.setPosition(CustomTabType.DIRECT_MESSAGES, key, cursor.getLong(messageIdIdx), false); } cursor.close(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java index 0d2f2d228..17b6b7d4e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java @@ -135,7 +135,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment> adapter = getAdapter(); final ParcelableStatus status = adapter.getStatus(adapter.getItemCount() - 1); - AccountKey[] accountKeys = {new AccountKey(status.account_id, status.account_host)}; + AccountKey[] accountKeys = {status.account_key}; final long[] maxIds = {status.id}; getStatuses(new BaseRefreshTaskParam(accountKeys, maxIds, null)); } @@ -187,7 +187,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment doInBackground(ParcelableStatus... params) { final ParcelableStatus status = params[0]; - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, - new AccountKey(status.account_id, status.account_host), true); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, status.account_key, + true); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); if (twitter == null) return SingleResponse.getInstance(); @@ -999,8 +996,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac retweetedByView.setVisibility(View.GONE); } - profileContainer.drawEnd(DataStoreUtils.getAccountColor(context, - new AccountKey(status.account_id, status.account_host))); + profileContainer.drawEnd(DataStoreUtils.getAccountColor(context, status.account_key)); final int layoutPosition = getLayoutPosition(); final boolean skipLinksInText = status.extras != null && status.extras.support_entities; @@ -1017,8 +1013,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final CharSequence quotedText = HtmlSpanBuilder.fromHtml(status.quoted_text_html, status.text_unescaped); if (quotedText instanceof Spanned) { - quotedTextView.setText(linkify.applyAllLinks(quotedText, - new AccountKey(status.account_id, status.account_host), + quotedTextView.setText(linkify.applyAllLinks(quotedText, status.account_key, layoutPosition, status.is_possibly_sensitive, skipLinksInText)); } @@ -1072,8 +1067,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final CharSequence text = HtmlSpanBuilder.fromHtml(status.text_html, status.text_unescaped); if (text instanceof Spanned) { - textView.setText(linkify.applyAllLinks(text, new AccountKey(status.account_id, - status.account_host), layoutPosition, status.is_possibly_sensitive, skipLinksInText)); + textView.setText(linkify.applyAllLinks(text, status.account_key, layoutPosition, + status.is_possibly_sensitive, skipLinksInText)); } final ParcelableLocation location; @@ -1127,8 +1122,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac mediaPreviewContainer.setVisibility(View.VISIBLE); mediaPreview.setVisibility(View.VISIBLE); mediaPreviewLoad.setVisibility(View.GONE); - mediaPreview.displayMedia(media, loader, new AccountKey(status.account_id, - status.account_host), -1, adapter.getFragment(), adapter.getMediaLoadingHandler()); + mediaPreview.displayMedia(media, loader, status.account_key, -1, + adapter.getFragment(), adapter.getMediaLoadingHandler()); } else { mediaPreviewContainer.setVisibility(View.VISIBLE); mediaPreview.setVisibility(View.GONE); @@ -1192,7 +1187,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final ParcelableStatus status = adapter.getStatus(getLayoutPosition()); final StatusFragment fragment = adapter.getFragment(); if (status == null || fragment == null) return; - final AccountKey accountKey = new AccountKey(status.account_id, status.account_host); switch (v.getId()) { case R.id.media_preview_load: { if (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive) { @@ -1205,13 +1199,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } case R.id.profile_container: { final FragmentActivity activity = fragment.getActivity(); - IntentUtils.openUserProfile(activity, accountKey, status.user_id, + IntentUtils.openUserProfile(activity, status.account_key, status.user_id, status.user_screen_name, null, true, UserFragment.Referral.STATUS); break; } case R.id.retweeted_by: { if (status.retweet_id > 0) { - IntentUtils.openUserProfile(adapter.getContext(), accountKey, + IntentUtils.openUserProfile(adapter.getContext(), status.account_key, status.retweeted_by_user_id, status.retweeted_by_user_screen_name, null, true, UserFragment.Referral.STATUS); } @@ -1224,13 +1218,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac break; } case R.id.quoted_name_container: { - IntentUtils.openUserProfile(adapter.getContext(), accountKey, + IntentUtils.openUserProfile(adapter.getContext(), status.account_key, status.quoted_user_id, status.quoted_user_screen_name, null, true, UserFragment.Referral.STATUS); break; } case R.id.quote_original_link: { - IntentUtils.openStatus(adapter.getContext(), accountKey, status.quoted_id); + IntentUtils.openStatus(adapter.getContext(), status.account_key, status.quoted_id); break; } case R.id.translate_label: { @@ -1470,14 +1464,14 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final LabeledCount count = getCount(position); final ParcelableStatus status = mStatusAdapter.getStatus(); if (count == null || status == null) return; - final AccountKey accountKey = new AccountKey(status.account_id, - status.account_host); switch (count.type) { case KEY_RETWEET_COUNT: { if (status.is_retweet) { - IntentUtils.openStatusRetweeters(getContext(), accountKey, status.retweet_id); + IntentUtils.openStatusRetweeters(getContext(), status.account_key, + status.retweet_id); } else { - IntentUtils.openStatusRetweeters(getContext(), accountKey, status.id); + IntentUtils.openStatusRetweeters(getContext(), status.account_key, + status.id); } break; } @@ -1485,9 +1479,11 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final ParcelableCredentials account = mStatusAdapter.getStatusAccount(); if (!Utils.isOfficialCredentials(getContext(), account)) return; if (status.is_retweet) { - IntentUtils.openStatusFavoriters(getContext(), accountKey, status.retweet_id); + IntentUtils.openStatusFavoriters(getContext(), status.account_key, + status.retweet_id); } else { - IntentUtils.openStatusFavoriters(getContext(), accountKey, status.id); + IntentUtils.openStatusFavoriters(getContext(), status.account_key, + status.id); } break; } @@ -1817,17 +1813,18 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } @Override - public long getAccountId(int position) { + public AccountKey getAccountKey(int position) { final ParcelableStatus status = getStatus(position); - return status != null ? status.account_id : position; + return status != null ? status.account_key : null; } @Override - public ParcelableStatus findStatusById(long accountId, long statusId) { - if (mStatus != null && accountId == mStatus.account_id && statusId == mStatus.id) + public ParcelableStatus findStatusById(AccountKey accountId, long statusId) { + if (mStatus != null && accountId.equals(mStatus.account_key) && statusId == mStatus.id) { return mStatus; + } for (ParcelableStatus status : Nullables.list(mData)) { - if (accountId == status.account_id && status.id == statusId) return status; + if (accountId.equals(status.account_key) && status.id == statusId) return status; } return null; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index 53b385e8f..2b6f90efe 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -295,7 +295,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener displayUser(user); if (user.is_cache) { final Bundle args = new Bundle(); - args.putParcelable(EXTRA_ACCOUNT_KEY, new AccountKey(user.account_id, + args.putParcelable(EXTRA_ACCOUNT_KEY, new AccountKey(user.account_key, user.account_host)); args.putLong(EXTRA_USER_ID, user.id); args.putString(EXTRA_SCREEN_NAME, user.screen_name); @@ -340,7 +340,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mRelationship = null; return; } - if (user.account_id == user.id) { + if (user.account_key == user.id) { mFollowButton.setText(R.string.edit); mFollowButton.setVisibility(View.VISIBLE); mRelationship = null; @@ -527,7 +527,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (user.account_color != 0) { mProfileNameContainer.drawEnd(user.account_color); } else { - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); mProfileNameContainer.drawEnd(DataStoreUtils.getAccountColor(activity, accountKey)); } final String nick = mUserColorNameManager.getUserNickname(user.id, true); @@ -543,7 +543,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mScreenNameView.setText(String.format("@%s", user.screen_name)); mDescriptionContainer.setVisibility(TextUtils.isEmpty(user.description_html) ? View.GONE : View.VISIBLE); final TwidereLinkify linkify = new TwidereLinkify(this); - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); mDescriptionView.setText(linkify.applyAllLinks(user.description_html != null ? HtmlSpanBuilder.fromHtml(user.description_html) : user.description_plain, accountKey, false, false)); @@ -646,7 +646,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Subscribe public void notifyFriendshipUpdated(FriendshipUpdatedEvent event) { final ParcelableUser user = getUser(); - if (user == null || !event.isAccount(user.account_id, user.account_host) || + if (user == null || !event.isAccount(user.account_key, user.account_host) || !event.isUser(user.id)) return; getFriendship(); } @@ -691,7 +691,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final AsyncTwitterWrapper twitter = mTwitterWrapper; final ParcelableUserList list = data.getParcelableExtra(EXTRA_USER_LIST); if (list == null || twitter == null) return; - twitter.addUserListMembersAsync(new AccountKey(user.account_id, user.account_host), + twitter.addUserListMembersAsync(new AccountKey(user.account_key, user.account_host), list.id, user); } break; @@ -903,7 +903,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (twitter == null || user == null || userRelationship == null) return; final Relationship relationship = userRelationship.relationship; - final boolean isMyself = user.account_id == user.id; + final boolean isMyself = user.account_key == user.id; final MenuItem mentionItem = menu.findItem(R.id.mention); if (mentionItem != null) { final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); @@ -913,7 +913,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener MenuUtils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.saved_searches, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.scheduled_statuses, isMyself - && TwitterAPIFactory.getOfficialKeyType(getActivity(), user.account_id) == ConsumerKeyType.TWEETDECK); + && TwitterAPIFactory.getOfficialKeyType(getActivity(), user.account_key) == ConsumerKeyType.TWEETDECK); // final MenuItem followItem = menu.findItem(MENU_FOLLOW); // followItem.setVisible(!isMyself); // final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself @@ -980,7 +980,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final ParcelableUser user = getUser(); final UserRelationship userRelationship = mRelationship; if (user == null || twitter == null) return false; - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); switch (item.getItemId()) { case R.id.block: { if (userRelationship == null) return true; @@ -1284,14 +1284,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final FragmentActivity activity = getActivity(); final ParcelableUser user = getUser(); if (activity == null || user == null) return; - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); switch (view.getId()) { case R.id.error_container: { getUserInfo(true); break; } case R.id.follow: { - if (user.id == user.account_id) { + if (user.id == user.account_key) { Utils.openProfileEditor(getActivity(), accountKey); break; } @@ -1337,7 +1337,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener break; } case R.id.name_container: { - if (user.account_id != user.id) return; + if (user.account_key != user.id) return; Utils.openProfileEditor(getActivity(), accountKey); break; } @@ -1358,12 +1358,12 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (user == null) return; switch (type) { case TwidereLinkify.LINK_TYPE_MENTION: { - IntentUtils.openUserProfile(getActivity(), new AccountKey(user.account_id, + IntentUtils.openUserProfile(getActivity(), new AccountKey(user.account_key, user.account_host), -1, link, null, true, Referral.USER_MENTION); break; } case TwidereLinkify.LINK_TYPE_HASHTAG: { - IntentUtils.openTweetSearch(getActivity(), new AccountKey(user.account_id, user.account_host), + IntentUtils.openTweetSearch(getActivity(), new AccountKey(user.account_key, user.account_host), "#" + link); break; } @@ -1450,7 +1450,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final LoaderManager lm = getLoaderManager(); lm.destroyLoader(LOADER_ID_FRIENDSHIP); final Bundle args = new Bundle(); - args.putLong(EXTRA_ACCOUNT_ID, user.account_id); + args.putLong(EXTRA_ACCOUNT_ID, user.account_key); args.putLong(EXTRA_USER_ID, user.id); if (!mGetFriendShipLoaderInitialized) { lm.initLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks); @@ -1463,7 +1463,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener private void getUserInfo(final boolean omitIntentExtra) { final ParcelableUser user = mUser; if (user == null) return; - getUserInfo(user.account_id, user.id, user.screen_name, omitIntentExtra); + getUserInfo(user.account_key, user.id, user.screen_name, omitIntentExtra); } private void setUiColor(int color) { @@ -1531,7 +1531,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final long accountId; final ParcelableUser user = args.getParcelable(EXTRA_USER); if (user != null) { - tabArgs.putLong(EXTRA_ACCOUNT_ID, accountId = user.account_id); + tabArgs.putLong(EXTRA_ACCOUNT_ID, accountId = user.account_key); tabArgs.putLong(EXTRA_USER_ID, user.id); tabArgs.putString(EXTRA_SCREEN_NAME, user.screen_name); } else { @@ -1563,7 +1563,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } final LoaderManager lm = getLoaderManager(); final boolean loadingRelationship = lm.getLoader(LOADER_ID_FRIENDSHIP) != null; - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); final boolean creatingFriendship = twitter.isCreatingFriendship(accountKey, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.id); final boolean creatingBlock = twitter.isCreatingFriendship(accountKey, user.id); @@ -1584,7 +1584,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final ParcelableUser user = getUser(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (user == null || twitter == null) return; - final AccountKey accountKey = new AccountKey(user.account_id, user.account_host); + final AccountKey accountKey = new AccountKey(user.account_key, user.account_host); final boolean isCreatingFriendship = twitter.isCreatingFriendship(accountKey, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.id); setProgressBarIndeterminateVisibility(isCreatingFriendship || destroyingFriendship); @@ -1811,7 +1811,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } public boolean check(@NonNull ParcelableUser user) { - return relationship.getSourceUserId() == user.account_id + return relationship.getSourceUserId() == user.account_key && relationship.getTargetUserId() == user.id; } } @@ -1829,7 +1829,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final ParcelableUser user = args.first; resolver.insert(CachedUsers.CONTENT_URI, ParcelableUserValuesCreator.create(user)); resolver.insert(CachedRelationships.CONTENT_URI, CachedRelationshipValuesCreator.create( - new CachedRelationship(user.account_id, user.id, args.second))); + new CachedRelationship(user.account_key, user.id, args.second))); return null; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java index 74783eb48..3d5d88a9a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableUserLoader.java @@ -102,8 +102,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader 0) { @@ -812,7 +812,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta new Column(SQLConstants.NULL, Suggestions.Search.EXTRA).getSQL(), new Column(SavedSearches.QUERY, Suggestions.Search.VALUE).getSQL() }; - final Expression savedSearchesWhere = Expression.equals(SavedSearches.ACCOUNT_ID, accountId); + final Expression savedSearchesWhere = Expression.equals(SavedSearches.ACCOUNT_KEY, accountId); @SuppressLint("Recycle") final Cursor savedSearchesCursor = mDatabaseWrapper.query(true, SavedSearches.TABLE_NAME, savedSearchesProjection, savedSearchesWhere.getSQL(), null, null, null, SavedSearches.DEFAULT_SORT_ORDER, null); diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java index 6fb6a7c43..21ca309b6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java @@ -315,7 +315,7 @@ public class BackgroundOperationService extends IntentService implements Constan final ContentResolver resolver = getContentResolver(); if (result.getData() != null && result.getData().id > 0) { final ContentValues values = ContentValuesCreator.createDirectMessage(result.getData()); - final String delete_where = DirectMessages.ACCOUNT_ID + " = " + accountId + " AND " + final String delete_where = DirectMessages.ACCOUNT_KEY + " = " + accountId + " AND " + DirectMessages.MESSAGE_ID + " = " + result.getData().id; resolver.delete(DirectMessages.Outbox.CONTENT_URI, delete_where, null); resolver.insert(DirectMessages.Outbox.CONTENT_URI, values); @@ -584,7 +584,7 @@ public class BackgroundOperationService extends IntentService implements Constan shortener.waitForService(); } for (final ParcelableAccount account : statusUpdate.accounts) { - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); + final AccountKey accountKey = new AccountKey(account.account_key, account.account_host); final ParcelableCredentials credentials = DataStoreUtils.getCredentials(this, accountKey); // Get Twitter instance corresponding to account diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java b/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java index b1f5d0a9a..fbfd342fc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java @@ -130,7 +130,7 @@ public class StreamingService extends Service implements Constants { final AccountKey[] accountKeys = new AccountKey[accountsList.size()]; for (int i = 0, j = accountKeys.length; i < j; i++) { final ParcelableCredentials credentials = accountsList.get(i); - accountKeys[i] = new AccountKey(credentials.account_id, credentials.account_host); + accountKeys[i] = new AccountKey(credentials.account_key, credentials.account_host); } final AccountPreferences[] activatedPreferences = AccountPreferences.getAccountPreferences(this, accountKeys); if (BuildConfig.DEBUG) { @@ -147,13 +147,13 @@ public class StreamingService extends Service implements Constants { final Authorization authorization = TwitterAPIFactory.getAuthorization(account); final TwitterUserStream twitter = TwitterAPIFactory.getInstance(this, endpoint, authorization, TwitterUserStream.class); final TwidereUserStreamCallback callback = new TwidereUserStreamCallback(this, account); - mCallbacks.put(account.account_id, callback); + mCallbacks.put(account.account_key, callback); new Thread() { @Override public void run() { twitter.getUserStream(callback); - Log.d(Constants.LOGTAG, String.format("Stream %d disconnected", account.account_id)); - mCallbacks.remove(account.account_id); + Log.d(Constants.LOGTAG, String.format("Stream %d disconnected", account.account_key)); + mCallbacks.remove(account.account_key); updateStreamState(); } }.start(); @@ -241,21 +241,21 @@ public class StreamingService extends Service implements Constants { public void onDirectMessage(final DirectMessage directMessage) { if (directMessage == null || directMessage.getId() <= 0) return; for (final Uri uri : MESSAGES_URIS) { - final String where = DirectMessages.ACCOUNT_ID + " = " + account.account_id + " AND " + final String where = DirectMessages.ACCOUNT_KEY + " = " + account.account_key + " AND " + DirectMessages.MESSAGE_ID + " = " + directMessage.getId(); resolver.delete(uri, where, null); } final User sender = directMessage.getSender(), recipient = directMessage.getRecipient(); - if (sender.getId() == account.account_id) { + if (sender.getId() == account.account_key) { final ContentValues values = ContentValuesCreator.createDirectMessage(directMessage, - account.account_id, account.account_host, true); + account.account_key, account.account_host, true); if (values != null) { resolver.insert(DirectMessages.Outbox.CONTENT_URI, values); } } - if (recipient.getId() == account.account_id) { + if (recipient.getId() == account.account_key) { final ContentValues values = ContentValuesCreator.createDirectMessage(directMessage, - account.account_id, account.account_host, false); + account.account_key, account.account_host, false); final Uri.Builder builder = DirectMessages.Inbox.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_NOTIFY, "true"); if (values != null) { @@ -335,12 +335,12 @@ public class StreamingService extends Service implements Constants { @Override public void onStatus(final Status status) { final ContentValues values = ContentValuesCreator.createStatus(status, - new AccountKey(account.account_id, account.account_host)); + new AccountKey(account.account_key, account.account_host)); if (!statusStreamStarted) { statusStreamStarted = true; values.put(Statuses.IS_GAP, true); } - final String where = Statuses.ACCOUNT_ID + " = " + account.account_id + " AND " + Statuses.STATUS_ID + " = " + final String where = Statuses.ACCOUNT_KEY + " = " + account.account_key + " AND " + Statuses.STATUS_ID + " = " + status.getId(); resolver.delete(Statuses.CONTENT_URI, where, null); resolver.delete(Mentions.CONTENT_URI, where, null); diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java index 65259838a..beb9ba529 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java @@ -116,8 +116,7 @@ public abstract class GetDirectMessagesTask extends AbstractTask searches = twitter.getSavedSearches(); final ContentValues[] values = ContentValuesCreator.createSavedSearches(searches, accountKey.getId(), accountKey.getHost()); - final Expression where = Expression.and(Expression.equalsArgs(SavedSearches.ACCOUNT_ID), + final Expression where = Expression.and(Expression.equalsArgs(SavedSearches.ACCOUNT_KEY), Expression.equalsArgs(SavedSearches.ACCOUNT_HOST)); final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost()}; cr.delete(SavedSearches.CONTENT_URI, where.getSQL(), whereArgs); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java index 045573df0..607001cba 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java @@ -29,6 +29,7 @@ import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.util.LongSparseArray; +import android.support.v4.util.SimpleArrayMap; import android.util.Log; import com.squareup.otto.Bus; @@ -442,7 +443,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } } - public void removeUnreadCountsAsync(final int position, final LongSparseArray> counts) { + public void removeUnreadCountsAsync(final int position, final SimpleArrayMap> counts) { final RemoveUnreadCountsTask task = new RemoveUnreadCountsTask(position, counts); AsyncTaskUtils.executeTask(task); } @@ -550,7 +551,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { mProcessingFriendshipRequestIds.removeElement(ParcelableUser.calculateHashCode(accountKey.getId(), userId)); } - public boolean isProcessingFollowRequest(long accountId, long userId) { + public boolean isProcessingFollowRequest(AccountKey accountId, long userId) { return mProcessingFriendshipRequestIds.contains(ParcelableUser.calculateHashCode(accountId, userId)); } @@ -839,8 +840,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } // I bet you don't want to see this user in your auto complete list. final ContentValues values = new ContentValues(); - values.put(CachedRelationships.ACCOUNT_ID, mAccountKey.getId()); - values.put(CachedRelationships.ACCOUNT_HOST, mAccountKey.getHost()); + values.put(CachedRelationships.ACCOUNT_KEY, mAccountKey.toString()); values.put(CachedRelationships.USER_ID, mUserId); values.put(CachedRelationships.BLOCKING, true); mResolver.insert(CachedRelationships.CONTENT_URI, values); @@ -1025,7 +1025,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { values.put(CachedRelationships.FOLLOWED_BY, false); mResolver.update(CachedRelationships.CONTENT_URI, values, Expression.inArgs(CachedRelationships.USER_ID, list.size()).getSQL(), - TwidereListUtils.toStringArray(list)); + TwidereCollectionUtils.toStringArray(list)); } @Override @@ -1943,9 +1943,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final class RemoveUnreadCountsTask extends AsyncTask { private final int position; - private final LongSparseArray> counts; + private final SimpleArrayMap> counts; - RemoveUnreadCountsTask(final int position, final LongSparseArray> counts) { + RemoveUnreadCountsTask(final int position, final SimpleArrayMap> counts) { this.position = position; this.counts = counts; } 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 92beb179f..f21c0a356 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java @@ -23,8 +23,6 @@ import android.content.ContentValues; import android.support.annotation.NonNull; import org.mariotaku.twidere.TwidereConstants; -import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization; -import org.mariotaku.twidere.api.twitter.auth.OAuthToken; import org.mariotaku.twidere.api.twitter.model.DirectMessage; import org.mariotaku.twidere.api.twitter.model.Relationship; import org.mariotaku.twidere.api.twitter.model.SavedSearch; @@ -36,7 +34,6 @@ import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityValuesCreator; -import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableDirectMessageValuesCreator; import org.mariotaku.twidere.model.ParcelableMedia; @@ -50,7 +47,6 @@ import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtra; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; import org.mariotaku.twidere.model.util.ParcelableUserUtils; -import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships; import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends; @@ -68,74 +64,10 @@ import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText; public final class ContentValuesCreator implements TwidereConstants { - public static ContentValues createAccount(final String basicUsername, final String basicPassword, - final User user, final int color, final String apiUrlFormat, - final boolean noVersionSuffix) { - if (user == null || user.getId() <= 0) return null; - final ContentValues values = new ContentValues(); - if (basicUsername == null || basicPassword == null) return null; - values.put(Accounts.BASIC_AUTH_USERNAME, basicUsername); - values.put(Accounts.BASIC_AUTH_PASSWORD, basicPassword); - values.put(Accounts.AUTH_TYPE, ParcelableCredentials.AUTH_TYPE_BASIC); - values.put(Accounts.ACCOUNT_ID, user.getId()); - values.put(Accounts.SCREEN_NAME, user.getScreenName()); - values.put(Accounts.NAME, user.getName()); - values.put(Accounts.PROFILE_IMAGE_URL, TwitterContentUtils.getProfileImageUrl(user)); - values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); - values.put(Accounts.COLOR, color); - values.put(Accounts.IS_ACTIVATED, 1); - values.put(Accounts.API_URL_FORMAT, apiUrlFormat); - values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); - return values; - } - - public static ContentValues createAccount(final OAuthAuthorization auth, final User user, - final int authType, final int color, - final String apiUrlFormat, final boolean sameOAuthSigningUrl, - final boolean noVersionSuffix) { - if (user == null || auth == null) return null; - final ContentValues values = new ContentValues(); - final OAuthToken accessToken = auth.getOauthToken(); - values.put(Accounts.OAUTH_TOKEN, accessToken.getOauthToken()); - values.put(Accounts.OAUTH_TOKEN_SECRET, accessToken.getOauthTokenSecret()); - values.put(Accounts.CONSUMER_KEY, auth.getConsumerKey()); - values.put(Accounts.CONSUMER_SECRET, auth.getConsumerSecret()); - values.put(Accounts.AUTH_TYPE, authType); - values.put(Accounts.ACCOUNT_ID, user.getId()); - values.put(Accounts.SCREEN_NAME, user.getScreenName()); - values.put(Accounts.NAME, user.getName()); - values.put(Accounts.PROFILE_IMAGE_URL, TwitterContentUtils.getProfileImageUrl(user)); - values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); - values.put(Accounts.COLOR, color); - values.put(Accounts.IS_ACTIVATED, 1); - values.put(Accounts.API_URL_FORMAT, apiUrlFormat); - values.put(Accounts.SAME_OAUTH_SIGNING_URL, sameOAuthSigningUrl); - values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); - return values; - } - - public static ContentValues createAccount(final User user, final int color, final String apiUrlFormat, - final boolean noVersionSuffix) { - if (user == null || user.getId() <= 0) return null; - final ContentValues values = new ContentValues(); - values.put(Accounts.AUTH_TYPE, ParcelableCredentials.AUTH_TYPE_TWIP_O_MODE); - values.put(Accounts.ACCOUNT_ID, user.getId()); - values.put(Accounts.SCREEN_NAME, user.getScreenName()); - values.put(Accounts.NAME, user.getName()); - values.put(Accounts.PROFILE_IMAGE_URL, TwitterContentUtils.getProfileImageUrl(user)); - values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); - values.put(Accounts.COLOR, color); - values.put(Accounts.IS_ACTIVATED, 1); - values.put(Accounts.API_URL_FORMAT, apiUrlFormat); - values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); - return values; - } - public static ContentValues createCachedRelationship(final Relationship relationship, final AccountKey accountKey) { final ContentValues values = new ContentValues(); - values.put(CachedRelationships.ACCOUNT_ID, accountKey.getId()); - values.put(CachedRelationships.ACCOUNT_HOST, accountKey.getHost()); + values.put(CachedRelationships.ACCOUNT_KEY, accountKey.toString()); values.put(CachedRelationships.USER_ID, relationship.getTargetUserId()); values.put(CachedRelationships.FOLLOWING, relationship.isSourceFollowingTarget()); values.put(CachedRelationships.FOLLOWED_BY, relationship.isSourceFollowedByTarget()); @@ -152,16 +84,16 @@ public final class ContentValuesCreator implements TwidereConstants { return values; } - public static ContentValues createDirectMessage(final DirectMessage message, final long accountId, - final String accountHost, final boolean isOutgoing) { + public static ContentValues createDirectMessage(final DirectMessage message, + final AccountKey accountKey, + final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); final User sender = message.getSender(), recipient = message.getRecipient(); if (sender == null || recipient == null) return null; final String sender_profile_image_url = TwitterContentUtils.getProfileImageUrl(sender); final String recipient_profile_image_url = TwitterContentUtils.getProfileImageUrl(recipient); - values.put(DirectMessages.ACCOUNT_ID, accountId); - values.put(DirectMessages.ACCOUNT_HOST, accountHost); + values.put(DirectMessages.ACCOUNT_KEY, accountKey.toString()); values.put(DirectMessages.MESSAGE_ID, message.getId()); values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime()); values.put(DirectMessages.SENDER_ID, sender.getId()); @@ -241,11 +173,10 @@ public final class ContentValuesCreator implements TwidereConstants { return values; } - public static ContentValues createSavedSearch(final SavedSearch savedSearch, final long accountId, - final String accountHost) { + public static ContentValues createSavedSearch(final SavedSearch savedSearch, + final AccountKey accountKey) { final ContentValues values = new ContentValues(); - values.put(SavedSearches.ACCOUNT_ID, accountId); - values.put(SavedSearches.ACCOUNT_HOST, accountHost); + values.put(SavedSearches.ACCOUNT_KEY, accountKey.toString()); values.put(SavedSearches.SEARCH_ID, savedSearch.getId()); values.put(SavedSearches.CREATED_AT, savedSearch.getCreatedAt().getTime()); values.put(SavedSearches.NAME, savedSearch.getName()); @@ -254,10 +185,10 @@ public final class ContentValuesCreator implements TwidereConstants { } public static ContentValues[] createSavedSearches(final List savedSearches, - final long accountId, final String accountHost) { + final AccountKey accountKey) { final ContentValues[] resultValuesArray = new ContentValues[savedSearches.size()]; for (int i = 0, j = savedSearches.size(); i < j; i++) { - resultValuesArray[i] = createSavedSearch(savedSearches.get(i), accountId, accountHost); + resultValuesArray[i] = createSavedSearch(savedSearches.get(i), accountKey); } return resultValuesArray; } 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 7e2fb1e26..b77e0dd28 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java @@ -200,14 +200,14 @@ public class DataStoreUtils implements Constants { 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_ID, DirectMessages.MESSAGE_ID, + 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_ID, Statuses.STATUS_ID, + return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Statuses.ACCOUNT_KEY, Statuses.STATUS_ID, new OrderBy(SQLFunctions.MAX(Statuses.STATUS_TIMESTAMP))); } @@ -215,21 +215,21 @@ public class DataStoreUtils implements Constants { @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_ID, + return getLongFieldArray(context, uri, AccountKey.getIds(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_ID, Statuses.STATUS_ID, + return getLongFieldArray(context, uri, AccountKey.getIds(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_ID, + return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Activities.ACCOUNT_KEY, Activities.MAX_POSITION, new OrderBy(SQLFunctions.MAX(Activities.TIMESTAMP))); } @@ -237,7 +237,7 @@ 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_ID, + return getLongFieldArray(context, uri, AccountKey.getIds(accountKeys), Activities.ACCOUNT_KEY, Activities.MAX_POSITION, new OrderBy(SQLFunctions.MIN(Activities.TIMESTAMP))); } @@ -387,7 +387,7 @@ public class DataStoreUtils implements Constants { public static String[] getAccountScreenNames(final Context context, @Nullable final AccountKey[] accountKeys) { if (context == null) return new String[0]; final String[] cols = new String[]{Accounts.SCREEN_NAME}; - final String where = accountKeys != null ? Expression.in(new Column(Accounts.ACCOUNT_ID), + final String where = accountKeys != null ? Expression.in(new Column(Accounts.ACCOUNT_KEY), new RawItemArray(accountKeys)).getSQL() : null; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, where, null, null); if (cur == null) return new String[0]; @@ -409,14 +409,14 @@ public class DataStoreUtils implements Constants { public static AccountKey[] getActivatedAccountKeys(final Context context) { if (context == null) return new AccountKey[0]; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, - new String[]{Accounts.ACCOUNT_ID, Accounts.ACCOUNT_HOST}, Accounts.IS_ACTIVATED + " = 1", null, null); + new String[]{Accounts.ACCOUNT_KEY}, Accounts.IS_ACTIVATED + " = 1", null, null); if (cur == null) return new AccountKey[0]; try { cur.moveToFirst(); final AccountKey[] ids = new AccountKey[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { - ids[i++] = new AccountKey(cur.getLong(0), cur.getString(1)); + ids[i++] = AccountKey.valueOf(cur.getString(0)); cur.moveToNext(); } return ids; @@ -429,12 +429,12 @@ public class DataStoreUtils implements Constants { if (context == null) return 0; final RawItemArray idsIn; if (ArrayUtils.isEmpty(accountKeys)) { - idsIn = new RawItemArray(getActivatedAccountKeys(context)); + idsIn = new RawItemArray(AccountKey.getIds(getActivatedAccountKeys(context))); } else { - idsIn = new RawItemArray(accountKeys); + idsIn = new RawItemArray(AccountKey.getIds(accountKeys)); } final Expression selection = Expression.and( - Expression.in(new Column(Statuses.ACCOUNT_ID), idsIn), + Expression.in(new Column(Statuses.ACCOUNT_KEY), idsIn), Expression.greaterThan(Statuses.STATUS_ID, sinceId), buildStatusFilterWhereClause(getTableNameByUri(uri), null) ); @@ -447,9 +447,9 @@ public class DataStoreUtils implements Constants { if (context == null) return 0; final RawItemArray idsIn; if (ArrayUtils.isEmpty(accountKeys)) { - idsIn = new RawItemArray(getActivatedAccountKeys(context)); + idsIn = new RawItemArray(AccountKey.getIds(getActivatedAccountKeys(context))); } else { - idsIn = new RawItemArray(accountKeys); + idsIn = new RawItemArray(AccountKey.getIds(accountKeys)); } Expression[] expressions; if (extraWhere != null) { @@ -458,7 +458,7 @@ public class DataStoreUtils implements Constants { } else { expressions = new Expression[3]; } - expressions[0] = Expression.in(new Column(Activities.ACCOUNT_ID), idsIn); + expressions[0] = Expression.in(new Column(Activities.ACCOUNT_KEY), idsIn); expressions[1] = Expression.greaterThan(Activities.TIMESTAMP, sinceTimestamp); expressions[2] = buildActivityFilterWhereClause(getTableNameByUri(uri), null); final Expression selection = Expression.and(expressions); @@ -638,8 +638,8 @@ public class DataStoreUtils implements Constants { public static int[] getAccountColors(final Context context, final long[] accountIds) { if (context == null || accountIds == null) return new int[0]; - final String[] cols = new String[]{Accounts.ACCOUNT_ID, Accounts.COLOR}; - final String where = Expression.in(new Column(Accounts.ACCOUNT_ID), new RawItemArray(accountIds)).getSQL(); + final String[] cols = new String[]{Accounts.ACCOUNT_KEY, Accounts.COLOR}; + final String where = Expression.in(new Column(Accounts.ACCOUNT_KEY), new RawItemArray(accountIds)).getSQL(); final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, where, null, null); if (cur == null) return new int[0]; try { @@ -656,7 +656,7 @@ public class DataStoreUtils implements Constants { public static AccountKey getAccountKey(final Context context, final String screenName) { if (context == null || isEmpty(screenName)) return null; - final String[] projection = {Accounts.ACCOUNT_ID, Accounts.ACCOUNT_HOST}; + final String[] projection = {Accounts.ACCOUNT_KEY}; final String where = Expression.equalsArgs(Accounts.SCREEN_NAME).getSQL(); final String[] whereArgs = {screenName}; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, projection, @@ -664,7 +664,7 @@ public class DataStoreUtils implements Constants { if (cur == null) return null; try { if (cur.moveToFirst()) { - return new AccountKey(cur.getLong(0), cur.getString(1)); + return AccountKey.valueOf(cur.getString(0)); } return null; } finally { @@ -675,7 +675,7 @@ public class DataStoreUtils implements Constants { @NonNull public static AccountKey[] getAccountKeys(final Context context) { if (context == null) return new AccountKey[0]; - final String[] projection = {Accounts.ACCOUNT_ID, Accounts.ACCOUNT_HOST}; + final String[] projection = {Accounts.ACCOUNT_KEY}; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, projection, null, null, null); if (cur == null) return new AccountKey[0]; @@ -684,7 +684,7 @@ public class DataStoreUtils implements Constants { final AccountKey[] ids = new AccountKey[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { - ids[i++] = new AccountKey(cur.getLong(0), cur.getString(1)); + ids[i++] = AccountKey.valueOf(cur.getString(0)); cur.moveToNext(); } return ids; @@ -718,8 +718,7 @@ public class DataStoreUtils implements Constants { continue; } final String table = getTableNameByUri(uri); - final Expression accountWhere = Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_ID), - Expression.equalsArgs(Statuses.ACCOUNT_HOST)); + final Expression accountWhere = Expression.equalsArgs(Statuses.ACCOUNT_KEY); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(Statuses._ID)) .from(new Tables(table)) @@ -729,14 +728,12 @@ public class DataStoreUtils implements Constants { final Expression where = Expression.and(Expression.lesserThan(new Column(Statuses._ID), SQLQueryBuilder.select(SQLFunctions.MIN(new Column(Statuses._ID))).from(qb.build()).build()), accountWhere); - final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost(), - String.valueOf(accountKey.getId()), accountKey.getHost()}; + final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)}; resolver.delete(uri, where.getSQL(), whereArgs); } for (final Uri uri : ACTIVITIES_URIS) { final String table = getTableNameByUri(uri); - final Expression accountWhere = Expression.and(Expression.equalsArgs(Accounts.ACCOUNT_ID), - Expression.equalsArgs(Accounts.ACCOUNT_HOST)); + final Expression accountWhere = Expression.equalsArgs(Accounts.ACCOUNT_KEY); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(Activities._ID)) .from(new Tables(table)) @@ -746,14 +743,12 @@ public class DataStoreUtils implements Constants { final Expression where = Expression.and(Expression.lesserThan(new Column(Activities._ID), SQLQueryBuilder.select(SQLFunctions.MIN(new Column(Activities._ID))) .from(qb.build()).build()), accountWhere); - final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost(), - String.valueOf(accountKey.getId()), accountKey.getHost()}; + final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)}; resolver.delete(uri, where.getSQL(), whereArgs); } for (final Uri uri : DIRECT_MESSAGES_URIS) { final String table = getTableNameByUri(uri); - final Expression accountWhere = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_ID), - Expression.equalsArgs(DirectMessages.ACCOUNT_HOST)); + final Expression accountWhere = Expression.equalsArgs(Accounts.ACCOUNT_KEY); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(DirectMessages._ID)) .from(new Tables(table)) @@ -763,8 +758,7 @@ public class DataStoreUtils implements Constants { final Expression where = Expression.and(Expression.lesserThan(new Column(DirectMessages._ID), SQLQueryBuilder.select(SQLFunctions.MIN(new Column(DirectMessages._ID))) .from(qb.build()).build()), accountWhere); - final String[] whereArgs = {String.valueOf(accountKey.getId()), accountKey.getHost(), - String.valueOf(accountKey.getId()), accountKey.getHost()}; + final String[] whereArgs = {String.valueOf(accountKey), String.valueOf(accountKey)}; resolver.delete(uri, where.getSQL(), whereArgs); } } @@ -892,13 +886,13 @@ public class DataStoreUtils implements Constants { public static ParcelableCredentials getCredentials(@NonNull final Context context, final long accountId, final String accountHost) { Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, - Expression.equals(Accounts.ACCOUNT_ID, accountId).getSQL(), null, null); + Expression.equals(Accounts.ACCOUNT_KEY, accountId).getSQL(), null, null); if (cur == null) return null; try { ParcelableCredentialsCursorIndices i = new ParcelableCredentialsCursorIndices(cur); cur.moveToFirst(); while (!cur.isAfterLast()) { - if (TextUtils.equals(cur.getString(i.account_host), accountHost)) { + if (TextUtils.equals(cur.getString(i.account_key), accountHost)) { return i.newObject(cur); } cur.moveToNext(); @@ -988,9 +982,9 @@ public class DataStoreUtils implements Constants { public static void initAccountColor(final Context context) { if (context == null) return; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[]{ - Accounts.ACCOUNT_ID, Accounts.COLOR}, null, null, null); + Accounts.ACCOUNT_KEY, Accounts.COLOR}, null, null, null); if (cur == null) return; - final int id_idx = cur.getColumnIndex(Accounts.ACCOUNT_ID), color_idx = cur.getColumnIndex(Accounts.COLOR); + final int id_idx = cur.getColumnIndex(Accounts.ACCOUNT_KEY), color_idx = cur.getColumnIndex(Accounts.COLOR); cur.moveToFirst(); while (!cur.isAfterLast()) { // sAccountColors.put(cur.getLong(id_idx), cur.getInt(color_idx)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java index cf4175ed1..8a066ddb5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java @@ -62,7 +62,7 @@ public class IntentUtils implements Constants { final Uri.Builder builder = new Uri.Builder(); builder.scheme(TwidereConstants.SCHEME_TWIDERE); builder.authority(TwidereConstants.AUTHORITY_USER); - builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id)); + builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_key)); if (user.id > 0) { builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_USER_ID, String.valueOf(user.id)); } @@ -130,16 +130,15 @@ public class IntentUtils implements Constants { public static void openMedia(@NonNull final Context context, final ParcelableDirectMessage message, final ParcelableMedia current, @Nullable final Bundle options, final boolean newDocument) { - openMedia(context, new AccountKey(message.account_id, message.account_host), false, null, - message, current, message.media, options, newDocument); + openMedia(context, message.account_key, false, null, message, current, message.media, + options, newDocument); } public static void openMedia(@NonNull final Context context, final ParcelableStatus status, final ParcelableMedia current, final Bundle options, final boolean newDocument) { - openMedia(context, new AccountKey(status.account_id, status.account_host), - status.is_possibly_sensitive, status, null, current, getPrimaryMedia(status), - options, newDocument); + openMedia(context, status.account_key, status.is_possibly_sensitive, status, null, current, + getPrimaryMedia(status), options, newDocument); } public static void openMedia(@NonNull final Context context, @Nullable final AccountKey accountKey, final boolean isPossiblySensitive, @@ -359,7 +358,7 @@ public class IntentUtils implements Constants { } public static void openStatus(@NonNull final Context context, @NonNull final ParcelableStatus status, Bundle activityOptions) { - final AccountKey accountKey = new AccountKey(status.account_id, status.account_host); + final AccountKey accountKey = status.account_key; final long statusId = status.id; final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_STATUS, status); 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 3286473a4..c66353dc3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java @@ -175,10 +175,9 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback, final Intent intent = item.getIntent(); if (intent == null || !intent.hasExtra(EXTRA_ACCOUNT)) return false; final ParcelableAccount account = intent.getParcelableExtra(EXTRA_ACCOUNT); - final AccountKey accountKey = new AccountKey(account.account_id, account.account_host); - mMultiSelectManager.setAccountKey(accountKey); + mMultiSelectManager.setAccountKey(account.account_key); if (mAccountActionProvider != null) { - mAccountActionProvider.setSelectedAccountIds(accountKey); + mAccountActionProvider.setSelectedAccountIds(account.account_key); } mode.invalidate(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java index c7600d9e0..c1d354287 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java @@ -117,10 +117,10 @@ public class MultiSelectManager implements Constants { final Object obj = selectedItems.get(0); if (obj instanceof ParcelableUser) { final ParcelableUser user = (ParcelableUser) obj; - return new AccountKey(user.account_id, user.account_host); + return user.account_key; } else if (obj instanceof ParcelableStatus) { final ParcelableStatus status = (ParcelableStatus) obj; - return new AccountKey(status.account_id, status.account_host); + return status.account_key; } return null; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereCollectionUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereCollectionUtils.java new file mode 100644 index 000000000..fe2d79f58 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereCollectionUtils.java @@ -0,0 +1,19 @@ +package org.mariotaku.twidere.util; + +import java.util.Collection; + +/** + * Created by mariotaku on 16/3/7. + */ +public class TwidereCollectionUtils { + public static String[] toStringArray(final Collection list) { + if (list == null) return null; + final int length = list.size(); + final String[] stringArray = new String[length]; + int idx = 0; + for (Object o : list) { + stringArray[idx++] = ParseUtils.parseString(o); + } + return stringArray; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereListUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereListUtils.java index c7cdd5657..d9ce57843 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereListUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereListUtils.java @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class TwidereListUtils { @@ -48,13 +49,4 @@ public class TwidereListUtils { return builder.toString(); } - public static String[] toStringArray(final List list) { - if (list == null) return null; - final int length = list.size(); - final String[] stringArray = new String[length]; - for (int i = 0; i < length; i++) { - stringArray[i] = ParseUtils.parseString(list.get(i)); - } - return stringArray; - } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereQueryBuilder.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereQueryBuilder.java index 8cb3bce09..7af93e3f7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereQueryBuilder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereQueryBuilder.java @@ -63,7 +63,7 @@ public class TwidereQueryBuilder { final Column usersUserId = new Column(new Table(CachedUsers.TABLE_NAME), CachedRelationships.USER_ID); final Column relationshipsAccountId = new Column(new Table(CachedRelationships.TABLE_NAME), - CachedRelationships.ACCOUNT_ID); + CachedRelationships.ACCOUNT_KEY); final Expression on = Expression.and( Expression.equals(relationshipsUserId, usersUserId), Expression.equals(relationshipsAccountId, accountId) @@ -128,7 +128,7 @@ public class TwidereQueryBuilder { final Selectable select = Utils.getColumnsFromProjection(projection); final SQLSelectQuery.Builder qb = SQLQueryBuilder.select(select); qb.from(new Tables(DirectMessages.TABLE_NAME)); - final Expression accountIdWhere = Expression.equals(DirectMessages.ACCOUNT_ID, account_id); + final Expression accountIdWhere = Expression.equals(DirectMessages.ACCOUNT_KEY, account_id); final Expression incomingWhere = Expression.and(Expression.notEquals(DirectMessages.IS_OUTGOING, 1), Expression.equals(DirectMessages.SENDER_ID, conversationId)); final Expression outgoingWhere = Expression.and(Expression.equals(DirectMessages.IS_OUTGOING, 1), @@ -149,7 +149,7 @@ public class TwidereQueryBuilder { final SQLSelectQuery.Builder qb = SQLQueryBuilder.select(select); qb.select(select); qb.from(new Tables(DirectMessages.TABLE_NAME)); - final Expression accountIdWhere = Expression.equals(DirectMessages.ACCOUNT_ID, account_id); + final Expression accountIdWhere = Expression.equals(DirectMessages.ACCOUNT_KEY, account_id); final Expression incomingWhere = Expression.and(Expression.notEquals(DirectMessages.IS_OUTGOING, 1), Expression.equals(new Column(DirectMessages.SENDER_SCREEN_NAME), screen_name)); final Expression outgoingWhere = Expression.and(Expression.equals(DirectMessages.IS_OUTGOING, 1), @@ -176,7 +176,7 @@ public class TwidereQueryBuilder { qb.select(new Columns(new Column(ConversationEntries._ID), new Column(ConversationEntries.MESSAGE_TIMESTAMP), new Column(ConversationEntries.MESSAGE_ID), - new Column(ConversationEntries.ACCOUNT_ID), + new Column(ConversationEntries.ACCOUNT_KEY), new Column(ConversationEntries.ACCOUNT_HOST), new Column(ConversationEntries.IS_OUTGOING), new Column(ConversationEntries.NAME), @@ -188,7 +188,7 @@ public class TwidereQueryBuilder { entryIds.select(new Columns(new Column(DirectMessages._ID), new Column(DirectMessages.MESSAGE_TIMESTAMP), new Column(DirectMessages.MESSAGE_ID), - new Column(DirectMessages.ACCOUNT_ID), + new Column(DirectMessages.ACCOUNT_KEY), new Column(DirectMessages.ACCOUNT_HOST), new Column("0", DirectMessages.IS_OUTGOING), new Column(DirectMessages.SENDER_NAME, ConversationEntries.NAME), @@ -201,7 +201,7 @@ public class TwidereQueryBuilder { entryIds.select(new Columns(new Column(DirectMessages._ID), new Column(DirectMessages.MESSAGE_TIMESTAMP), new Column(DirectMessages.MESSAGE_ID), - new Column(DirectMessages.ACCOUNT_ID), + new Column(DirectMessages.ACCOUNT_KEY), new Column(DirectMessages.ACCOUNT_HOST), new Column("1", DirectMessages.IS_OUTGOING), new Column(DirectMessages.RECIPIENT_NAME, ConversationEntries.NAME), @@ -239,7 +239,7 @@ public class TwidereQueryBuilder { where = groupedWhere; } qb.where(where); - qb.groupBy(Utils.getColumnsFromProjection(ConversationEntries.CONVERSATION_ID, DirectMessages.ACCOUNT_ID)); + qb.groupBy(Utils.getColumnsFromProjection(ConversationEntries.CONVERSATION_ID, DirectMessages.ACCOUNT_KEY)); qb.orderBy(new OrderBy(ConversationEntries.MESSAGE_TIMESTAMP, false)); return qb.build(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIFactory.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIFactory.java index 17ff2e7d4..9775d4682 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIFactory.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIFactory.java @@ -402,7 +402,7 @@ public class TwitterAPIFactory implements TwidereConstants { public static ConsumerKeyType getOfficialKeyType(final Context context, final long accountId) { if (context == null) return ConsumerKeyType.UNKNOWN; final String[] projection = {Accounts.CONSUMER_KEY, Accounts.CONSUMER_SECRET, Accounts.AUTH_TYPE}; - final String selection = Expression.equals(Accounts.ACCOUNT_ID, accountId).getSQL(); + final String selection = Expression.equals(Accounts.ACCOUNT_KEY, accountId).getSQL(); final Cursor c = context.getContentResolver().query(Accounts.CONTENT_URI, projection, selection, null, null); if (c == null) return ConsumerKeyType.UNKNOWN; //noinspection TryFinallyCanBeTryWithResources diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java index 08aace4b0..71d186939 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java @@ -23,6 +23,7 @@ import android.content.Context; import android.net.Uri; import android.support.annotation.NonNull; import android.support.v4.util.LongSparseArray; +import android.support.v4.util.SimpleArrayMap; import android.util.Log; import org.mariotaku.restfu.http.mime.FileBody; @@ -88,11 +89,12 @@ public class TwitterWrapper implements Constants { return result; } - public static int removeUnreadCounts(final Context context, final int position, final LongSparseArray> counts) { + public static int removeUnreadCounts(final Context context, final int position, + final SimpleArrayMap> counts) { if (context == null || position < 0 || counts == null) return 0; int result = 0; for (int i = 0, j = counts.size(); i < j; i++) { - final long key = counts.keyAt(i); + final AccountKey key = counts.keyAt(i); final Set value = counts.valueAt(i); final Uri.Builder builder = UnreadCounts.CONTENT_URI.buildUpon(); builder.appendPath(String.valueOf(position)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index d0f2f61a6..bd607ff96 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -848,15 +848,17 @@ public final class Utils implements Constants { return buf.toString(); } - public static ParcelableDirectMessage findDirectMessageInDatabases(final Context context, final long account_id, - final long message_id) { + public static ParcelableDirectMessage findDirectMessageInDatabases(final Context context, + final AccountKey accountKey, + final long messageId) { if (context == null) return null; final ContentResolver resolver = context.getContentResolver(); ParcelableDirectMessage message = null; - final String where = DirectMessages.ACCOUNT_ID + " = " + account_id + " AND " + DirectMessages.MESSAGE_ID - + " = " + message_id; + final String where = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY), + Expression.equalsArgs(DirectMessages.MESSAGE_ID)).getSQL(); + final String[] whereArgs = {accountKey.toString(), String.valueOf(messageId)}; for (final Uri uri : DIRECT_MESSAGES_URIS) { - final Cursor cur = resolver.query(uri, DirectMessages.COLUMNS, where, null, null); + final Cursor cur = resolver.query(uri, DirectMessages.COLUMNS, where, whereArgs, null); if (cur == null) { continue; } @@ -878,7 +880,7 @@ public final class Utils implements Constants { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountKey, true); if (twitter == null) throw new TwitterException("Account does not exist"); final Status status = twitter.showStatus(statusId); - final String where = Expression.and(Expression.equals(Statuses.ACCOUNT_ID, accountKey.getId()), + final String where = Expression.and(Expression.equals(Statuses.ACCOUNT_KEY, accountKey.getId()), Expression.equals(Statuses.STATUS_ID, statusId)).getSQL(); final ContentResolver resolver = context.getContentResolver(); resolver.delete(CachedStatuses.CONTENT_URI, where, null); @@ -892,7 +894,7 @@ public final class Utils implements Constants { if (context == null) return null; final ContentResolver resolver = context.getContentResolver(); ParcelableStatus status = null; - final String where = Expression.and(Expression.equals(Statuses.ACCOUNT_ID, accountKey.getId()), + final String where = Expression.and(Expression.equals(Statuses.ACCOUNT_KEY, accountKey.getId()), Expression.equals(Statuses.STATUS_ID, statusId)).getSQL(); for (final Uri uri : STATUSES_URIS) { final Cursor cur = resolver.query(uri, Statuses.COLUMNS, where, null, null); @@ -1587,8 +1589,8 @@ public final class Utils implements Constants { 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_ID).getSQL(); - final String[] projection = new String[]{Accounts.ACCOUNT_HOST}; + 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); if (cur == null) return false; @@ -1615,7 +1617,7 @@ public final class Utils implements Constants { } public static boolean isMyRetweet(final ParcelableStatus status) { - return status != null && isMyRetweet(status.account_id, status.retweeted_by_user_id, status.my_retweet_id); + return status != null && isMyRetweet(status.account_key.getId(), status.retweeted_by_user_id, status.my_retweet_id); } public static boolean isMyRetweet(final long accountId, final long retweetedById, final long myRetweetId) { @@ -1798,7 +1800,7 @@ public final class Utils implements Constants { static boolean isMyStatus(ParcelableStatus status) { if (isMyRetweet(status)) return true; - return status.account_id == status.user_id; + return status.account_key.getId() == status.user_id; } public static boolean shouldStopAutoRefreshOnBatteryLow(final Context context) { @@ -2258,9 +2260,7 @@ public final class Utils implements Constants { } public static Expression getAccountCompareExpression() { - return Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_ID), - Expression.or(Expression.isNull(new Column(Statuses.ACCOUNT_HOST)), - Expression.equalsArgs(Statuses.ACCOUNT_HOST))); + return Expression.equalsArgs(Statuses.ACCOUNT_KEY); } static class UtilsL { 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 885a2c8bd..ebdd9879e 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 @@ -86,7 +86,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C db.execSQL(createTable(CachedStatuses.TABLE_NAME, CachedStatuses.COLUMNS, CachedStatuses.TYPES, true)); db.execSQL(createTable(CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS, CachedHashtags.TYPES, true)); db.execSQL(createTable(CachedRelationships.TABLE_NAME, CachedRelationships.COLUMNS, CachedRelationships.TYPES, true, - createConflictReplaceConstraint(CachedRelationships.ACCOUNT_ID, CachedRelationships.USER_ID))); + createConflictReplaceConstraint(CachedRelationships.ACCOUNT_KEY, CachedRelationships.USER_ID))); db.execSQL(createTable(Filters.Users.TABLE_NAME, Filters.Users.COLUMNS, Filters.Users.TYPES, true)); db.execSQL(createTable(Filters.Keywords.TABLE_NAME, Filters.Keywords.COLUMNS, Filters.Keywords.TYPES, true)); db.execSQL(createTable(Filters.Sources.TABLE_NAME, Filters.Sources.COLUMNS, Filters.Sources.TYPES, true)); @@ -115,9 +115,9 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C private void createIndices(SQLiteDatabase db) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; - db.execSQL(createIndex("statuses_index", Statuses.TABLE_NAME, new String[]{Statuses.ACCOUNT_ID}, true)); - db.execSQL(createIndex("messages_inbox_index", DirectMessages.Inbox.TABLE_NAME, new String[]{DirectMessages.ACCOUNT_ID}, true)); - db.execSQL(createIndex("messages_outbox_index", DirectMessages.Outbox.TABLE_NAME, new String[]{DirectMessages.ACCOUNT_ID}, true)); + db.execSQL(createIndex("statuses_index", Statuses.TABLE_NAME, new String[]{Statuses.ACCOUNT_KEY}, true)); + db.execSQL(createIndex("messages_inbox_index", DirectMessages.Inbox.TABLE_NAME, new String[]{DirectMessages.ACCOUNT_KEY}, true)); + db.execSQL(createIndex("messages_outbox_index", DirectMessages.Outbox.TABLE_NAME, new String[]{DirectMessages.ACCOUNT_KEY}, true)); } private void createViews(SQLiteDatabase db) { @@ -171,7 +171,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C private SQLQuery createDeleteDuplicateStatusTrigger(String triggerName, String tableName) { final Table table = new Table(tableName); final SQLDeleteQuery deleteOld = SQLQueryBuilder.deleteFrom(table).where(Expression.and( - Expression.equals(new Column(Statuses.ACCOUNT_ID), new Column(Table.NEW, Statuses.ACCOUNT_ID)), + Expression.equals(new Column(Statuses.ACCOUNT_KEY), new Column(Table.NEW, Statuses.ACCOUNT_KEY)), Expression.equals(new Column(Statuses.STATUS_ID), new Column(Table.NEW, Statuses.STATUS_ID)) )).build(); return SQLQueryBuilder.createTrigger(false, true, triggerName) @@ -183,7 +183,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C private SQLQuery createDeleteDuplicateMessageTrigger(String triggerName, String tableName) { final Table table = new Table(tableName); final SQLDeleteQuery deleteOld = SQLQueryBuilder.deleteFrom(table).where(Expression.and( - Expression.equals(new Column(DirectMessages.ACCOUNT_ID), new Column(Table.NEW, DirectMessages.ACCOUNT_ID)), + Expression.equals(new Column(DirectMessages.ACCOUNT_KEY), new Column(Table.NEW, DirectMessages.ACCOUNT_KEY)), Expression.equals(new Column(DirectMessages.MESSAGE_ID), new Column(Table.NEW, DirectMessages.MESSAGE_ID)) )).build(); return SQLQueryBuilder.createTrigger(false, true, triggerName) @@ -220,7 +220,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C final HashMap draftsAlias = new HashMap<>(); accountsAlias.put(Accounts.SCREEN_NAME, "username"); accountsAlias.put(Accounts.NAME, "username"); - accountsAlias.put(Accounts.ACCOUNT_ID, "user_id"); + accountsAlias.put(Accounts.ACCOUNT_KEY, "user_id"); accountsAlias.put(Accounts.COLOR, "user_color"); accountsAlias.put(Accounts.OAUTH_TOKEN_SECRET, "token_secret"); accountsAlias.put(Accounts.API_URL_FORMAT, "rest_base_url"); @@ -237,7 +237,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C safeUpgrade(db, CachedStatuses.TABLE_NAME, CachedStatuses.COLUMNS, CachedStatuses.TYPES, true, null); safeUpgrade(db, CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS, CachedHashtags.TYPES, true, null); safeUpgrade(db, CachedRelationships.TABLE_NAME, CachedRelationships.COLUMNS, CachedRelationships.TYPES, true, null, - createConflictReplaceConstraint(CachedRelationships.ACCOUNT_ID, CachedRelationships.USER_ID)); + createConflictReplaceConstraint(CachedRelationships.ACCOUNT_KEY, CachedRelationships.USER_ID)); safeUpgrade(db, Filters.Users.TABLE_NAME, Filters.Users.COLUMNS, Filters.Users.TYPES, oldVersion < 49, null); safeUpgrade(db, Filters.Keywords.TABLE_NAME, Filters.Keywords.COLUMNS, Filters.Keywords.TYPES, diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java index b54d47351..3ddd178f4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java @@ -69,7 +69,7 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene final MediaLoaderWrapper loader = adapter.getMediaLoader(); final UserColorNameManager manager = adapter.getUserColorNameManager(); - final AccountKey accountKey = new AccountKey(cursor.getLong(ConversationEntries.IDX_ACCOUNT_ID), + final AccountKey accountKey = new AccountKey(cursor.getLong(ConversationEntries.IDX_ACCOUNT_KEY), cursor.getString(ConversationEntries.IDX_ACCOUNT_HOST)); final long conversationId = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID); final long timestamp = cursor.getLong(ConversationEntries.IDX_MESSAGE_TIMESTAMP); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java index dde99fe7e..61186a512 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserViewHolder.java @@ -116,7 +116,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon loader.cancelDisplayTask(profileImageView); } - if (twitter.isProcessingFollowRequest(user.account_id, user.id)) { + if (twitter.isProcessingFollowRequest(user.account_key, user.id)) { processingRequestProgress.setVisibility(View.VISIBLE); acceptRequestButton.setVisibility(View.GONE); denyRequestButton.setVisibility(View.GONE);