diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/statusnet/model/Attention.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/statusnet/model/Attention.java new file mode 100644 index 000000000..0b92ac29c --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/statusnet/model/Attention.java @@ -0,0 +1,53 @@ +package org.mariotaku.twidere.api.statusnet.model; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +/** + * Created by mariotaku on 16/3/7. + */ +@JsonObject +public class Attention { + + @JsonField(name = "fullname") + String fullName; + @JsonField(name = "id") + long id; + @JsonField(name = "ostatus_uri") + String ostatusUri; + @JsonField(name = "profileurl") + String profileUrl; + @JsonField(name = "screen_name") + String screenName; + + public String getFullName() { + return fullName; + } + + public long getId() { + return id; + } + + public String getOstatusUri() { + return ostatusUri; + } + + public String getProfileUrl() { + return profileUrl; + } + + public String getScreenName() { + return screenName; + } + + @Override + public String toString() { + return "Attention{" + + "fullName='" + fullName + '\'' + + ", id='" + id + '\'' + + ", ostatusUri='" + ostatusUri + '\'' + + ", profileUrl='" + profileUrl + '\'' + + ", screenName='" + screenName + '\'' + + '}'; + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java index d1c184eb1..e33d7f892 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java @@ -30,6 +30,7 @@ import org.mariotaku.twidere.api.twitter.model.RateLimitStatus; import org.mariotaku.twidere.api.twitter.model.TwitterResponse; import org.mariotaku.twidere.api.twitter.util.InternalParseUtil; +import java.io.IOException; import java.util.Locale; /** @@ -76,6 +77,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http if (cause instanceof TwitterException) { ((TwitterException) cause).setNested(); } + setCausedByNetworkIssue(cause instanceof IOException); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java index fa4d840ae..6a67ec22c 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java @@ -27,6 +27,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.OnJsonParseComplete; import org.mariotaku.twidere.api.gnusocial.model.Attachment; +import org.mariotaku.twidere.api.statusnet.model.Attention; import org.mariotaku.twidere.api.twitter.util.TwitterDateConverter; import java.io.IOException; @@ -124,6 +125,9 @@ public class Status extends TwitterResponseObject implements Comparable, @JsonField(name = "external_url") String externalUrl; + @JsonField(name = "attentions") + Attention[] attentions; + public User getUser() { return user; @@ -308,6 +312,10 @@ public class Status extends TwitterResponseObject implements Comparable, return externalUrl; } + public Attention[] getAttentions() { + return attentions; + } + @Override public int compareTo(@NonNull final Status that) { final long delta = id - that.getId(); @@ -317,7 +325,6 @@ public class Status extends TwitterResponseObject implements Comparable, return (int) delta; } - @Override public String toString() { return "Status{" + @@ -347,7 +354,10 @@ public class Status extends TwitterResponseObject implements Comparable, ", quotedStatus=" + quotedStatus + ", card=" + card + ", possiblySensitive=" + possiblySensitive + - '}'; + ", attachments=" + Arrays.toString(attachments) + + ", externalUrl='" + externalUrl + '\'' + + ", attentions=" + Arrays.toString(attentions) + + "} " + super.toString(); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index a817e135e..0848a6716 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -105,6 +105,7 @@ public interface IntentConstants { String EXTRA_PAGE = "page"; String EXTRA_DATA = "data"; String EXTRA_QUERY = "query"; + String EXTRA_USER_KEY = "user_key"; String EXTRA_USER_ID = "user_id"; String EXTRA_USER_IDS = "user_ids"; String EXTRA_LIST_ID = "list_id"; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Draft.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Draft.java index 7f01acd30..320ba327b 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Draft.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Draft.java @@ -30,7 +30,7 @@ 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.draft.ActionExtra; -import org.mariotaku.twidere.model.util.AccountKeysCursorFieldConverter; +import org.mariotaku.twidere.model.util.UserKeysCursorFieldConverter; import org.mariotaku.twidere.model.util.DraftExtrasConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Drafts; @@ -43,8 +43,8 @@ import java.lang.annotation.RetentionPolicy; public class Draft implements Parcelable { @ParcelableThisPlease - @CursorField(value = Drafts.ACCOUNT_IDS, converter = AccountKeysCursorFieldConverter.class) - public AccountKey[] account_ids; + @CursorField(value = Drafts.ACCOUNT_IDS, converter = UserKeysCursorFieldConverter.class) + public UserKey[] account_ids; @ParcelableThisPlease @CursorField(value = Drafts._ID, excludeWrite = true) public long _id; 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 87cb4914c..e5245b021 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,8 +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.UserKeyConverter; +import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -46,9 +46,9 @@ public class ParcelableAccount implements Parcelable { public long id; @ParcelableThisPlease - @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) - @CursorField(value = Accounts.ACCOUNT_KEY, converter = AccountKeyCursorFieldConverter.class) - public AccountKey account_key; + @JsonField(name = "account_id", typeConverter = UserKeyConverter.class) + @CursorField(value = Accounts.ACCOUNT_KEY, converter = UserKeyCursorFieldConverter.class) + public UserKey account_key; @ParcelableThisPlease @JsonField(name = "screen_name") 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 98d85d58c..fd9228ea0 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 @@ -22,7 +22,6 @@ package org.mariotaku.twidere.model; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -31,9 +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.api.twitter.model.Activity; -import org.mariotaku.twidere.model.util.AccountKeyConverter; -import org.mariotaku.twidere.model.util.AccountKeyCursorFieldConverter; +import org.mariotaku.twidere.model.util.UserKeyConverter; +import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.model.util.LongArrayConverter; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -61,9 +59,9 @@ public class ParcelableActivity implements Comparable, Parce @CursorField(value = Activities._ID, excludeWrite = true) public long _id; @ParcelableThisPlease - @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) - @CursorField(value = Activities.ACCOUNT_KEY, converter = AccountKeyCursorFieldConverter.class) - public AccountKey account_key; + @JsonField(name = "account_id", typeConverter = UserKeyConverter.class) + @CursorField(value = Activities.ACCOUNT_KEY, converter = UserKeyCursorFieldConverter.class) + public UserKey account_key; @ParcelableThisPlease @JsonField(name = "timestamp") @CursorField(value = Activities.TIMESTAMP) @@ -134,7 +132,7 @@ public class ParcelableActivity implements Comparable, Parce public ParcelableActivity() { } - public static int calculateHashCode(AccountKey accountKey, long timestamp, long maxPosition, long minPosition) { + public static int calculateHashCode(UserKey accountKey, long timestamp, long maxPosition, long minPosition) { int result = accountKey.hashCode(); result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); result = 31 * result + (int) (maxPosition ^ (maxPosition >>> 32)); diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableCardEntity.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableCardEntity.java index dfaa3bb82..5a4de2d0e 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableCardEntity.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableCardEntity.java @@ -33,7 +33,7 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; import org.mariotaku.twidere.api.twitter.model.CardEntity; -import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.UserKeyConverter; import java.util.Arrays; import java.util.HashMap; @@ -58,8 +58,8 @@ public final class ParcelableCardEntity implements Parcelable { } }; @ParcelableThisPlease - @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) - public AccountKey account_key; + @JsonField(name = "account_id", typeConverter = UserKeyConverter.class) + public UserKey account_key; @ParcelableThisPlease @JsonField(name = "name") public String name; 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 6cbb55516..8fc70260f 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,8 +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.UserKeyConverter; +import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.LoganSquareCursorFieldConverter; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; @@ -55,9 +55,9 @@ public class ParcelableDirectMessage implements Parcelable, Comparable, Cloneable { + + public static final Comparator REVERSE_TIMESTAMP_COMPARATOR = new Comparator() { + + @Override + public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { + final long diff = object1.timestamp - object2.timestamp; + if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; + if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; + return (int) diff; + } + }; + @ParcelableThisPlease @JsonField(name = "id") @CursorField(Statuses.STATUS_ID) public long id; - public static final Comparator REVERSE_ID_COMPARATOR = new Comparator() { - - @Override - public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { - final long diff = object1.id - object2.id; - if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; - if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; - return (int) diff; - } - }; @ParcelableThisPlease - @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) - @CursorField(value = Statuses.ACCOUNT_KEY, converter = AccountKeyCursorFieldConverter.class) - public AccountKey account_key; + @JsonField(name = "account_id", typeConverter = UserKeyConverter.class) + @CursorField(value = Statuses.ACCOUNT_KEY, converter = UserKeyCursorFieldConverter.class) + public UserKey account_key; @ParcelableThisPlease @JsonField(name = "timestamp") @CursorField(Statuses.STATUS_TIMESTAMP) public long timestamp; - public static final Comparator TIMESTAMP_COMPARATOR = new Comparator() { - - @Override - public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { - final long diff = object2.timestamp - object1.timestamp; - if (diff > Integer.MAX_VALUE) return Integer.MAX_VALUE; - if (diff < Integer.MIN_VALUE) return Integer.MIN_VALUE; - return (int) diff; - } - }; @ParcelableThisPlease - @JsonField(name = "user_id") - @CursorField(Statuses.USER_ID) - public long user_id = -1; + @JsonField(name = "user_id", typeConverter = UserKeyConverter.class) + @CursorField(value = Statuses.USER_ID, converter = UserKeyCursorFieldConverter.class) + public UserKey user_key; @ParcelableThisPlease @JsonField(name = "retweet_id") @CursorField(Statuses.RETWEET_ID) public long retweet_id = -1; @ParcelableThisPlease - @JsonField(name = "retweeted_by_user_id") - @CursorField(Statuses.RETWEETED_BY_USER_ID) - public long retweeted_by_user_id = -1; + @JsonField(name = "retweeted_by_user_id", typeConverter = UserKeyConverter.class) + @CursorField(value = Statuses.RETWEETED_BY_USER_ID, converter = UserKeyCursorFieldConverter.class) + public UserKey retweeted_by_user_id; @ParcelableThisPlease @JsonField(name = "retweet_timestamp") @CursorField(Statuses.RETWEET_TIMESTAMP) @@ -112,9 +104,9 @@ public class ParcelableStatus implements Parcelable, Comparable>> 32)); result = 31 * result + account_key.hashCode(); return result; @@ -363,7 +355,7 @@ public class ParcelableStatus implements Parcelable, Comparable { @CursorField(value = CachedUsers.EXTRAS, converter = LoganSquareCursorFieldConverter.class) public Extras extras; - @ParcelableThisPlease - @JsonField(name = "user_host") - @CursorField(value = CachedUsers.USER_HOST) - public String user_host; - public static final Creator CREATOR = new Creator() { public ParcelableUser createFromParcel(Parcel source) { ParcelableUser target = new ParcelableUser(); @@ -191,13 +187,13 @@ public class ParcelableUser implements Parcelable, Comparable { public ParcelableUser() { } - public ParcelableUser(final AccountKey account_key, final long id, final String name, - final String screen_name, final String profile_image_url) { + public ParcelableUser(final UserKey account_key, final UserKey key, final String name, + final String screenName, final String profileImageUrl) { this.account_key = account_key; - this.id = id; + this.key = key; this.name = name; - this.screen_name = screen_name; - this.profile_image_url = profile_image_url; + this.screen_name = screenName; + this.profile_image_url = profileImageUrl; is_cache = true; is_basic = true; } @@ -235,19 +231,19 @@ public class ParcelableUser implements Parcelable, Comparable { ParcelableUser user = (ParcelableUser) o; - if (id != user.id) return false; - return account_key.equals(user.account_key); + if (!account_key.equals(user.account_key)) return false; + return key.equals(user.key); } @Override public int hashCode() { - return calculateHashCode(account_key, id); + return calculateHashCode(account_key, key); } - public static int calculateHashCode(AccountKey account_key, long id) { - int result = account_key.hashCode(); - result = 31 * result + (int) (id ^ (id >>> 32)); + public static int calculateHashCode(UserKey accountKey, UserKey userKey) { + int result = accountKey.hashCode(); + result = 31 * result + userKey.hashCode(); return result; } @@ -256,7 +252,7 @@ public class ParcelableUser implements Parcelable, Comparable { return "ParcelableUser{" + "account_id=" + account_key + ", account_color=" + account_color + - ", id=" + id + + ", id=" + key + ", created_at=" + created_at + ", position=" + position + ", is_protected=" + is_protected + diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java index 18afca7ff..190a34279 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUserList.java @@ -28,31 +28,19 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; -import org.mariotaku.twidere.model.util.AccountKeyConverter; +import org.mariotaku.twidere.model.util.UserKeyConverter; @ParcelablePlease @JsonObject public class ParcelableUserList implements Parcelable, Comparable { @ParcelableThisPlease - @JsonField(name = "members_count") - public long members_count; - @ParcelableThisPlease - @JsonField(name = "subscribers_count") - public long subscribers_count; - @ParcelableThisPlease - @JsonField(name = "account_id", typeConverter = AccountKeyConverter.class) - public AccountKey account_key; + @JsonField(name = "account_id", typeConverter = UserKeyConverter.class) + public UserKey account_key; @ParcelableThisPlease @JsonField(name = "id") public long id; @ParcelableThisPlease - @JsonField(name = "user_id") - public long user_id; - @ParcelableThisPlease - @JsonField(name = "position") - public long position; - @ParcelableThisPlease @JsonField(name = "is_public") public boolean is_public; @ParcelableThisPlease @@ -64,6 +52,21 @@ public class ParcelableUserList implements Parcelable, Comparable>> 32); - return result; - } - - - @Override - public String toString() { - return "ParcelableUserMention{id=" + id + ", name=" + name + ", screen_name=" + screen_name + "}"; - } - - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeLong(id); - dest.writeString(name); - dest.writeString(screen_name); - } - - public static ParcelableUserMention[] fromUserMentionEntities(final UserMentionEntity[] entities) { - if (entities == null) return null; - final ParcelableUserMention[] mentions = new ParcelableUserMention[entities.length]; - for (int i = 0, j = entities.length; i < j; i++) { - mentions[i] = new ParcelableUserMention(entities[i]); + public static final Creator CREATOR = new Creator() { + public ParcelableUserMention createFromParcel(Parcel source) { + ParcelableUserMention target = new ParcelableUserMention(); + ParcelableUserMentionParcelablePlease.readFromParcel(target, source); + return target; } - return mentions; - } + public ParcelableUserMention[] newArray(int size) { + return new ParcelableUserMention[size]; + } + }; } 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/UserKey.java similarity index 72% rename from twidere.component.common/src/main/java/org/mariotaku/twidere/model/AccountKey.java rename to twidere.component.common/src/main/java/org/mariotaku/twidere/model/UserKey.java index 0fffc203d..877b938ad 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/UserKey.java @@ -19,17 +19,17 @@ import java.util.List; */ @JsonObject @ParcelablePlease -public class AccountKey implements Comparable, Parcelable { +public class UserKey implements Comparable, Parcelable { - public static final Creator CREATOR = new Creator() { - public AccountKey createFromParcel(Parcel source) { - AccountKey target = new AccountKey(); - AccountKeyParcelablePlease.readFromParcel(target, source); + public static final Creator CREATOR = new Creator() { + public UserKey createFromParcel(Parcel source) { + UserKey target = new UserKey(); + UserKeyParcelablePlease.readFromParcel(target, source); return target; } - public AccountKey[] newArray(int size) { - return new AccountKey[size]; + public UserKey[] newArray(int size) { + return new UserKey[size]; } }; @@ -40,12 +40,12 @@ public class AccountKey implements Comparable, Parcelable { @ParcelableThisPlease String host; - public AccountKey(long id, String host) { + public UserKey(long id, String host) { this.id = id; this.host = host; } - AccountKey() { + UserKey() { } @@ -64,7 +64,7 @@ public class AccountKey implements Comparable, Parcelable { } @Override - public int compareTo(@NonNull AccountKey another) { + public int compareTo(@NonNull UserKey another) { if (this.id == another.id) { if (this.host != null && another.host != null) { return this.host.compareTo(another.host); @@ -83,7 +83,7 @@ public class AccountKey implements Comparable, Parcelable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - AccountKey accountKey = (AccountKey) o; + UserKey accountKey = (UserKey) o; return id == accountKey.id; @@ -101,25 +101,25 @@ public class AccountKey implements Comparable, Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { - AccountKeyParcelablePlease.writeToParcel(this, dest, flags); + UserKeyParcelablePlease.writeToParcel(this, dest, flags); } - public boolean isAccount(long accountId, String accountHost) { + public boolean check(long accountId, String accountHost) { return this.id == accountId; } @Nullable - public static AccountKey valueOf(@Nullable String str) { + public static UserKey valueOf(@Nullable String str) { if (str == null) return null; int idxOfAt = str.indexOf("@"); try { if (idxOfAt != -1) { final String idStr = str.substring(0, idxOfAt); - return new AccountKey(Long.parseLong(idStr), + return new UserKey(Long.parseLong(idStr), str.substring(idxOfAt + 1, str.length())); } else { - return new AccountKey(Long.parseLong(str), null); + return new UserKey(Long.parseLong(str), null); } } catch (NumberFormatException e) { return null; @@ -127,10 +127,10 @@ public class AccountKey implements Comparable, Parcelable { } @Nullable - public static AccountKey[] arrayOf(@Nullable String str) { + public static UserKey[] arrayOf(@Nullable String str) { if (str == null) return null; List split = TwitterDateConverter.split(str, ","); - AccountKey[] keys = new AccountKey[split.size()]; + UserKey[] keys = new UserKey[split.size()]; for (int i = 0, splitLength = split.size(); i < splitLength; i++) { keys[i] = valueOf(split.get(i)); if (keys[i] == null) return null; @@ -138,11 +138,15 @@ public class AccountKey implements Comparable, Parcelable { return keys; } - public static long[] getIds(AccountKey[] ids) { + public static long[] getIds(UserKey[] ids) { long[] result = new long[ids.length]; for (int i = 0, idsLength = ids.length; i < idsLength; i++) { result[i] = ids[i].getId(); } return result; } + + public boolean maybeEquals(@Nullable UserKey another) { + return another != null && another.getId() == id; + } } 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 deleted file mode 100644 index 491605e05..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyConverter.java +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index b986ac5ee..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeyCursorFieldConverter.java +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index c6856066b..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/AccountKeysCursorFieldConverter.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.mariotaku.twidere.model.util; - -import org.mariotaku.twidere.model.AccountKey; - -/** - * Created by mariotaku on 16/3/7. - */ -public class AccountKeysCursorFieldConverter extends AbsObjectArrayConverter { - - @Override - protected AccountKey[] newArray(int size) { - return new AccountKey[size]; - } - - @Override - protected AccountKey parseItem(String s) { - return AccountKey.valueOf(s); - } -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyConverter.java new file mode 100644 index 000000000..3ebafa5c1 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyConverter.java @@ -0,0 +1,22 @@ +package org.mariotaku.twidere.model.util; + +import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter; + +import org.mariotaku.twidere.model.UserKey; + +/** + * Created by mariotaku on 16/3/7. + */ +public class UserKeyConverter extends StringBasedTypeConverter { + + @Override + public UserKey getFromString(String string) { + return UserKey.valueOf(string); + } + + @Override + public String convertToString(UserKey object) { + if (object == null) return null; + return object.toString(); + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyCursorFieldConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyCursorFieldConverter.java new file mode 100644 index 000000000..bc3540acf --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeyCursorFieldConverter.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.UserKey; + +import java.lang.reflect.ParameterizedType; + +/** + * Created by mariotaku on 16/3/7. + */ +public class UserKeyCursorFieldConverter implements CursorFieldConverter { + @Override + public UserKey parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) { + return UserKey.valueOf(cursor.getString(columnIndex)); + } + + @Override + public void writeField(ContentValues values, UserKey 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/UserKeysCursorFieldConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeysCursorFieldConverter.java new file mode 100644 index 000000000..dd7ff7dbe --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/util/UserKeysCursorFieldConverter.java @@ -0,0 +1,19 @@ +package org.mariotaku.twidere.model.util; + +import org.mariotaku.twidere.model.UserKey; + +/** + * Created by mariotaku on 16/3/7. + */ +public class UserKeysCursorFieldConverter extends AbsObjectArrayConverter { + + @Override + protected UserKey[] newArray(int size) { + return new UserKey[size]; + } + + @Override + protected UserKey parseItem(String s) { + return UserKey.valueOf(s); + } +} 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 4fc2faf95..aefb5c5c6 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 @@ -237,7 +237,7 @@ public interface TwidereDataStore { Uri CONTENT_URI_WITH_SCORE = Uri.withAppendedPath(BASE_CONTENT_URI, CONTENT_PATH_WITH_SCORE); - String USER_ID = "user_id"; + String USER_KEY = "user_id"; String CREATED_AT = "created_at"; @@ -300,13 +300,13 @@ public interface TwidereDataStore { String USER_HOST = "user_host"; - String[] COLUMNS = {_ID, USER_ID, CREATED_AT, NAME, SCREEN_NAME, DESCRIPTION_PLAIN, LOCATION, + String[] COLUMNS = {_ID, USER_KEY, CREATED_AT, NAME, SCREEN_NAME, DESCRIPTION_PLAIN, LOCATION, URL, PROFILE_IMAGE_URL, PROFILE_BANNER_URL, IS_PROTECTED, IS_VERIFIED, IS_FOLLOWING, FOLLOWERS_COUNT, FRIENDS_COUNT, STATUSES_COUNT, FAVORITES_COUNT, LISTED_COUNT, MEDIA_COUNT, DESCRIPTION_HTML, DESCRIPTION_EXPANDED, URL_EXPANDED, BACKGROUND_COLOR, LINK_COLOR, TEXT_COLOR, LAST_SEEN, DESCRIPTION_UNESCAPED, EXTRAS, USER_HOST}; - String[] BASIC_COLUMNS = {_ID, USER_ID, NAME, SCREEN_NAME, PROFILE_IMAGE_URL}; + String[] BASIC_COLUMNS = {_ID, USER_KEY, NAME, SCREEN_NAME, PROFILE_IMAGE_URL}; String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_BOOLEAN, TYPE_BOOLEAN, @@ -639,7 +639,7 @@ public interface TwidereDataStore { String[] COLUMNS = {_ID, USER_ID, NAME, SCREEN_NAME}; - String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_INT_UNIQUE, TYPE_TEXT_NOT_NULL, + String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL}; } } @@ -857,7 +857,7 @@ public interface TwidereDataStore { String QUOTED_MEDIA_JSON = "quoted_media_json"; String QUOTED_TIMESTAMP = "quoted_timestamp"; String QUOTED_SOURCE = "quoted_source"; - String QUOTED_USER_ID = "quoted_user_id"; + String QUOTED_USER_KEY = "quoted_user_id"; String QUOTED_USER_NAME = "quoted_user_name"; String QUOTED_USER_SCREEN_NAME = "quoted_user_screen_name"; String QUOTED_USER_PROFILE_IMAGE = "quoted_user_profile_image"; @@ -876,7 +876,7 @@ public interface TwidereDataStore { IN_REPLY_TO_USER_SCREEN_NAME, SOURCE, LOCATION, RETWEET_COUNT, FAVORITE_COUNT, REPLY_COUNT, RETWEET_ID, RETWEET_TIMESTAMP, RETWEETED_BY_USER_ID, RETWEETED_BY_USER_NAME, RETWEETED_BY_USER_SCREEN_NAME, RETWEETED_BY_USER_PROFILE_IMAGE, QUOTED_ID, QUOTED_TEXT_HTML, - QUOTED_TEXT_PLAIN, QUOTED_TEXT_UNESCAPED, QUOTED_TIMESTAMP, QUOTED_SOURCE, QUOTED_USER_ID, + QUOTED_TEXT_PLAIN, QUOTED_TEXT_UNESCAPED, QUOTED_TIMESTAMP, QUOTED_SOURCE, QUOTED_USER_KEY, QUOTED_USER_NAME, QUOTED_USER_SCREEN_NAME, QUOTED_USER_PROFILE_IMAGE, QUOTED_USER_IS_VERIFIED, QUOTED_USER_IS_PROTECTED, MY_RETWEET_ID, IS_RETWEET, IS_QUOTE, IS_FAVORITE, IS_PROTECTED, IS_VERIFIED, IS_FOLLOWING, IS_GAP, diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java index 47e3116e0..2327c3c08 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java @@ -40,18 +40,6 @@ public class TwitterContentUtils { public static final int TWITTER_BULK_QUERY_COUNT = 100; - @NonNull - public static String getInReplyToName(@NonNull final Status status) { - final Status orig = status.isRetweet() ? status.getRetweetedStatus() : status; - final long inReplyToUserId = status.getInReplyToUserId(); - final UserMentionEntity[] entities = status.getUserMentionEntities(); - if (entities == null) return orig.getInReplyToScreenName(); - for (final UserMentionEntity entity : entities) { - if (inReplyToUserId == entity.getId()) return entity.getName(); - } - return orig.getInReplyToScreenName(); - } - public static boolean isOfficialKey(final Context context, final String consumerKey, final String consumerSecret) { if (context == null || consumerKey == null || consumerSecret == null) return false; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/content/ContentValuesUtils.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/content/ContentValuesUtils.java deleted file mode 100644 index f51e3ad16..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/content/ContentValuesUtils.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.util.content; - -import android.content.ContentValues; - -public class ContentValuesUtils { - - public static boolean getAsBoolean(final ContentValues values, final String key, final boolean def) { - if (values == null || key == null) return def; - final Object value = values.get(key); - if (value == null) return def; - return Boolean.valueOf(value.toString()); - } - - public static long getAsInteger(final ContentValues values, final String key, final int def) { - if (values == null || key == null) return def; - final Object value = values.get(key); - if (value == null) return def; - return Integer.valueOf(value.toString()); - } - - public static long getAsLong(final ContentValues values, final String key, final long def) { - if (values == null || key == null) return def; - final Object value = values.get(key); - if (value == null) return def; - return Long.valueOf(value.toString()); - } -} 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 e15312f55..fde052087 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,8 +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.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.StatusShortenResult; @@ -35,7 +34,7 @@ import org.mariotaku.twidere.service.StatusShortenerService; public class GistStatusShortenerService extends StatusShortenerService { @Override - protected StatusShortenResult shorten(ParcelableStatusUpdate status, AccountKey currentAccountKey, String overrideStatusText) { + protected StatusShortenResult shorten(ParcelableStatusUpdate status, UserKey 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 e91f6c4b2..cd857eca6 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,7 +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.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; @@ -31,7 +31,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp */ @Override protected StatusShortenResult shorten(final ParcelableStatusUpdate status, - final AccountKey currentAccountKey, + final UserKey currentAccountKey, final String overrideStatusText) { final int granted = Twidere.isPermissionGranted(this); if (granted == Twidere.Permission.DENIED) { @@ -119,7 +119,7 @@ public class TwitLongerStatusShortenerService extends StatusShortenerService imp } @Nullable - private ParcelableCredentials getOAuthCredentials(AccountKey accountId) { + private ParcelableCredentials getOAuthCredentials(UserKey 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 d6cfd9fc0..e3da7d477 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,7 +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.UserKey; import org.mariotaku.twidere.model.ComposingStatus; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices; @@ -234,7 +234,7 @@ public final class Twidere implements TwidereConstants { @Nullable public static ParcelableCredentials getCredentials(@NonNull final Context context, - @NonNull final AccountKey accountId) + @NonNull final UserKey accountId) throws SecurityException { final String selection = Accounts.ACCOUNT_KEY + " = ?"; final String[] selectionArgs = {String.valueOf(accountId)}; 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 a26d8e84f..310d7ea18 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,7 +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.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.StatusShortenResult; @@ -29,7 +29,7 @@ public abstract class StatusShortenerService extends Service { } protected abstract StatusShortenResult shorten(ParcelableStatusUpdate status, - AccountKey currentAccountKey, + UserKey currentAccountKey, String overrideStatusText); protected abstract boolean callback(StatusShortenResult result, ParcelableStatus status); @@ -54,7 +54,7 @@ public abstract class StatusShortenerService extends Service { try { final ParcelableStatusUpdate statusUpdate = LoganSquareMapperFinder.mapperFor(ParcelableStatusUpdate.class) .parse(statusJson); - final AccountKey currentAccountId = AccountKey.valueOf(currentAccountIdStr); + final UserKey currentAccountId = UserKey.valueOf(currentAccountIdStr); final StatusShortenResult shorten = mService.get().shorten(statusUpdate, currentAccountId, overrideStatusText); return LoganSquareMapperFinder.mapperFor(StatusShortenResult.class).serialize(shorten); diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/HotMobiLogger.java b/twidere/src/main/java/edu/tsinghua/hotmobi/HotMobiLogger.java index d4ca8e3e5..0c8dd9c9b 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/HotMobiLogger.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/HotMobiLogger.java @@ -28,7 +28,7 @@ import android.util.Log; import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.dagger.DependencyHolder; import java.io.File; @@ -91,7 +91,7 @@ public class HotMobiLogger implements HotMobiConstants { return DependencyHolder.get(context).getHotMobiLogger(); } - public static File getLogFile(Context context, @Nullable AccountKey accountKey, String type) { + public static File getLogFile(Context context, @Nullable UserKey accountKey, String type) { final File logsDir = getLogsDir(context); final File todayLogDir = new File(logsDir, DATE_FORMAT.format(new Date())); if (!todayLogDir.exists()) { @@ -127,11 +127,11 @@ public class HotMobiLogger implements HotMobiConstants { return false; } - public void log(AccountKey accountId, final T event, final PreProcessing preProcessing) { + public void log(UserKey accountId, final T event, final PreProcessing preProcessing) { mExecutor.execute(new WriteLogTask<>(mApplication, accountId, event, preProcessing)); } - public void log(AccountKey accountId, final T event) { + public void log(UserKey accountId, final T event) { log(accountId, event, null); } @@ -143,11 +143,11 @@ public class HotMobiLogger implements HotMobiConstants { log(null, event, preProcessing); } - public void logList(List events, AccountKey accountId, String type) { + public void logList(List events, UserKey accountId, String type) { logList(events, accountId, type, null); } - public void logList(List events, AccountKey accountId, String type, final PreProcessing preProcessing) { + public void logList(List events, UserKey accountId, String type, final PreProcessing preProcessing) { mExecutor.execute(new WriteLogTask<>(mApplication, accountId, type, events, preProcessing)); } diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/WriteLogTask.java b/twidere/src/main/java/edu/tsinghua/hotmobi/WriteLogTask.java index 36846bbc8..95e860e2b 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/WriteLogTask.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/WriteLogTask.java @@ -27,7 +27,7 @@ import android.util.Log; import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.JsonSerializer; import org.mariotaku.twidere.util.Utils; @@ -49,17 +49,17 @@ public class WriteLogTask implements Runnable, Constants { private static final byte[] LF = {'\n'}; private final Context context; - private final AccountKey accountKey; + private final UserKey accountKey; private final String type; private final List events; @Nullable private final PreProcessing preProcessing; - public WriteLogTask(Context context, AccountKey accountKey, T event, @Nullable PreProcessing preProcessing) { + public WriteLogTask(Context context, UserKey accountKey, T event, @Nullable PreProcessing preProcessing) { this(context, accountKey, HotMobiLogger.getLogFilename(event), Collections.singletonList(event), preProcessing); } - public WriteLogTask(Context context, AccountKey accountKey, String type, List events, + public WriteLogTask(Context context, UserKey accountKey, String type, List events, @Nullable PreProcessing preProcessing) { this.context = context; this.accountKey = accountKey; diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/MediaEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/MediaEvent.java index ee7733785..8b6aa100e 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/MediaEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/MediaEvent.java @@ -76,7 +76,7 @@ public class MediaEvent extends BaseEvent implements Parcelable { final MediaEvent event = new MediaEvent(); event.markStart(context); event.setId(status.id); - event.setUserId(status.user_id); + event.setUserId(status.user_key.getId()); event.setMediaUrl(media.media_url); event.setPreviewUrl(media.preview_url); event.setPreviewEnabled(previewEnabled); diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/NotificationEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/NotificationEvent.java index 02761b3bb..1753e3667 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/NotificationEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/NotificationEvent.java @@ -31,7 +31,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import java.util.TimeZone; @@ -94,7 +94,7 @@ public class NotificationEvent extends BaseEvent implements Parcelable { } public static NotificationEvent deleted(Context context, long postTime, String type, - AccountKey accountKey, long itemId, long itemUserId, + UserKey accountKey, long itemId, long itemUserId, boolean itemUserFollowing) { return create(context, Action.DELETE, System.currentTimeMillis(), postTime, type, accountKey.getId(), itemId, itemUserId, itemUserFollowing); 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 415018d78..0eea6ffbe 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/ScrollRecord.java @@ -24,7 +24,7 @@ import android.support.annotation.NonNull; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 15/8/8. @@ -44,7 +44,7 @@ public class ScrollRecord implements LogModel { @JsonField(name = "scroll_state") int scrollState; - public static ScrollRecord create(long id, AccountKey accountKey, long timestamp, long timeOffset, int scrollState) { + public static ScrollRecord create(long id, UserKey accountKey, long timestamp, long timeOffset, int scrollState) { final ScrollRecord record = new ScrollRecord(); record.setId(id); record.setAccountId(accountKey.getId()); diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/model/SessionEvent.java b/twidere/src/main/java/edu/tsinghua/hotmobi/model/SessionEvent.java index 21b39fe8e..eada195fc 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/SessionEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/SessionEvent.java @@ -32,7 +32,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.util.DataStoreUtils; @@ -98,7 +98,7 @@ public class SessionEvent extends BaseEvent implements Parcelable { public void dumpPreferences(Context context) { final HashMap preferences = new HashMap<>(); for (AccountPreferences pref : AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context))) { - final AccountKey accountKey = pref.getAccountKey(); + final UserKey accountKey = pref.getAccountKey(); preferences.put("notification_" + accountKey + "_home", String.valueOf(pref.isHomeTimelineNotificationEnabled())); preferences.put("notification_" + accountKey + "_interactions", String.valueOf(pref.isInteractionsNotificationEnabled())); } 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 313f49979..1c2de7277 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/TweetEvent.java @@ -85,7 +85,7 @@ public class TweetEvent extends BaseEvent implements Parcelable { event.setId(status.id); event.setAccountId(status.account_key.getId()); event.setAccountHost(status.account_key.getHost()); - event.setUserId(status.user_id); + event.setUserId(status.user_key.getId()); event.setTimelineType(timelineType); event.setTweetType(TwidereDataUtils.getTweetType(status)); event.setFollowing(status.user_is_following); 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 39aaa5376..da79464f8 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/model/UserEvent.java @@ -31,6 +31,9 @@ public class UserEvent extends BaseEvent implements Parcelable { @JsonField(name = "user_id") long userId; @ParcelableThisPlease + @JsonField(name = "user_host") + String userHost; + @ParcelableThisPlease @JsonField(name = "status_count") long statusCount; @ParcelableThisPlease @@ -66,7 +69,8 @@ public class UserEvent extends BaseEvent implements Parcelable { public void setUser(@NonNull ParcelableUser user) { accountId = user.account_key.getId(); accountHost = user.account_key.getHost(); - userId = user.id; + userId = user.key.getId(); + userHost = user.key.toString(); statusCount = user.statuses_count; followerCount = user.followers_count; friendCount = user.friends_count; diff --git a/twidere/src/main/java/org/mariotaku/twidere/Constants.java b/twidere/src/main/java/org/mariotaku/twidere/Constants.java index 586709297..d0197707f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/Constants.java +++ b/twidere/src/main/java/org/mariotaku/twidere/Constants.java @@ -33,7 +33,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING; public interface Constants extends TwidereConstants { String DATABASES_NAME = "twidere.sqlite"; - int DATABASES_VERSION = 130; + int DATABASES_VERSION = 131; int MENU_GROUP_STATUS_EXTENSION = 10; int MENU_GROUP_COMPOSE_EXTENSION = 11; 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 02e076836..13ae3031c 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 @@ -103,7 +103,6 @@ import org.mariotaku.twidere.adapter.ArrayRecyclerAdapter; import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter; import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment; import org.mariotaku.twidere.fragment.support.SupportProgressDialogFragment; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ConsumerKeyType; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.DraftValuesCreator; @@ -115,6 +114,7 @@ import org.mariotaku.twidere.model.ParcelableMediaUpdate; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra; import org.mariotaku.twidere.model.util.ParcelableAccountUtils; import org.mariotaku.twidere.preference.ServicePickerPreference; @@ -442,12 +442,12 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte try { final String action = intent.getAction(); if (INTENT_ACTION_EXTENSION_COMPOSE.equals(action)) { - final AccountKey[] accountKeys = mAccountsAdapter.getSelectedAccountKeys(); + final UserKey[] accountKeys = mAccountsAdapter.getSelectedAccountKeys(); intent.putExtra(EXTRA_TEXT, ParseUtils.parseString(mEditText.getText())); - intent.putExtra(EXTRA_ACCOUNT_IDS, AccountKey.getIds(accountKeys)); + intent.putExtra(EXTRA_ACCOUNT_IDS, UserKey.getIds(accountKeys)); intent.putExtra(EXTRA_ACCOUNT_KEYS, accountKeys); if (accountKeys.length > 0) { - final AccountKey accountKey = accountKeys[0]; + final UserKey accountKey = accountKeys[0]; intent.putExtra(EXTRA_NAME, DataStoreUtils.getAccountName(this, accountKey)); intent.putExtra(EXTRA_SCREEN_NAME, DataStoreUtils.getAccountScreenName(this, accountKey)); } @@ -628,7 +628,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte finish(); return; } - final AccountKey[] defaultAccountIds = ParcelableAccountUtils.getAccountKeys(accounts); + final UserKey[] defaultAccountIds = ParcelableAccountUtils.getAccountKeys(accounts); mMenuBar.setOnMenuItemClickListener(this); setupEditText(); mAccountSelectorContainer.setOnClickListener(this); @@ -660,7 +660,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte if (savedInstanceState != null) { // Restore from previous saved state mAccountsAdapter.setSelectedAccountIds(Utils.newParcelableArray( - savedInstanceState.getParcelableArray(EXTRA_ACCOUNT_KEY), AccountKey.CREATOR)); + savedInstanceState.getParcelableArray(EXTRA_ACCOUNT_KEY), UserKey.CREATOR)); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList mediaList = savedInstanceState.getParcelableArrayList(EXTRA_MEDIA); if (mediaList != null) { @@ -675,7 +675,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } else { // The context was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); - final AccountKey notificationAccount = intent.getParcelableExtra(EXTRA_NOTIFICATION_ACCOUNT); + final UserKey notificationAccount = intent.getParcelableExtra(EXTRA_NOTIFICATION_ACCOUNT); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } @@ -683,10 +683,10 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte handleDefaultIntent(intent); } setLabel(intent); - final AccountKey[] selectedAccountIds = mAccountsAdapter.getSelectedAccountKeys(); + final UserKey[] selectedAccountIds = mAccountsAdapter.getSelectedAccountKeys(); if (ArrayUtils.isEmpty(selectedAccountIds)) { - final AccountKey[] idsInPrefs = AccountKey.arrayOf(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null)); - AccountKey[] intersection = null; + final UserKey[] idsInPrefs = UserKey.arrayOf(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null)); + UserKey[] intersection = null; if (idsInPrefs != null) { intersection = TwidereArrayUtils.intersection(idsInPrefs, defaultAccountIds); } @@ -872,12 +872,12 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte final String action = intent.getAction(); final boolean hasAccountIds; if (intent.hasExtra(EXTRA_ACCOUNT_KEYS)) { - final AccountKey[] accountKeys = Utils.newParcelableArray( - intent.getParcelableArrayExtra(EXTRA_ACCOUNT_KEYS), AccountKey.CREATOR); + final UserKey[] accountKeys = Utils.newParcelableArray( + intent.getParcelableArrayExtra(EXTRA_ACCOUNT_KEYS), UserKey.CREATOR); mAccountsAdapter.setSelectedAccountIds(accountKeys); hasAccountIds = true; } else if (intent.hasExtra(EXTRA_ACCOUNT_KEY)) { - final AccountKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); mAccountsAdapter.setSelectedAccountIds(accountKey); hasAccountIds = true; } else { @@ -1006,7 +1006,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } case INTENT_ACTION_REPLY_MULTIPLE: { final String[] screenNames = intent.getStringArrayExtra(EXTRA_SCREEN_NAMES); - final AccountKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEYS); + final UserKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEYS); final ParcelableStatus inReplyToStatus = intent.getParcelableExtra(EXTRA_IN_REPLY_TO_STATUS); return handleReplyMultipleIntent(screenNames, accountKey, inReplyToStatus); } @@ -1022,7 +1022,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } private boolean handleMentionIntent(final ParcelableUser user) { - if (user == null || user.id <= 0) return false; + if (user == null || user.key == null) return false; final String accountScreenName = DataStoreUtils.getAccountScreenName(this, user.account_key); if (TextUtils.isEmpty(accountScreenName)) return false; mEditText.setText(String.format("@%s ", user.screen_name)); @@ -1075,7 +1075,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte 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_key.getId() != status.user_id) { + if (!status.account_key.equals(status.user_key)) { selectionStart = mEditText.length(); } if (status.is_retweet) { @@ -1102,7 +1102,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte return true; } - private boolean handleReplyMultipleIntent(final String[] screenNames, final AccountKey accountId, + private boolean handleReplyMultipleIntent(final String[] screenNames, final UserKey accountId, final ParcelableStatus inReplyToStatus) { if (screenNames == null || screenNames.length == 0 || accountId == null) return false; final String myScreenName = DataStoreUtils.getAccountScreenName(this, accountId); @@ -1130,7 +1130,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte private boolean isQuotingProtectedStatus() { final ParcelableStatus status = mInReplyToStatus; if (!isQuote() || status == null) return false; - return status.user_is_protected && status.account_key.getId() != status.user_id; + return status.user_is_protected && !status.account_key.equals(status.user_key); } private boolean noReplyContent(final String text) { @@ -1338,7 +1338,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte return; } final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false); - final AccountKey[] accountKeys = mAccountsAdapter.getSelectedAccountKeys(); + final UserKey[] accountKeys = mAccountsAdapter.getSelectedAccountKeys(); final ParcelableLocation statusLocation = attachLocation ? mRecentLocation : null; final boolean isPossiblySensitive = hasMedia && mIsPossiblySensitive; final ParcelableStatusUpdate update = new ParcelableStatusUpdate(); @@ -1480,7 +1480,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte private final ComposeActivity mActivity; private final LayoutInflater mInflater; - private final Map mSelection; + private final Map mSelection; private final boolean mNameFirst; private ParcelableCredentials[] mAccounts; @@ -1504,24 +1504,24 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte } @NonNull - public AccountKey[] getSelectedAccountKeys() { - if (mAccounts == null) return new AccountKey[0]; - final AccountKey[] temp = new AccountKey[mAccounts.length]; + public UserKey[] getSelectedAccountKeys() { + if (mAccounts == null) return new UserKey[0]; + final UserKey[] temp = new UserKey[mAccounts.length]; int selectedCount = 0; for (ParcelableAccount account : mAccounts) { if (Boolean.TRUE.equals(mSelection.get(account.account_key))) { temp[selectedCount++] = account.account_key; } } - final AccountKey[] result = new AccountKey[selectedCount]; + final UserKey[] result = new UserKey[selectedCount]; System.arraycopy(temp, 0, result, 0, result.length); return result; } - public void setSelectedAccountIds(AccountKey... accountKeys) { + public void setSelectedAccountIds(UserKey... accountKeys) { mSelection.clear(); if (accountKeys != null) { - for (AccountKey accountKey : accountKeys) { + for (UserKey accountKey : accountKeys) { mSelection.put(accountKey, true); } } 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 195d5f47d..f38378006 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 @@ -50,7 +50,7 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter; import org.mariotaku.twidere.adapter.ArrayAdapter; import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.CustomTabConfiguration; import org.mariotaku.twidere.model.CustomTabConfiguration.ExtraConfiguration; import org.mariotaku.twidere.model.ParcelableAccount; @@ -223,7 +223,7 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement icon.setVisibility(displayProfileImage ? View.VISIBLE : View.GONE); if (value instanceof ParcelableUser) { final ParcelableUser user = (ParcelableUser) value; - text1.setText(mUserColorNameManager.getUserNickname(user.id, user.name, false)); + text1.setText(mUserColorNameManager.getUserNickname(user.key, user.name, false)); text2.setText("@" + user.screen_name); if (displayProfileImage) { mImageLoader.displayProfileImage(icon, user); @@ -372,14 +372,14 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement if (value == null || args == null || conf == null) return; if (value instanceof ParcelableUser) { final ParcelableUser user = (ParcelableUser) value; - args.putLong(EXTRA_USER_ID, user.id); + args.putLong(EXTRA_USER_ID, user.key.getId()); args.putString(EXTRA_SCREEN_NAME, user.screen_name); args.putString(EXTRA_NAME, user.name); } else if (value instanceof ParcelableUserList) { final ParcelableUserList user_list = (ParcelableUserList) value; args.putLong(EXTRA_LIST_ID, user_list.id); args.putString(EXTRA_LIST_NAME, user_list.name); - args.putLong(EXTRA_USER_ID, user_list.user_id); + args.putLong(EXTRA_USER_ID, user_list.user_key.getId()); args.putString(EXTRA_SCREEN_NAME, user_list.user_screen_name); } else if (value instanceof CharSequence) { final String key = conf.getSecondaryFieldTextKey(); @@ -392,7 +392,7 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement addFieldValueToArguments(value, args); } - private AccountKey getAccountKey() { + private UserKey getAccountKey() { final int pos = mAccountSpinner.getSelectedItemPosition(); if (mAccountSpinner.getCount() > pos && pos >= 0) { ParcelableCredentials credentials = mAccountsAdapter.getItem(pos); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java index 0b7c8d961..1817f865c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java @@ -75,7 +75,7 @@ import org.mariotaku.twidere.fragment.support.AccountsDashboardFragment; import org.mariotaku.twidere.fragment.support.DirectMessagesFragment; import org.mariotaku.twidere.fragment.support.TrendsSuggestionsFragment; import org.mariotaku.twidere.graphic.EmptyDrawable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.SupportTabSpec; import org.mariotaku.twidere.model.message.TaskStateChangedEvent; @@ -150,7 +150,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen } @NonNull - public AccountKey[] getActivatedAccountKeys() { + public UserKey[] getActivatedAccountKeys() { final Fragment fragment = getLeftDrawerFragment(); if (fragment instanceof AccountsDashboardFragment) { return ((AccountsDashboardFragment) fragment).getActivatedAccountIds(); @@ -673,7 +673,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen if (Intent.ACTION_SEARCH.equals(action)) { final String query = intent.getStringExtra(SearchManager.QUERY); final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA); - final AccountKey accountKey; + final UserKey accountKey; if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_KEY)) { accountKey = appSearchData.getParcelable(EXTRA_ACCOUNT_KEY); } else { @@ -692,7 +692,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen final String tabType = uri != null ? Utils.matchTabType(uri) : null; int initialTab = -1; if (tabType != null) { - final AccountKey accountId = AccountKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); + final UserKey accountId = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); for (int i = 0, j = mPagerAdapter.getCount(); i < j; i++) { final SupportTabSpec tab = mPagerAdapter.getTab(i); if (tabType.equals(CustomTabUtils.getTabTypeAlias(tab.type))) { @@ -924,7 +924,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen } switch (spec.type) { case CustomTabType.HOME_TIMELINE: { - final AccountKey[] accountKeys = Utils.getAccountKeys(mContext, spec.args); + final UserKey[] accountKeys = Utils.getAccountKeys(mContext, spec.args); final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(mContext, true, ReadPositionTag.HOME_TIMELINE, accountKeys); final long position = mReadStateManager.getPosition(tagWithAccounts); @@ -935,7 +935,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen break; } case CustomTabType.NOTIFICATIONS_TIMELINE: { - final AccountKey[] accountIds = Utils.getAccountKeys(mContext, spec.args); + final UserKey[] accountIds = Utils.getAccountKeys(mContext, spec.args); final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(mContext, true, ReadPositionTag.ACTIVITIES_ABOUT_ME, accountIds); final long position = mReadStateManager.getPosition(tagWithAccounts); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java index 6d0883778..913ed0867 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java @@ -81,7 +81,7 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IExtendedActivity; import org.mariotaku.twidere.fragment.ProgressDialogFragment; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.provider.CacheProvider; @@ -825,7 +825,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements @Override protected Object getDownloadExtra() { final MediaExtra mediaExtra = new MediaExtra(); - mediaExtra.setAccountKey(getArguments().getParcelable(EXTRA_ACCOUNT_KEY)); + mediaExtra.setAccountKey(getArguments().getParcelable(EXTRA_ACCOUNT_KEY)); final Uri origDownloadUri = super.getDownloadUri(); final Uri downloadUri = getDownloadUri(); if (origDownloadUri != null && downloadUri != 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 a58366147..f4442d07e 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 @@ -56,9 +56,9 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter; import org.mariotaku.twidere.fragment.support.UserFragment; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory; import org.mariotaku.twidere.provider.TwidereDataStore.Suggestions; import org.mariotaku.twidere.util.DataStoreUtils; @@ -112,7 +112,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On mUsersSearchAdapter.addRemovedPositions(reverseSortedPositions); final ContentResolver cr = getContentResolver(); ContentResolverUtils.bulkDelete(cr, SearchHistory.CONTENT_URI, SearchHistory._ID, ids, - null, false); + null); getSupportLoaderManager().restartLoader(0, null, this); } @@ -143,7 +143,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On @Override public Loader onCreateLoader(int id, Bundle args) { - final AccountKey accountId = getSelectedAccountKey(); + final UserKey accountId = getSelectedAccountKey(); final Uri.Builder builder = Suggestions.Search.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_QUERY, ParseUtils.parseString(mSearchQuery.getText())); if (accountId != null) { @@ -229,7 +229,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On mAccountSpinner.setOnItemSelectedListener(this); if (savedInstanceState == null) { final Intent intent = getIntent(); - final AccountKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); final int index = accountsSpinnerAdapter.findItemPosition(System.identityHashCode(accountKey)); if (index != -1) { mAccountSpinner.setSelection(index); @@ -292,7 +292,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On finish(); } - private AccountKey getSelectedAccountKey() { + private UserKey getSelectedAccountKey() { final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem(); if (account == null) return null; return account.account_key; @@ -400,7 +400,9 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On } case VIEW_TYPE_USER_SUGGESTION_ITEM: { final UserViewHolder holder = (UserViewHolder) view.getTag(); - holder.text1.setText(mUserColorNameManager.getUserNickname(cursor.getLong(mIndices.extra_id), + final UserKey userKey = UserKey.valueOf(cursor.getString(mIndices.extra_id)); + assert userKey != null; + holder.text1.setText(mUserColorNameManager.getUserNickname(userKey, cursor.getString(mIndices.title), false)); holder.text2.setVisibility(View.VISIBLE); holder.text2.setText(String.format("@%s", cursor.getString(mIndices.summary))); 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 0c3ee33e8..13bbb1633 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 @@ -84,11 +84,12 @@ import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment; import org.mariotaku.twidere.fragment.support.SupportProgressDialogFragment; import org.mariotaku.twidere.graphic.EmptyDrawable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.StatusNetAccountExtra; import org.mariotaku.twidere.model.TwitterAccountExtra; +import org.mariotaku.twidere.model.util.UserKeyUtils; import org.mariotaku.twidere.model.util.ParcelableUserUtils; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.util.AsyncTaskUtils; @@ -231,7 +232,7 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case android.R.id.home: { - final AccountKey[] accountKeys = getActivatedAccountKeys(this); + final UserKey[] accountKeys = getActivatedAccountKeys(this); if (accountKeys.length > 0) { onBackPressed(); } @@ -1094,8 +1095,8 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList 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 UserKey accountKey = new UserKey(user.getId(), + UserKeyUtils.getUserHost(user.getOstatusUri())); final ParcelableUser parcelableUser = ParcelableUserUtils.fromUser(user, accountKey); values.put(Accounts.ACCOUNT_USER, JsonSerializer.serialize(parcelableUser, ParcelableUser.class)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java index ee215941a..15d708fc0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/UserListSelectorActivity.java @@ -48,7 +48,7 @@ import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.fragment.support.CreateUserListDialogFragment; import org.mariotaku.twidere.fragment.support.SupportProgressDialogFragment; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.SingleResponse; @@ -203,7 +203,7 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen getUserLists(mScreenName); } - private AccountKey getAccountKey() { + private UserKey getAccountKey() { return getIntent().getParcelableExtra(EXTRA_ACCOUNT_KEY); } @@ -280,10 +280,10 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen private static final String FRAGMENT_TAG_GET_USER_LISTS = "get_user_lists"; private final UserListSelectorActivity mActivity; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final String mScreenName; - GetUserListsTask(final UserListSelectorActivity activity, final AccountKey accountKey, + GetUserListsTask(final UserListSelectorActivity activity, final UserKey accountKey, final String screenName) { mActivity = activity; mAccountKey = accountKey; @@ -344,10 +344,10 @@ public class UserListSelectorActivity extends BaseSupportDialogActivity implemen private static final String FRAGMENT_TAG_SEARCH_USERS = "search_users"; private final UserListSelectorActivity mActivity; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final String mName; - SearchUsersTask(final UserListSelectorActivity activity, final AccountKey accountKey, + SearchUsersTask(final UserListSelectorActivity activity, final UserKey accountKey, final String name) { mActivity = activity; mAccountKey = accountKey; 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 d39de6cb2..998fdb6b5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java @@ -438,7 +438,7 @@ public abstract class AbsActivitiesAdapter extends LoadMoreSupportAdapter< final ParcelableActivity activity = adapter.getActivity(position); final ParcelableStatus status = ParcelableActivityUtils.getActivityStatus(activity); assert status != null; - IntentUtils.openUserProfile(context, status.account_key, status.user_id, + IntentUtils.openUserProfile(context, status.account_key, status.user_key.getId(), status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } 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 9d8c6759e..5783f1a19 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsParcelableStatusesAdapter.java @@ -24,7 +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.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusCursorIndices; @@ -66,7 +66,7 @@ public abstract class AbsParcelableStatusesAdapter extends AbsStatusesAdapter
  • = getStatusCount()) return null; if (mData instanceof ObjectCursor) { final Cursor cursor = ((ObjectCursor) mData).getCursor(dataPosition); final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData).getIndices(); - return AccountKey.valueOf(cursor.getString(indices.account_key)); + return UserKey.valueOf(cursor.getString(indices.account_key)); } return mData.get(dataPosition).account_key; } 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 000b8d26d..756e4301f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java @@ -12,7 +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.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.MediaLoadingHandler; @@ -283,7 +283,7 @@ public abstract class AbsStatusesAdapter extends LoadMoreSupportAdapter, @Override @Nullable - public AccountKey getAccountKey(int position) { + public UserKey getAccountKey(int position) { return null; } @Nullable @Override - public ParcelableStatus findStatusById(AccountKey accountId, long statusId) { + public ParcelableStatus findStatusById(UserKey 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 5c5fe2867..99ac0b228 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java @@ -29,7 +29,7 @@ import android.view.ViewGroup; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IDirectMessagesAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices; import org.mariotaku.twidere.model.ParcelableMedia; @@ -168,7 +168,7 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter im public static class DirectMessageEntry { - public final AccountKey account_key; + public final UserKey account_key; public final long conversation_id; public final String screen_name, name; DirectMessageEntry(Cursor cursor) { - account_key = AccountKey.valueOf(cursor.getString(ConversationEntries.IDX_ACCOUNT_KEY)); + account_key = UserKey.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 7ce704adf..69e84c40a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java @@ -25,7 +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.UserKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityCursorIndices; import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder; @@ -59,7 +59,7 @@ public class ParcelableActivitiesAdapter extends AbsActivitiesAdapter @Override public long getUserId(int position) { if (position == getUserCount()) return -1; - return mData.get(position).id; + return mData.get(position).key.getId(); } @Override @@ -103,11 +103,11 @@ public class ParcelableUsersAdapter extends AbsUsersAdapter return true; } - public int findPosition(AccountKey accountKey, long userId) { + public int findPosition(UserKey accountKey, 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_key.equals(accountKey) && user.id == userId) { + if (user.account_key.equals(accountKey) && user.key.getId() == userId) { return i; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/SimpleParcelableUsersAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/SimpleParcelableUsersAdapter.java index f30a758e0..e5e55a58f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/SimpleParcelableUsersAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/SimpleParcelableUsersAdapter.java @@ -35,21 +35,18 @@ import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes; public class SimpleParcelableUsersAdapter extends BaseArrayAdapter implements IBaseAdapter { - private final Context mContext; - public SimpleParcelableUsersAdapter(final Context context) { this(context, R.layout.list_item_user); } public SimpleParcelableUsersAdapter(final Context context, final int layoutRes) { super(context, layoutRes); - mContext = context; configBaseAdapter(context, this); } @Override public long getItemId(final int position) { - return getItem(position) != null ? getItem(position).id : -1; + return getItem(position) != null ? getItem(position).key.getId() : -1; } @Override @@ -68,8 +65,8 @@ public class SimpleParcelableUsersAdapter extends BaseArrayAdapter extends IContentCardAdapter, IGapSupport long getStatusId(int position); @Nullable - AccountKey getAccountKey(int position); + UserKey getAccountKey(int position); @Nullable - ParcelableStatus findStatusById(AccountKey accountKey, long statusId); + ParcelableStatus findStatusById(UserKey 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 156862edd..60bdbec78 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/BaseAccountPreferenceFragment.java @@ -58,7 +58,7 @@ 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_key.getId(), + final String name = mUserColorNameManager.getDisplayName(account.account_key, account.name, account.screen_name, nameFirst, false); activity.setTitle(name); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java index 46aa68622..3a8c9d067 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java @@ -61,7 +61,7 @@ import org.mariotaku.sqliteqb.library.RawItemArray; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.SettingsActivity; import org.mariotaku.twidere.activity.support.CustomTabEditorActivity; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.CustomTabConfiguration; import org.mariotaku.twidere.model.CustomTabConfiguration.CustomTabConfigurationComparator; import org.mariotaku.twidere.provider.TwidereDataStore.Tabs; @@ -222,7 +222,7 @@ public class CustomTabsFragment extends BaseFragment implements LoaderCallbacks< final Resources res = getResources(); final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity()); final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false); - final AccountKey[] accountIds = DataStoreUtils.getAccountKeys(getActivity()); + final UserKey[] accountIds = DataStoreUtils.getAccountKeys(getActivity()); final MenuItem itemAdd = menu.findItem(R.id.add_submenu); if (itemAdd != null && itemAdd.hasSubMenu()) { final SubMenu subMenu = itemAdd.getSubMenu(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java index e10d1c080..8759e9303 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java @@ -33,7 +33,7 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils; import org.mariotaku.twidere.util.DataStoreUtils; @@ -155,7 +155,7 @@ public class NetworkDiagnosticsFragment extends BaseFragment { } publishProgress(LogText.LINEBREAK, LogText.LINEBREAK); - for (AccountKey accountKey : DataStoreUtils.getAccountKeys(mContext)) { + for (UserKey accountKey : DataStoreUtils.getAccountKeys(mContext)) { final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(mContext, accountKey); final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountKey, false); if (credentials == null || twitter == null) continue; 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 dc04d834e..5e12a5faa 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 @@ -47,7 +47,7 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosi import org.mariotaku.twidere.annotation.ReadPositionTag; import org.mariotaku.twidere.fragment.support.AbsStatusesFragment.DefaultOnLikedListener; import org.mariotaku.twidere.loader.iface.IExtendedLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.BaseRefreshTaskParam; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableMedia; @@ -91,7 +91,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler public List mRecords; private long mFirstVisibleTimestamp = -1; - private AccountKey mFirstVisibleAccountId = null; + private UserKey mFirstVisibleAccountId = null; private int mFirstVisiblePosition = -1; private int mScrollState; @@ -105,7 +105,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler final ParcelableActivity activity = adapter.getActivity(firstVisiblePosition); if (activity != null) { final long timestamp = activity.timestamp; - final AccountKey accountKey = activity.account_key; + final UserKey accountKey = activity.account_key; if (timestamp != mFirstVisibleTimestamp || !accountKey.equals(mFirstVisibleAccountId)) { if (mRecords == null) mRecords = new ArrayList<>(); final long time = System.currentTimeMillis(); @@ -340,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 = {activity.account_key}; + final UserKey[] accountIds = {activity.account_key}; final long[] maxIds = {activity.min_position}; getActivities(new BaseRefreshTaskParam(accountIds, maxIds, null)); } @@ -507,7 +507,7 @@ public abstract class AbsActivitiesFragment extends AbsContentListRecycler return new StatusesBusCallback(); } - protected abstract AccountKey[] getAccountKeys(); + protected abstract UserKey[] getAccountKeys(); protected Data getAdapterData() { final AbsActivitiesAdapter adapter = getAdapter(); 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 de49a55ef..d1e30ac26 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 @@ -47,11 +47,11 @@ import org.mariotaku.twidere.adapter.iface.IStatusesAdapter.StatusAdapterListene import org.mariotaku.twidere.annotation.ReadPositionTag; import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable; import org.mariotaku.twidere.loader.iface.IExtendedLoader; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.BaseRefreshTaskParam; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.RefreshTaskParam; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.task.AbstractTask; import org.mariotaku.twidere.task.util.TaskStarter; @@ -90,7 +90,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi public List mRecords; private long mFirstVisibleId = -1; - private AccountKey mFirstVisibleAccountId = null; + private UserKey mFirstVisibleAccountId = null; private int mFirstVisiblePosition = -1; private int mScrollState; @@ -104,7 +104,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi final ParcelableStatus status = adapter.getStatus(firstVisiblePosition); if (status != null) { final long id = status.id; - final AccountKey accountId = status.account_key; + final UserKey accountId = status.account_key; if (id != mFirstVisibleId || !accountId.equals(mFirstVisibleAccountId)) { if (mRecords == null) mRecords = new ArrayList<>(); final long time = System.currentTimeMillis(); @@ -321,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 = {status.account_key}; + final UserKey[] accountIds = {status.account_key}; final long[] maxIds = {status.id}; getStatuses(new BaseRefreshTaskParam(accountIds, maxIds, null)); } @@ -405,7 +405,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi @Override public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) { final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, status.account_key, status.user_id, + IntentUtils.openUserProfile(activity, status.account_key, status.user_key.getId(), status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } @@ -493,7 +493,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerVi return new StatusesBusCallback(); } - protected abstract AccountKey[] getAccountKeys(); + protected abstract UserKey[] getAccountKeys(); protected Data getAdapterData() { final AbsStatusesAdapter adapter = getAdapter(); 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 51ec119e9..d856abe41 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 @@ -112,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, user.account_key, user.id, user.screen_name, null, - true, getUserReferral()); + IntentUtils.openUserProfile(activity, user.account_key, user.key.getId(), + 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 6ade243ac..8d9a432d3 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 @@ -87,9 +87,9 @@ import org.mariotaku.twidere.activity.support.QuickSearchBarActivity; import org.mariotaku.twidere.adapter.ArrayAdapter; import org.mariotaku.twidere.annotation.CustomTabType; import org.mariotaku.twidere.menu.support.AccountToggleProvider; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.SupportTabSpec; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableAccountUtils; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.util.CompareUtils; @@ -159,7 +159,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo private boolean mLoaderInitialized; @NonNull - public AccountKey[] getActivatedAccountIds() { + public UserKey[] getActivatedAccountIds() { if (mAccountActionProvider != null) { return mAccountActionProvider.getActivatedAccountIds(); } @@ -278,7 +278,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo mNoAccountContainer.setVisibility(View.VISIBLE); mAccountProfileContainer.setVisibility(View.INVISIBLE); } - AccountKey defaultId = null; + UserKey defaultId = null; for (ParcelableAccount account : accounts) { if (account.is_activated) { defaultId = account.account_key; @@ -288,7 +288,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo mUseStarsForLikes = mPreferences.getBoolean(KEY_I_WANT_MY_STARS_BACK); mAccountsAdapter.setAccounts(accounts); - AccountKey accountKey = AccountKey.valueOf(mPreferences.getString(KEY_DEFAULT_ACCOUNT_KEY, null)); + UserKey accountKey = UserKey.valueOf(mPreferences.getString(KEY_DEFAULT_ACCOUNT_KEY, null)); if (accountKey == null) { accountKey = defaultId; } @@ -580,9 +580,9 @@ 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, AccountKey accountId, boolean isActivated) { + private boolean hasAccountInTab(SupportTabSpec tab, UserKey accountId, boolean isActivated) { if (tab.args == null) return false; - final AccountKey[] accountKeys = Utils.getAccountKeys(getContext(), tab.args); + final UserKey[] accountKeys = Utils.getAccountKeys(getContext(), tab.args); if (accountKeys == null) return isActivated; return ArrayUtils.contains(accountKeys, accountId); } @@ -754,8 +754,8 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo final ParcelableAccount account = mSelectedAccount; if (account != null && option.id == R.id.compose) { final Context context = getContext(); - final String displayName = mUserColorNameManager.getDisplayName(-1, account.name, - account.screen_name, mNameFirst, false); + final String displayName = UserColorNameManager.getDisplayName(account.name, + account.screen_name, mNameFirst); return context.getString(R.string.tweet_from_name, displayName); } return super.getTitle(position, option); @@ -798,7 +798,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo setHasStableIds(true); } - private static int indexOfAccount(List accounts, AccountKey accountId) { + private static int indexOfAccount(List accounts, UserKey accountId) { for (int i = 0, j = accounts.size(); i < j; i++) { if (accounts.get(i).account_key.equals(accountId)) return i; } @@ -821,13 +821,13 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo } @Nullable - public AccountKey getSelectedAccountKey() { + public UserKey getSelectedAccountKey() { final ParcelableAccount selectedAccount = getSelectedAccount(); if (selectedAccount == null) return null; return selectedAccount.account_key; } - public void setSelectedAccountKey(@Nullable AccountKey accountKey) { + public void setSelectedAccountKey(@Nullable UserKey accountKey) { final ParcelableAccount selectedAccount = getSelectedAccount(); if (selectedAccount == null || accountKey == null) return; swap(accountKey, selectedAccount.account_key); @@ -889,7 +889,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo return mInternalAccounts; } - private void swap(AccountKey fromId, AccountKey toId) { + private void swap(UserKey fromId, UserKey toId) { int fromIdx = -1, toIdx = -1; for (int i = 0, j = mInternalAccounts.length; i < j; i++) { final ParcelableAccount account = mInternalAccounts[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 07adb47f7..698222598 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 @@ -44,7 +44,7 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.support.ColorPickerDialogActivity; import org.mariotaku.twidere.activity.support.SignInActivity; import org.mariotaku.twidere.adapter.AccountsAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -71,7 +71,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load private AccountsAdapter mAdapter; private ParcelableAccount mSelectedAccount; - private SimpleArrayMap mActivatedState = new SimpleArrayMap<>(); + private SimpleArrayMap mActivatedState = new SimpleArrayMap<>(); private DragSortListView mListView; private View mEmptyView; @@ -163,7 +163,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)); @@ -184,7 +184,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load } @Override - public void onAccountToggle(AccountKey accountId, boolean state) { + public void onAccountToggle(UserKey accountId, boolean state) { mActivatedState.put(accountId, state); } @@ -303,7 +303,7 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load @Override public void onClick(final DialogInterface dialog, final int which) { final Bundle args = getArguments(); - final AccountKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); if (accountId == null) return; final ContentResolver resolver = getContentResolver(); switch (which) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AddStatusFilterDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AddStatusFilterDialogFragment.java index f067c91a9..c0ea74a5c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AddStatusFilterDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AddStatusFilterDialogFragment.java @@ -36,6 +36,7 @@ import com.twitter.Extractor; import org.mariotaku.twidere.R; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUserMention; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.HtmlEscapeHelper; @@ -59,7 +60,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp @Override public void onClick(final DialogInterface dialog, final int which) { - final Set user_ids = new HashSet<>(); + final Set userKeys = new HashSet<>(); final Set keywords = new HashSet<>(); final Set sources = new HashSet<>(); final ArrayList userValues = new ArrayList<>(); @@ -69,11 +70,11 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp final Object value = info.value; if (value instanceof ParcelableUserMention) { final ParcelableUserMention mention = (ParcelableUserMention) value; - user_ids.add(mention.id); + userKeys.add(mention.key); userValues.add(ContentValuesCreator.createFilteredUser(mention)); } else if (value instanceof UserItem) { final UserItem item = (UserItem) value; - user_ids.add(item.id); + userKeys.add(item.key); userValues.add(createFilteredUser(item)); } else if (info.type == FilterItemInfo.FILTER_TYPE_KEYWORD) { if (value != null) { @@ -94,9 +95,9 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp } } final ContentResolver resolver = getContentResolver(); - ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, Filters.Users.USER_ID, user_ids, null, false); - ContentResolverUtils.bulkDelete(resolver, Filters.Keywords.CONTENT_URI, Filters.Keywords.VALUE, keywords, null, true); - ContentResolverUtils.bulkDelete(resolver, Filters.Sources.CONTENT_URI, Filters.Sources.VALUE, sources, null, true); + ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, Filters.Users.USER_ID, userKeys, null); + ContentResolverUtils.bulkDelete(resolver, Filters.Keywords.CONTENT_URI, Filters.Keywords.VALUE, keywords, null); + ContentResolverUtils.bulkDelete(resolver, Filters.Sources.CONTENT_URI, Filters.Sources.VALUE, sources, null); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, userValues); ContentResolverUtils.bulkInsert(resolver, Filters.Keywords.CONTENT_URI, keywordValues); ContentResolverUtils.bulkInsert(resolver, Filters.Sources.CONTENT_URI, sourceValues); @@ -154,12 +155,12 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, new UserItem(status.quoted_user_id, status.quoted_user_name, status.quoted_user_screen_name))); } - list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, new UserItem(status.user_id, + list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, new UserItem(status.user_key, status.user_name, status.user_screen_name))); final ParcelableUserMention[] mentions = status.mentions; if (mentions != null) { for (final ParcelableUserMention mention : mentions) { - if (mention.id != status.user_id) { + if (!mention.key.equals(status.user_key)) { list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, mention)); } } @@ -177,11 +178,11 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp private String getName(final UserColorNameManager manager, final Object value, boolean nameFirst) { if (value instanceof ParcelableUserMention) { final ParcelableUserMention mention = (ParcelableUserMention) value; - return manager.getDisplayName(mention.id, mention.name, mention.screen_name, nameFirst, + return manager.getDisplayName(mention.key, mention.name, mention.screen_name, nameFirst, true); } else if (value instanceof UserItem) { final UserItem item = (UserItem) value; - return manager.getDisplayName(item.id, item.name, item.screen_name, nameFirst, true); + return manager.getDisplayName(item.key, item.name, item.screen_name, nameFirst, true); } else return ParseUtils.parseString(value); } @@ -189,7 +190,7 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp private static ContentValues createFilteredUser(UserItem item) { if (item == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, item.id); + values.put(Filters.Users.USER_ID, item.key.toString()); values.put(Filters.Users.NAME, item.name); values.put(Filters.Users.SCREEN_NAME, item.screen_name); return values; @@ -248,11 +249,11 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp } private static class UserItem { - private final long id; + private final UserKey key; private final String name, screen_name; - public UserItem(long id, String name, String screen_name) { - this.id = id; + public UserItem(UserKey key, String name, String screen_name) { + this.key = key; this.name = name; this.screen_name = screen_name; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/BaseFiltersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/BaseFiltersFragment.java index 12bf6b1ea..8447c2c4b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/BaseFiltersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/BaseFiltersFragment.java @@ -61,6 +61,7 @@ import org.mariotaku.twidere.activity.support.UserListSelectorActivity; import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter; import org.mariotaku.twidere.adapter.SourceAutoCompleteAdapter; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.ParseUtils; @@ -406,7 +407,9 @@ public abstract class BaseFiltersFragment extends AbsContentListViewFragment> adapter = getAdapter(); if (adapter.getItemCount() > 0) { showContent(); @@ -107,7 +107,7 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment() { @Override public RefreshTaskParam doLongOperation(Object o) { - final AccountKey[] accountKeys = getAccountKeys(); + final UserKey[] accountKeys = getAccountKeys(); final long[] maxIds = getOldestActivityIds(accountKeys); return new BaseRefreshTaskParam(accountKeys, maxIds, null); } @@ -219,7 +219,7 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment { - private final AccountKey[] mAccountKeys; + private final UserKey[] mAccountKeys; public CursorActivitiesLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, - boolean fromUser, AccountKey[] accountKeys) { + boolean fromUser, UserKey[] accountKeys) { super(context, ParcelableActivityCursorIndices.class, uri, projection, selection, selectionArgs, sortOrder, fromUser); mAccountKeys = accountKeys; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java index af63cdecd..e8dad85d5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java @@ -43,7 +43,7 @@ import org.mariotaku.twidere.adapter.AbsStatusesAdapter; import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.loader.support.ExtendedObjectCursorLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusCursorIndices; @@ -75,7 +75,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment> adapter = getAdapter(); if (adapter.getItemCount() > 0) { showContent(); @@ -106,7 +106,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment { - private final AccountKey[] mAccountKeys; + private final UserKey[] mAccountKeys; public CursorStatusesLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, - boolean fromUser, AccountKey[] accountKeys) { + boolean fromUser, UserKey[] accountKeys) { super(context, ParcelableStatusCursorIndices.class, uri, projection, selection, selectionArgs, sortOrder, fromUser); mAccountKeys = accountKeys; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroyFriendshipDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroyFriendshipDialogFragment.java index 979aed2e1..5a989d54c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroyFriendshipDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroyFriendshipDialogFragment.java @@ -45,7 +45,7 @@ public class DestroyFriendshipDialogFragment extends BaseSupportDialogFragment i final ParcelableUser user = getUser(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (user == null || twitter == null) return; - twitter.destroyFriendshipAsync(user.account_key, user.id); + twitter.destroyFriendshipAsync(user.account_key, user.key.getId()); break; default: break; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroySavedSearchDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroySavedSearchDialogFragment.java index f1a698d68..125036097 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroySavedSearchDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DestroySavedSearchDialogFragment.java @@ -28,7 +28,7 @@ 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.UserKey; import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.ThemeUtils; @@ -41,7 +41,7 @@ public class DestroySavedSearchDialogFragment extends BaseSupportDialogFragment public void onClick(final DialogInterface dialog, final int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - final AccountKey accountKey = getAccountKey(); + final UserKey accountKey = getAccountKey(); final long searchId = getSearchId(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (searchId <= 0 || twitter == null) return; @@ -67,7 +67,7 @@ public class DestroySavedSearchDialogFragment extends BaseSupportDialogFragment return builder.create(); } - private AccountKey getAccountKey() { + private UserKey getAccountKey() { final Bundle args = getArguments(); return args.getParcelable(EXTRA_ACCOUNT_KEY); } @@ -85,7 +85,7 @@ public class DestroySavedSearchDialogFragment extends BaseSupportDialogFragment } public static DestroySavedSearchDialogFragment show(final FragmentManager fm, - final AccountKey accountKey, + final UserKey accountKey, final long searchId, final String name) { final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java index 96b88517b..2a7d7402f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java @@ -54,7 +54,7 @@ import org.mariotaku.twidere.adapter.MessageEntriesAdapter.DirectMessageEntry; import org.mariotaku.twidere.adapter.MessageEntriesAdapter.MessageEntriesAdapterListener; import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.BaseRefreshTaskParam; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.message.GetMessagesTaskEvent; @@ -89,7 +89,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment> mUnreadCountsToRemove = new SimpleArrayMap<>(); + private final SimpleArrayMap> mUnreadCountsToRemove = new SimpleArrayMap<>(); private final Set mReadPositions = Collections.synchronizedSet(new HashSet()); private int mFirstVisibleItem; @@ -121,7 +121,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 UserKey[] accountIds = getAccountKeys(); final String selection = Expression.in(new Column(Statuses.ACCOUNT_KEY), new ArgsArray(accountIds.length)).getSQL(); final String[] selectionArgs = TwidereArrayUtils.toStringArray(accountIds, 0, accountIds.length); @@ -169,7 +169,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment 1); setRefreshEnabled(true); @@ -242,7 +242,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment counts = new HashSet<>(); counts.add(id); @@ -390,7 +390,7 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment 0 ? item.media[0].uri : null; twitter.sendDirectMessageAsync(accountId, recipientId, item.text, imageUri); break; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/HomeTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/HomeTimelineFragment.java index e8bdd37e9..192d438fa 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/HomeTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/HomeTimelineFragment.java @@ -24,7 +24,7 @@ import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import org.mariotaku.twidere.annotation.ReadPositionTag; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; import org.mariotaku.twidere.util.AsyncTwitterWrapper; @@ -84,7 +84,7 @@ public class HomeTimelineFragment extends CursorStatusesFragment { super.setUserVisibleHint(isVisibleToUser); final FragmentActivity activity = getActivity(); if (isVisibleToUser && activity != null) { - for (AccountKey accountId : getAccountKeys()) { + for (UserKey accountId : getAccountKeys()) { final String tag = "home_" + accountId; mNotificationManager.cancel(tag, NOTIFICATION_ID_HOME_TIMELINE); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java index 20576834a..8cc5759aa 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/IncomingFriendshipsFragment.java @@ -30,7 +30,7 @@ import org.mariotaku.twidere.adapter.ParcelableUsersAdapter; import org.mariotaku.twidere.adapter.iface.IUsersAdapter; import org.mariotaku.twidere.loader.support.IDsUsersLoader; import org.mariotaku.twidere.loader.support.IncomingFriendshipsLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.message.FollowRequestTaskEvent; import org.mariotaku.twidere.view.holder.UserViewHolder; @@ -53,7 +53,7 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment @Override public IDsUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, final boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final IncomingFriendshipsLoader loader = new IncomingFriendshipsLoader(context, accountKey, getData(), fromUser); loader.setCursor(getNextCursor()); @@ -73,7 +73,7 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment final AbsUsersAdapter> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.acceptFriendshipAsync(user.account_key, user.id); + mTwitterWrapper.acceptFriendshipAsync(user.account_key, user.key); } @Override @@ -81,7 +81,7 @@ public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment final AbsUsersAdapter> adapter = getAdapter(); final ParcelableUser user = adapter.getUser(position); if (user == null) return; - mTwitterWrapper.denyFriendshipAsync(user.account_key, user.id); + mTwitterWrapper.denyFriendshipAsync(user.account_key, user.key); } @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 4bfc384ce..657cf67f9 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 @@ -83,11 +83,11 @@ import org.mariotaku.twidere.adapter.SimpleParcelableUsersAdapter; import org.mariotaku.twidere.adapter.iface.IBaseCardAdapter.MenuButtonClickListener; import org.mariotaku.twidere.annotation.CustomTabType; import org.mariotaku.twidere.loader.support.UserSearchLoader; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserCursorIndices; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.TaskStateChangedEvent; import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils; import org.mariotaku.twidere.provider.TwidereDataStore; @@ -139,7 +139,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements mUsersSearchList.setVisibility(View.GONE); mUsersSearchEmpty.setVisibility(View.GONE); mUsersSearchProgress.setVisibility(View.VISIBLE); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final String query = args.getString(EXTRA_QUERY); final boolean fromCache = args.getBoolean(EXTRA_FROM_CACHE); final boolean fromUser = args.getBoolean(EXTRA_FROM_USER, false); @@ -304,7 +304,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements account = args.getParcelable(EXTRA_ACCOUNT); recipient = args.getParcelable(EXTRA_USER); } else if (args.containsKey(EXTRA_ACCOUNT_KEY)) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_RECIPIENT_ID, -1); final int accountPos = accountsSpinnerAdapter.findItemPosition(accountKey.getId()); if (accountPos >= 0) { @@ -319,7 +319,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements } showConversation(account, recipient); if (account != null && recipient != null) { - final String key = getDraftsTextKey(account.account_key, recipient.id); + final String key = getDraftsTextKey(account.account_key, recipient.key.getId()); mEditText.setText(mMessageDrafts.getString(key, null)); } } @@ -373,7 +373,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_key, recipient.id); + final String key = getDraftsTextKey(account.account_key, recipient.key.getId()); final SharedPreferences.Editor editor = mMessageDrafts.edit(); final String text = ParseUtils.parseString(mEditText.getText()); if (TextUtils.isEmpty(text)) { @@ -405,7 +405,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements case R.id.delete_all: { final ParcelableCredentials account = mAccount; if (account == null || mRecipient == null) return true; - mTwitterWrapper.destroyMessageConversationAsync(account.account_key, mRecipient.id); + mTwitterWrapper.destroyMessageConversationAsync(account.account_key, + mRecipient.key.getId()); return true; } } @@ -432,7 +433,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements @Override public Loader onCreateLoader(final int id, final Bundle args) { - final AccountKey accountId = args != null ? args.getParcelable(EXTRA_ACCOUNT_KEY) : null; + final UserKey accountId = args != null ? args.getParcelable(EXTRA_ACCOUNT_KEY) : null; final long recipientId = args != null ? args.getLong(EXTRA_RECIPIENT_ID, -1) : -1; final String[] cols = DirectMessages.COLUMNS; final boolean isValid = accountId != null && recipientId > 0; @@ -567,7 +568,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final LoaderManager lm = getLoaderManager(); final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, account.account_key); - args.putLong(EXTRA_RECIPIENT_ID, recipient.id); + args.putLong(EXTRA_RECIPIENT_ID, recipient.key.getId()); if (mLoaderInitialized) { lm.restartLoader(0, args, this); } else { @@ -584,11 +585,11 @@ public class MessagesConversationFragment extends BaseSupportFragment implements return mConversationContainer.getVisibility() == View.VISIBLE; } - private String getDraftsTextKey(AccountKey accountKey, long userId) { + private String getDraftsTextKey(UserKey accountKey, long userId) { return String.format(Locale.ROOT, "text_%s_to_%d", accountKey, userId); } - private void searchUsers(AccountKey accountKey, String query, boolean fromCache) { + private void searchUsers(UserKey accountKey, String query, boolean fromCache) { final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); args.putString(EXTRA_QUERY, query); @@ -638,8 +639,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements if (TextUtils.isEmpty(message)) { mEditText.setError(getString(R.string.error_message_no_content)); } else { - mTwitterWrapper.sendDirectMessageAsync(account.account_key, recipient.id, message, - mImageUri); + mTwitterWrapper.sendDirectMessageAsync(account.account_key, recipient.key.getId(), + message, mImageUri); mEditText.setText(null); mImageUri = null; updateAddImageButton(); @@ -834,7 +835,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements private final boolean mFromCache; private final UserColorNameManager mUserColorNameManager; - public CacheUserSearchLoader(MessagesConversationFragment fragment, AccountKey accountKey, + public CacheUserSearchLoader(MessagesConversationFragment fragment, UserKey accountKey, String query, boolean fromCache, boolean fromUser) { super(fragment.getContext(), accountKey, query, 0, null, fromUser); mUserColorNameManager = fragment.mUserColorNameManager; @@ -855,7 +856,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements final long[] nicknameIds = Utils.getMatchedNicknameIds(query, mUserColorNameManager); selection = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"), Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"), - Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds))); + Expression.in(new Column(CachedUsers.USER_KEY), new RawItemArray(nicknameIds))); selectionArgs = new String[]{queryEscaped, queryEscaped}; } else { selection = null; @@ -902,7 +903,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(account.account_key, user.id); + twitter.destroyMessageConversationAsync(account.account_key, user.key.getId()); break; } } @@ -933,7 +934,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements Expression.equalsArgs(ConversationEntries.CONVERSATION_ID) ).getSQL(); final String[] selectionArgs = {String.valueOf(mAccount.account_key), - String.valueOf(mRecipient.id)}; + String.valueOf(mRecipient.key)}; final String orderBy = new OrderBy(ConversationEntries.MESSAGE_ID, false).getSQL(); return resolver.query(ConversationEntries.CONTENT_URI, projection, selection, selectionArgs, orderBy); @@ -943,7 +944,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements protected void onPostExecute(Cursor cursor) { if (cursor.moveToFirst()) { final int messageIdIdx = cursor.getColumnIndex(ConversationEntries.MESSAGE_ID); - final String key = mAccount.account_key + "-" + mRecipient.id; + final String key = mAccount.account_key + "-" + mRecipient.key; mReadStateManager.setPosition(CustomTabType.DIRECT_MESSAGES, key, cursor.getLong(messageIdIdx), false); } cursor.close(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java index fd710a87d..248476c4f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MutesUsersListFragment.java @@ -25,13 +25,13 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.MutesUsersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class MutesUsersListFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final MutesUsersLoader loader = new MutesUsersLoader(context, accountKey, getData(), fromUser); loader.setCursor(getNextCursor()); return loader; 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 2d3584384..5087e5a4e 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 @@ -30,7 +30,7 @@ import org.mariotaku.twidere.adapter.AbsStatusesAdapter; import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.BaseRefreshTaskParam; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.RefreshTaskParam; @@ -104,7 +104,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment> adapter = getAdapter(); final ParcelableStatus status = adapter.getStatus(adapter.getStatusStartIndex() + adapter.getStatusCount() - 1); - AccountKey[] accountKeys = {status.account_key}; + UserKey[] accountKeys = {status.account_key}; final long[] maxIds = {status.id}; getStatuses(new BaseRefreshTaskParam(accountKeys, maxIds, null)); } @@ -157,7 +157,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment> adapter = getAdapter(); - final AccountKey[] accountIds = getAccountKeys(); + final UserKey[] accountIds = getAccountKeys(); if (adapter.getStatusCount() > 0) { final long[] sinceIds = new long[]{adapter.getStatus(0).id}; getStatuses(new BaseRefreshTaskParam(accountIds, null, sinceIds)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUserListsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUserListsFragment.java index 3a7799c84..ee12539ad 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUserListsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableUserListsFragment.java @@ -28,7 +28,7 @@ import android.support.v4.content.Loader; import org.mariotaku.twidere.adapter.ParcelableUserListsAdapter; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import java.util.List; @@ -49,7 +49,7 @@ public abstract class ParcelableUserListsFragment extends AbsUserListsFragment> onCreateStatusesLoader(final Context context, final Bundle args, final boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final int tabPosition = args.getInt(EXTRA_TAB_POSITION, -1); @@ -59,7 +59,7 @@ public class RetweetsOfMeFragment extends ParcelableStatusesFragment { protected String[] getSavedStatusesFileArgs() { final Bundle args = getArguments(); if (args == null) return null; - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); return new String[]{AUTHORITY_RETWEETS_OF_ME, "account" + accountKey}; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java index 128def9f9..96999ccee 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java @@ -34,7 +34,7 @@ import org.mariotaku.twidere.adapter.SavedSearchesAdapter; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; import org.mariotaku.twidere.loader.support.SavedSearchesLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent; import java.util.Collections; @@ -87,7 +87,7 @@ public class SavedSearchesListFragment extends AbsContentListViewFragment> onCreateLoader(int id, Bundle args) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final String[] states = {ScheduledStatus.State.SCHEDULED, ScheduledStatus.State.FAILED}; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java index c21e5edb6..0dba359f1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java @@ -51,7 +51,7 @@ import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCal import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback; import org.mariotaku.twidere.graphic.EmptyDrawable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.RecentSearchProvider; import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory; import org.mariotaku.twidere.util.AsyncTwitterWrapper; @@ -74,7 +74,7 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll private int mControlBarOffsetPixels; private int mControlBarHeight; - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return getArguments().getParcelable(EXTRA_ACCOUNT_KEY); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchUsersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchUsersFragment.java index 11f79315c..e354f09b4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchUsersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchUsersFragment.java @@ -26,7 +26,7 @@ import android.support.v4.content.Loader; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.loader.support.UserSearchLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -45,7 +45,7 @@ public class SearchUsersFragment extends ParcelableUsersFragment { @Override public Loader> onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final String query = args.getString(EXTRA_QUERY); final int page = args.getInt(EXTRA_PAGE, 1); return new UserSearchLoader(context, accountKey, query, page, getData(), fromUser); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SensitiveContentWarningDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SensitiveContentWarningDialogFragment.java index 851da9a04..ea422a833 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SensitiveContentWarningDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SensitiveContentWarningDialogFragment.java @@ -27,7 +27,7 @@ import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.IntentUtils; @@ -44,7 +44,7 @@ public class SensitiveContentWarningDialogFragment extends BaseSupportDialogFrag final Context context = getActivity(); final Bundle args = getArguments(); if (args == null || context == null) return; - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final ParcelableMedia current = args.getParcelable(EXTRA_CURRENT_MEDIA); final ParcelableStatus status = args.getParcelable(EXTRA_STATUS); final Bundle option = args.getBundle(EXTRA_ACTIVITY_OPTIONS); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SetUserNicknameDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SetUserNicknameDialogFragment.java index 1b065ac4c..190693f53 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SetUserNicknameDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SetUserNicknameDialogFragment.java @@ -33,6 +33,7 @@ import android.widget.EditText; import android.widget.FrameLayout; import org.mariotaku.twidere.R; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.ThemeUtils; @@ -44,9 +45,10 @@ public class SetUserNicknameDialogFragment extends BaseSupportDialogFragment imp @Override public void onClick(final DialogInterface dialog, final int which) { final Bundle args = getArguments(); + assert args != null; final String text = ParseUtils.parseString(mEditText.getText()); - final long userId = args != null ? args.getLong(EXTRA_USER_ID, -1) : -1; - if (userId == -1) return; + final UserKey userId = args.getParcelable(EXTRA_USER_ID); + assert userId != null; switch (which) { case DialogInterface.BUTTON_POSITIVE: { if (TextUtils.isEmpty(text)) { @@ -89,10 +91,10 @@ public class SetUserNicknameDialogFragment extends BaseSupportDialogFragment imp return builder.create(); } - public static SetUserNicknameDialogFragment show(final FragmentManager fm, final long user_id, final String nickname) { + public static SetUserNicknameDialogFragment show(final FragmentManager fm, final UserKey userKey, final String nickname) { final SetUserNicknameDialogFragment f = new SetUserNicknameDialogFragment(); final Bundle args = new Bundle(); - args.putLong(EXTRA_USER_ID, user_id); + args.putParcelable(EXTRA_USER_KEY, userKey); args.putString(EXTRA_NAME, nickname); f.setArguments(args); f.show(fm, FRAGMENT_TAG_SET_USER_NICKNAME); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFavoritersListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFavoritersListFragment.java index b516660f7..d4d756a25 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFavoritersListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFavoritersListFragment.java @@ -25,13 +25,13 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.IDsUsersLoader; import org.mariotaku.twidere.loader.support.StatusFavoritersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class StatusFavoritersListFragment extends CursorSupportUsersListFragment { @Override public IDsUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long statusId = args.getLong(EXTRA_STATUS_ID, -1); final StatusFavoritersLoader loader = new StatusFavoritersLoader(context, accountKey, statusId, getData(), false); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index 3f9d1e977..7f09b6c9c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -105,7 +105,6 @@ import org.mariotaku.twidere.fragment.support.AbsStatusesFragment.DefaultOnLiked import org.mariotaku.twidere.loader.support.ConversationLoader; import org.mariotaku.twidere.loader.support.ParcelableStatusLoader; import org.mariotaku.twidere.menu.support.FavoriteItemProvider; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityCursorIndices; import org.mariotaku.twidere.model.ParcelableActivityValuesCreator; @@ -116,6 +115,7 @@ import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusValuesCreator; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.SingleResponse; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.FavoriteTaskEvent; import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.model.util.ParcelableActivityUtils; @@ -223,7 +223,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac assert status != null; final ConversationLoader loader = new ConversationLoader(getActivity(), status, sinceId, maxId, mStatusAdapter.getData(), true); - loader.setComparator(ParcelableStatus.REVERSE_ID_COMPARATOR); + loader.setComparator(ParcelableStatus.REVERSE_TIMESTAMP_COMPARATOR); return loader; } @@ -248,8 +248,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } mStatusAdapter.setLoadMoreSupportedPosition(supportedPositions); setConversation(data); - final ParcelableCredentials account = mStatusAdapter.getStatusAccount(); - if (Utils.hasOfficialAPIAccess(loader.getContext(), account)) { + final boolean canLoadAllReplies = ((ConversationLoader) loader).canLoadAllReplies(); + if (canLoadAllReplies) { mStatusAdapter.setReplyError(null); } else { final SpannableStringBuilder error = SpannableStringBuilder.valueOf( @@ -289,7 +289,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac private LoaderCallbacks mStatusActivityLoaderCallback = new LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long statusId = args.getLong(EXTRA_STATUS_ID, -1); return new StatusActivitySummaryLoader(getActivity(), accountKey, statusId); } @@ -317,9 +317,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac if (resultCode == Activity.RESULT_OK) { if (data == null) return; final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT); - mUserColorNameManager.setUserColor(status.user_id, color); + mUserColorNameManager.setUserColor(status.user_key, color); } else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) { - mUserColorNameManager.clearUserColor(status.user_id); + mUserColorNameManager.clearUserColor(status.user_key); } break; } @@ -328,7 +328,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac if (status == null) return; if (resultCode == Activity.RESULT_OK) { if (data == null || !data.hasExtra(EXTRA_ID)) return; - final AccountKey accountKey = data.getParcelableExtra(EXTRA_KEY); + final UserKey accountKey = data.getParcelableExtra(EXTRA_KEY); IntentUtils.openStatus(activity, accountKey, status.id); } break; @@ -461,12 +461,12 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac @Override public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) { final FragmentActivity activity = getActivity(); - IntentUtils.openUserProfile(activity, status.account_key, status.user_id, + IntentUtils.openUserProfile(activity, status.account_key, status.user_key.getId(), status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS); } @Override - public void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long extraId) { + public void onMediaClick(View view, ParcelableMedia media, UserKey accountKey, long extraId) { final ParcelableStatus status = mStatusAdapter.getStatus(); if (status == null) return; IntentUtils.openMediaDirectly(getActivity(), accountKey, status, media, null, true); @@ -543,7 +543,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac @Override public Loader> onCreateLoader(final int id, final Bundle args) { final Bundle fragmentArgs = getArguments(); - final AccountKey accountKey = fragmentArgs.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = fragmentArgs.getParcelable(EXTRA_ACCOUNT_KEY); final long statusId = fragmentArgs.getLong(EXTRA_STATUS_ID, -1); return new ParcelableStatusLoader(getActivity(), false, fragmentArgs, accountKey, statusId); } @@ -590,7 +590,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final TweetEvent event = mStatusEvent; if (event == null) return; event.markEnd(); - final AccountKey accountKey = new AccountKey(event.getAccountId(), event.getAccountHost()); + final UserKey accountKey = new UserKey(event.getAccountId(), event.getAccountHost()); HotMobiLogger.getInstance(getActivity()).log(accountKey, event); } @@ -989,7 +989,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac if (status.retweet_id > 0) { final String retweetedBy = manager.getDisplayName(status.retweeted_by_user_id, - status.retweeted_by_user_name, status.retweeted_by_user_screen_name, nameFirst, false); + status.retweeted_by_user_name, status.retweeted_by_user_screen_name, + nameFirst, false); retweetedByView.setText(context.getString(R.string.name_retweeted, retweetedBy)); retweetedByView.setVisibility(View.VISIBLE); } else { @@ -1018,7 +1019,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac layoutPosition, status.is_possibly_sensitive, skipLinksInText)); } - quoteIndicator.setColor(manager.getUserColor(status.user_id, false)); + quoteIndicator.setColor(manager.getUserColor(status.user_key, false)); profileContainer.drawStart(manager.getUserColor(status.quoted_user_id, false)); } else { quoteOriginalLink.setVisibility(View.GONE); @@ -1026,7 +1027,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac quotedTextView.setVisibility(View.GONE); quoteIndicator.setVisibility(View.GONE); - profileContainer.drawStart(manager.getUserColor(status.user_id, false)); + profileContainer.drawStart(manager.getUserColor(status.user_key, false)); } final long timestamp; @@ -1037,7 +1038,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac timestamp = status.timestamp; } - nameView.setText(manager.getUserNickname(status.user_id, status.user_name, false)); + nameView.setText(manager.getUserNickname(status.user_key, status.user_name, false)); screenNameView.setText(String.format("@%s", status.user_screen_name)); loader.displayProfileImage(profileImageView, status); @@ -1200,14 +1201,14 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } case R.id.profile_container: { final FragmentActivity activity = fragment.getActivity(); - IntentUtils.openUserProfile(activity, status.account_key, status.user_id, + IntentUtils.openUserProfile(activity, status.account_key, status.user_key.getId(), status.user_screen_name, null, true, UserFragment.Referral.STATUS); break; } case R.id.retweeted_by: { if (status.retweet_id > 0) { IntentUtils.openUserProfile(adapter.getContext(), status.account_key, - status.retweeted_by_user_id, status.retweeted_by_user_screen_name, + status.retweeted_by_user_id.getId(), status.retweeted_by_user_screen_name, null, true, UserFragment.Referral.STATUS); } break; @@ -1220,8 +1221,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } case R.id.quoted_name_container: { IntentUtils.openUserProfile(adapter.getContext(), status.account_key, - status.quoted_user_id, status.quoted_user_screen_name, null, true, - UserFragment.Referral.STATUS); + status.quoted_user_id.getId(), status.quoted_user_screen_name, null, + true, UserFragment.Referral.STATUS); break; } case R.id.quote_original_link: { @@ -1592,7 +1593,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } @Override - public void onLinkClick(final String link, final String orig, final AccountKey accountKey, + public void onLinkClick(final String link, final String orig, final UserKey accountKey, long extraId, int type, boolean sensitive, int start, int end) { final ParcelableStatus status = adapter.getStatus(); ParcelableMedia current; @@ -1814,13 +1815,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } @Override - public AccountKey getAccountKey(int position) { + public UserKey getAccountKey(int position) { final ParcelableStatus status = getStatus(position); return status != null ? status.account_key : null; } @Override - public ParcelableStatus findStatusById(AccountKey accountId, long statusId) { + public ParcelableStatus findStatusById(UserKey accountId, long statusId) { if (mStatus != null && accountId.equals(mStatus.account_key) && statusId == mStatus.id) { return mStatus; } @@ -2426,10 +2427,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac } public static class StatusActivitySummaryLoader extends AsyncTaskLoader { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mStatusId; - public StatusActivitySummaryLoader(Context context, AccountKey accountKey, long statusId) { + public StatusActivitySummaryLoader(Context context, UserKey accountKey, long statusId) { super(context); mAccountKey = accountKey; mStatusId = statusId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusRetweetersListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusRetweetersListFragment.java index edfc5698f..ba2777f4b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusRetweetersListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusRetweetersListFragment.java @@ -25,13 +25,13 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.IDsUsersLoader; import org.mariotaku.twidere.loader.support.StatusRetweetersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class StatusRetweetersListFragment extends CursorSupportUsersListFragment { @Override public IDsUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long statusId = args.getLong(EXTRA_STATUS_ID, -1); final StatusRetweetersLoader loader = new StatusRetweetersLoader(context, accountKey, statusId, getData(), fromUser); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusesSearchFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusesSearchFragment.java index 0a8f5e463..6b4cff0ba 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusesSearchFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusesSearchFragment.java @@ -26,7 +26,7 @@ import android.support.annotation.NonNull; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.TweetSearchLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.io.UnsupportedEncodingException; @@ -52,7 +52,7 @@ public class StatusesSearchFragment extends ParcelableStatusesFragment { final Bundle args, final boolean fromUser) { setRefreshing(true); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final String query = args.getString(EXTRA_QUERY); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java index 798b0c1ae..cc5e0d93d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/TrendsSuggestionsFragment.java @@ -34,7 +34,7 @@ import android.widget.ListView; import com.squareup.otto.Subscribe; import org.mariotaku.twidere.adapter.TrendsAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends; import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.model.message.TaskStateChangedEvent; @@ -46,7 +46,7 @@ import static org.mariotaku.twidere.util.IntentUtils.openTweetSearch; public class TrendsSuggestionsFragment extends AbsContentListViewFragment implements LoaderCallbacks, AdapterView.OnItemClickListener { - private AccountKey mAccountId; + private UserKey mAccountId; @Override public void onActivityCreated(final Bundle savedInstanceState) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserBlocksListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserBlocksListFragment.java index 2207a3541..8e3f39691 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserBlocksListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserBlocksListFragment.java @@ -25,13 +25,13 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.UserBlocksLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class UserBlocksListFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final UserBlocksLoader loader = new UserBlocksLoader(context, accountKey, getData(), fromUser); loader.setCursor(getNextCursor()); return loader; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFavoritesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFavoritesFragment.java index b6853d9bf..891a20bdd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFavoritesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFavoritesFragment.java @@ -25,7 +25,7 @@ import android.support.annotation.NonNull; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.UserFavoritesLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.util.List; @@ -42,7 +42,7 @@ public class UserFavoritesFragment extends ParcelableStatusesFragment { final Bundle args, final boolean fromUser) { setRefreshing(true); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final long userId = args.getLong(EXTRA_USER_ID, -1); @@ -56,7 +56,7 @@ public class UserFavoritesFragment extends ParcelableStatusesFragment { protected String[] getSavedStatusesFileArgs() { final Bundle args = getArguments(); if (args == null) return null; - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); return new String[]{AUTHORITY_USER_FAVORITES, "account" + accountKey, "user" + userId, "name" + screenName}; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java index 2e544b8dd..b9388d15f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFollowersFragment.java @@ -27,7 +27,7 @@ import com.squareup.otto.Subscribe; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.UserFollowersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.UsersBlockedEvent; import static org.mariotaku.twidere.util.DataStoreUtils.getAccountScreenName; @@ -37,7 +37,7 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final UserFollowersLoader loader = new UserFollowersLoader(context, accountKey, userId, @@ -60,7 +60,7 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment { @Subscribe public void onUsersBlocked(UsersBlockedEvent event) { - final AccountKey accountKey = event.getAccountKey(); + final UserKey accountKey = event.getAccountKey(); final String screen_name = getAccountScreenName(getActivity(), accountKey); final Bundle args = getArguments(); if (args == null) return; 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 7b9d52b98..735e9e45a 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 @@ -102,7 +102,6 @@ import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback; import org.mariotaku.twidere.graphic.ActionBarColorDrawable; import org.mariotaku.twidere.graphic.ActionIconDrawable; import org.mariotaku.twidere.loader.support.ParcelableUserLoader; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.CachedRelationship; import org.mariotaku.twidere.model.CachedRelationshipValuesCreator; import org.mariotaku.twidere.model.ConsumerKeyType; @@ -112,6 +111,7 @@ import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.ParcelableUserValuesCreator; import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.model.SupportTabSpec; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent; import org.mariotaku.twidere.model.message.FriendshipUserUpdatedEvent; import org.mariotaku.twidere.model.message.ProfileUpdatedEvent; @@ -236,7 +236,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mFollowButton.setVisibility(View.GONE); mFollowProgress.setVisibility(View.VISIBLE); mFollowingYouIndicator.setVisibility(View.GONE); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); return new UserRelationshipLoader(getActivity(), accountKey, userId); } @@ -261,7 +261,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Override public Loader> onCreateLoader(final int id, final Bundle args) { final boolean omitIntentExtra = args.getBoolean(EXTRA_OMIT_INTENT_EXTRA, true); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); if (mUser == null && (!omitIntentExtra || !args.containsKey(EXTRA_USER))) { @@ -274,8 +274,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } setProgressBarIndeterminateVisibility(true); final ParcelableUser user = mUser; + final boolean loadFromCache = user == null || !user.is_cache && userId != user.key.getId(); return new ParcelableUserLoader(getActivity(), accountKey, userId, screenName, getArguments(), - omitIntentExtra, user == null || !user.is_cache && userId != user.id); + omitIntentExtra, loadFromCache); } @Override @@ -297,7 +298,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (user.is_cache) { final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key); - args.putLong(EXTRA_USER_ID, user.id); + args.putLong(EXTRA_USER_ID, user.key.getId()); args.putString(EXTRA_SCREEN_NAME, user.screen_name); args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, true); getLoaderManager().restartLoader(LOADER_ID_USER, args, this); @@ -340,7 +341,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mRelationship = null; return; } - if (user.account_key.isAccount(user.id, user.user_host)) { + if (user.account_key.maybeEquals(user.key)) { mFollowButton.setText(R.string.edit); mFollowButton.setVisibility(View.VISIBLE); mRelationship = null; @@ -513,7 +514,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener public void displayUser(final ParcelableUser user) { mUser = user; final FragmentActivity activity = getActivity(); - if (user == null || user.id <= 0 || activity == null) return; + if (user == null || user.key == null || activity == null) return; final Resources resources = getResources(); final LoaderManager lm = getLoaderManager(); lm.destroyLoader(LOADER_ID_USER); @@ -522,10 +523,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mHeaderErrorContainer.setVisibility(View.GONE); mProgressContainer.setVisibility(View.GONE); mUser = user; - final int userColor = mUserColorNameManager.getUserColor(user.id, true); + final int userColor = mUserColorNameManager.getUserColor(user.key, true); mProfileImageView.setBorderColor(userColor != 0 ? userColor : Color.WHITE); mProfileNameContainer.drawEnd(user.account_color); - final String nick = mUserColorNameManager.getUserNickname(user.id, true); + final String nick = mUserColorNameManager.getUserNickname(user.key, true); mNameView.setText(mBidiFormatter.unicodeWrap(TextUtils.isEmpty(nick) ? user.name : getString(R.string.name_with_nickname, user.name, nick))); final int typeIconRes = Utils.getUserTypeIconRes(user.is_verified, user.is_protected); if (typeIconRes != 0) { @@ -615,7 +616,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener return mUser; } - public void getUserInfo(final AccountKey accountId, final long userId, final String screenName, + public void getUserInfo(final UserKey accountId, final long userId, final String screenName, final boolean omitIntentExtra) { final LoaderManager lm = getLoaderManager(); lm.destroyLoader(LOADER_ID_USER); @@ -640,7 +641,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Subscribe public void notifyFriendshipUpdated(FriendshipUpdatedEvent event) { final ParcelableUser user = getUser(); - if (user == null || !event.isAccount(user.account_key) || !event.isUser(user.id)) return; + if (user == null || !event.isAccount(user.account_key) || !event.isUser(user.key.getId())) + return; getFriendship(); } @@ -672,9 +674,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (resultCode == Activity.RESULT_OK) { if (data == null) return; final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT); - mUserColorNameManager.setUserColor(mUser.id, color); + mUserColorNameManager.setUserColor(mUser.key, color); } else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) { - mUserColorNameManager.clearUserColor(mUser.id); + mUserColorNameManager.clearUserColor(mUser.key); } break; } @@ -692,10 +694,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (user == null) return; if (resultCode == Activity.RESULT_OK) { if (data == null || !data.hasExtra(EXTRA_ID)) return; - final AccountKey accountKey = data.getParcelableExtra(EXTRA_KEY); + final UserKey accountKey = data.getParcelableExtra(EXTRA_KEY); @Referral final String referral = getArguments().getString(EXTRA_REFERRAL); - IntentUtils.openUserProfile(getActivity(), accountKey, user.id, + IntentUtils.openUserProfile(getActivity(), accountKey, user.key.getId(), user.screen_name, null, true, referral); } break; @@ -732,7 +734,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener ThemeUtils.getUserThemeBackgroundAlpha(activity)); mActionBarShadowColor = 0xA0000000; final Bundle args = getArguments(); - AccountKey accountId = null; + UserKey accountId = null; long userId = -1; String screenName = null; if (savedInstanceState != null) { @@ -894,7 +896,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_key.getId() == user.id; + final boolean isMyself = user.account_key.equals(user.key); final MenuItem mentionItem = menu.findItem(R.id.mention); if (mentionItem != null) { final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); @@ -975,7 +977,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener case R.id.block: { if (userRelationship == null) return true; if (userRelationship.relationship.isSourceBlockingTarget()) { - twitter.destroyBlockAsync(user.account_key, user.id); + twitter.destroyBlockAsync(user.account_key, user.key.getId()); } else { CreateUserBlockDialogFragment.show(getFragmentManager(), user); } @@ -989,8 +991,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener if (userRelationship == null) return true; final ContentResolver cr = getContentResolver(); if (userRelationship.isFiltering) { - final Expression where = Expression.equals(Filters.Users.USER_ID, user.id); - cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null); + final String where = Expression.equalsArgs(Filters.Users.USER_ID).getSQL(); + final String[] whereArgs = {user.key.toString()}; + cr.delete(Filters.Users.CONTENT_URI, where, whereArgs); Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false); } else { cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user)); @@ -1001,7 +1004,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener case R.id.mute_user: { if (userRelationship == null) return true; if (userRelationship.relationship.isSourceMutingTarget()) { - twitter.destroyMuteAsync(user.account_key, user.id); + twitter.destroyMuteAsync(user.account_key, user.key.getId()); } else { CreateUserMuteDialogFragment.show(getFragmentManager(), user); } @@ -1020,7 +1023,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION); builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_key)); - builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id)); + builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.key)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentialsUtils.getCredentials(getActivity(), user.account_key)); intent.putExtra(EXTRA_USER, user); @@ -1029,19 +1032,19 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } case R.id.set_color: { final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class); - intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.id, true)); + intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.key, true)); intent.putExtra(EXTRA_ALPHA_SLIDER, false); intent.putExtra(EXTRA_CLEAR_BUTTON, true); startActivityForResult(intent, REQUEST_SET_COLOR); break; } case R.id.clear_nickname: { - mUserColorNameManager.clearUserNickname(user.id); + mUserColorNameManager.clearUserNickname(user.key); break; } case R.id.set_nickname: { - final String nick = mUserColorNameManager.getUserNickname(user.id, true); - SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick); + final String nick = mUserColorNameManager.getUserNickname(user.key, true); + SetUserNicknameDialogFragment.show(getFragmentManager(), user.key, nick); break; } case R.id.add_to_list: { @@ -1063,13 +1066,15 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener case R.id.follow: { if (userRelationship == null) return true; final boolean isFollowing = userRelationship.relationship.isSourceFollowingTarget(); - final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_key, user.id); - final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_key, user.id); + final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_key, + user.key.getId()); + final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_key, + user.key.getId()); if (!isCreatingFriendship && !isDestroyingFriendship) { if (isFollowing) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { - twitter.createFriendshipAsync(user.account_key, user.id); + twitter.createFriendshipAsync(user.account_key, user.key.getId()); } } return true; @@ -1078,7 +1083,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final boolean newState = !item.isChecked(); final FriendshipUpdate update = new FriendshipUpdate(); update.retweets(newState); - twitter.updateFriendship(user.account_key, user.id, update); + twitter.updateFriendship(user.account_key, user.key.getId(), update); item.setChecked(newState); return true; } @@ -1280,7 +1285,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener break; } case R.id.follow: { - if (user.account_key.isAccount(user.id, user.user_host)) { + if (user.account_key.equals(user.key)) { Utils.openProfileEditor(getActivity(), user.account_key); break; } @@ -1288,11 +1293,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final AsyncTwitterWrapper twitter = mTwitterWrapper; if (userRelationship == null || twitter == null) return; if (userRelationship.relationship.isSourceBlockingTarget()) { - twitter.destroyBlockAsync(user.account_key, user.id); + twitter.destroyBlockAsync(user.account_key, user.key.getId()); } else if (userRelationship.relationship.isSourceFollowingTarget()) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { - twitter.createFriendshipAsync(user.account_key, user.id); + twitter.createFriendshipAsync(user.account_key, user.key.getId()); } break; } @@ -1314,19 +1319,22 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener break; } case R.id.listed_container: { - IntentUtils.openUserLists(getActivity(), user.account_key, user.id, user.screen_name); + IntentUtils.openUserLists(getActivity(), user.account_key, user.key.getId(), + user.screen_name); break; } case R.id.followers_container: { - IntentUtils.openUserFollowers(getActivity(), user.account_key, user.id, user.screen_name); + IntentUtils.openUserFollowers(getActivity(), user.account_key, user.key.getId(), + user.screen_name); break; } case R.id.friends_container: { - IntentUtils.openUserFriends(getActivity(), user.account_key, user.id, user.screen_name); + IntentUtils.openUserFriends(getActivity(), user.account_key, user.key.getId(), + user.screen_name); break; } case R.id.name_container: { - if (user.account_key.isAccount(user.id, user.user_host)) return; + if (user.account_key.equals(user.key)) return; Utils.openProfileEditor(getActivity(), user.account_key); break; } @@ -1341,7 +1349,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } @Override - public void onLinkClick(final String link, final String orig, final AccountKey accountKey, long extraId, final int type, + public void onLinkClick(final String link, final String orig, final UserKey accountKey, long extraId, final int type, final boolean sensitive, int start, int end) { final ParcelableUser user = getUser(); if (user == null) return; @@ -1382,14 +1390,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } @Override - public void onUserNicknameChanged(long userId, String nick) { - if (mUser == null || mUser.id != userId) return; + public void onUserNicknameChanged(@NonNull UserKey userId, String nick) { + if (mUser == null || !mUser.key.equals(userId)) return; displayUser(mUser); } @Override - public void onUserColorChanged(long userId, int color) { - if (mUser == null || mUser.id != userId) return; + public void onUserColorChanged(@NonNull UserKey userId, int color) { + if (mUser == null || !mUser.key.equals(userId)) return; displayUser(mUser); } @@ -1439,7 +1447,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener lm.destroyLoader(LOADER_ID_FRIENDSHIP); final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key); - args.putLong(EXTRA_USER_ID, user.id); + args.putLong(EXTRA_USER_ID, user.key.getId()); if (!mGetFriendShipLoaderInitialized) { lm.initLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks); mGetFriendShipLoaderInitialized = true; @@ -1451,7 +1459,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_key, user.id, user.screen_name, omitIntentExtra); + getUserInfo(user.account_key, user.key.getId(), user.screen_name, omitIntentExtra); } private void setUiColor(int color) { @@ -1516,15 +1524,13 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener private void setupUserPages() { final Context context = getActivity(); final Bundle args = getArguments(), tabArgs = new Bundle(); - final AccountKey accountId; final ParcelableUser user = args.getParcelable(EXTRA_USER); if (user != null) { - tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, accountId = user.account_key); - tabArgs.putLong(EXTRA_USER_ID, user.id); + tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key); + tabArgs.putLong(EXTRA_USER_ID, user.key.getId()); tabArgs.putString(EXTRA_SCREEN_NAME, user.screen_name); } else { - accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); - tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, accountId); + tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, args.getParcelable(EXTRA_ACCOUNT_KEY)); tabArgs.putLong(EXTRA_USER_ID, args.getLong(EXTRA_USER_ID, -1)); tabArgs.putString(EXTRA_SCREEN_NAME, args.getString(EXTRA_SCREEN_NAME)); } @@ -1551,11 +1557,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } final LoaderManager lm = getLoaderManager(); final boolean loadingRelationship = lm.getLoader(LOADER_ID_FRIENDSHIP) != null; - final AccountKey accountKey = user.account_key; - final boolean creatingFriendship = twitter.isCreatingFriendship(accountKey, user.id); - final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.id); - final boolean creatingBlock = twitter.isCreatingFriendship(accountKey, user.id); - final boolean destroyingBlock = twitter.isDestroyingFriendship(accountKey, user.id); + final UserKey accountKey = user.account_key; + final boolean creatingFriendship = twitter.isCreatingFriendship(accountKey, user.key.getId()); + final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.key.getId()); + final boolean creatingBlock = twitter.isCreatingFriendship(accountKey, user.key.getId()); + final boolean destroyingBlock = twitter.isDestroyingFriendship(accountKey, user.key.getId()); if (loadingRelationship || creatingFriendship || destroyingFriendship || creatingBlock || destroyingBlock) { mFollowButton.setVisibility(View.GONE); mFollowProgress.setVisibility(View.VISIBLE); @@ -1572,9 +1578,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final ParcelableUser user = getUser(); final AsyncTwitterWrapper twitter = mTwitterWrapper; if (user == null || twitter == null) return; - final AccountKey accountKey = user.account_key; - final boolean isCreatingFriendship = twitter.isCreatingFriendship(accountKey, user.id); - final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.id); + final UserKey accountKey = user.account_key; + final boolean isCreatingFriendship = twitter.isCreatingFriendship(accountKey, user.key.getId()); + final boolean destroyingFriendship = twitter.isDestroyingFriendship(accountKey, user.key.getId()); setProgressBarIndeterminateVisibility(isCreatingFriendship || destroyingFriendship); invalidateOptionsMenu(); } @@ -1750,10 +1756,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener static class UserRelationshipLoader extends AsyncTaskLoader> { private final Context context; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public UserRelationshipLoader(final Context context, @NonNull final AccountKey accountKey, + public UserRelationshipLoader(final Context context, @Nullable final UserKey accountKey, final long userId) { super(context); this.context = context; @@ -1763,17 +1769,23 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Override public SingleResponse loadInBackground() { + if (mAccountKey == null) { + return SingleResponse.getInstance(new TwitterException("No Account")); + } final boolean isFiltering = DataStoreUtils.isFilteringUser(context, mUserId); if (mAccountKey.getId() == mUserId) return SingleResponse.getInstance(); final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, mAccountKey, false); - if (twitter == null) return SingleResponse.getInstance(); + if (twitter == null) { + return SingleResponse.getInstance(new TwitterException("No Account")); + } try { final Relationship relationship = twitter.showFriendship(mUserId); + final UserKey userKey = new UserKey(mUserId, mAccountKey.getHost()); if (relationship.isSourceBlockingTarget() || relationship.isSourceBlockedByTarget()) { - Utils.setLastSeen(context, mUserId, -1); + Utils.setLastSeen(context, userKey, -1); } else { - Utils.setLastSeen(context, mUserId, System.currentTimeMillis()); + Utils.setLastSeen(context, userKey, System.currentTimeMillis()); } Utils.updateRelationship(context, relationship, mAccountKey); return SingleResponse.getInstance(new UserRelationship(relationship, isFiltering)); @@ -1800,7 +1812,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener public boolean check(@NonNull ParcelableUser user) { return relationship.getSourceUserId() == user.account_key.getId() - && relationship.getTargetUserId() == user.id; + && user.key.check(relationship.getTargetUserId(), null); } } @@ -1817,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_key, user.id, args.second))); + new CachedRelationship(user.account_key, user.key.getId(), args.second))); return null; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFriendsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFriendsFragment.java index b89da0e57..cf2d47dfd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFriendsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFriendsFragment.java @@ -25,14 +25,14 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.UserFriendsLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class UserFriendsFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final UserFriendsLoader loader = new UserFriendsLoader(context, accountKey, userId, diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java index 5123ef56d..0e017eaf1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListFragment.java @@ -68,10 +68,10 @@ import org.mariotaku.twidere.api.twitter.model.UserListUpdate; import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback; import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback; import org.mariotaku.twidere.graphic.EmptyDrawable; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.SingleResponse; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableUserListUtils; import org.mariotaku.twidere.text.validator.UserListNameValidator; import org.mariotaku.twidere.util.AsyncTwitterWrapper; @@ -177,9 +177,9 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList if (resultCode == Activity.RESULT_OK) { if (data == null || !data.hasExtra(EXTRA_ID)) return; final ParcelableUserList userList = mUserList; - final AccountKey accountKey = data.getParcelableExtra(EXTRA_KEY); + final UserKey accountKey = data.getParcelableExtra(EXTRA_KEY); IntentUtils.openUserListDetails(getActivity(), accountKey, userList.id, - userList.user_id, userList.user_screen_name, userList.name); + userList.user_key.getId(), userList.user_screen_name, userList.name); } break; } @@ -256,7 +256,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList MenuUtils.setMenuItemAvailability(menu, R.id.info, userList != null); menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION); if (userList != null) { - final boolean isMyList = userList.user_id == userList.account_key.getId(); + final boolean isMyList = userList.user_key.equals(userList.account_key); final boolean isFollowing = userList.is_following; MenuUtils.setMenuItemAvailability(menu, R.id.edit, isMyList); MenuUtils.setMenuItemAvailability(menu, R.id.follow, !isMyList); @@ -289,7 +289,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList if (twitter == null || userList == null) return false; switch (item.getItemId()) { case R.id.add: { - if (userList.user_id != userList.account_key.getId()) return false; + if (!userList.user_key.equals(userList.account_key)) return false; final Intent intent = new Intent(INTENT_ACTION_SELECT_USER); intent.setClass(getActivity(), UserListSelectorActivity.class); intent.putExtra(EXTRA_ACCOUNT_KEY, userList.account_key); @@ -297,7 +297,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList break; } case R.id.delete: { - if (userList.user_id != userList.account_key.getId()) return false; + if (!userList.user_key.equals(userList.account_key)) return false; DestroyUserListDialogFragment.show(getFragmentManager(), userList); break; } @@ -353,8 +353,8 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList case R.id.profile_image: { final ParcelableUserList userList = mUserList; if (userList == null) return; - IntentUtils.openUserProfile(getActivity(), userList.account_key, userList.user_id, - userList.user_screen_name, null, true, null); + IntentUtils.openUserProfile(getActivity(), userList.account_key, + userList.user_key.getId(), userList.user_screen_name, null, true, null); break; } } @@ -364,7 +364,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList @Override public Loader> onCreateLoader(final int id, final Bundle args) { setProgressBarIndeterminateVisibility(true); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final long listId = args.getLong(EXTRA_LIST_ID, -1); final String listName = args.getString(EXTRA_LIST_NAME); @@ -406,7 +406,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList final ParcelableUserList userList = args.getParcelable(EXTRA_USER_LIST); assert userList != null; tabArgs.putParcelable(EXTRA_ACCOUNT_KEY, userList.account_key); - tabArgs.putLong(EXTRA_USER_ID, userList.user_id); + tabArgs.putLong(EXTRA_USER_ID, userList.user_key.getId()); tabArgs.putString(EXTRA_SCREEN_NAME, userList.user_screen_name); tabArgs.putLong(EXTRA_LIST_ID, userList.id); tabArgs.putString(EXTRA_LIST_NAME, userList.name); @@ -439,7 +439,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList DialogInterface.OnClickListener { private String mName, mDescription; - private AccountKey mAccountKey; + private UserKey mAccountKey; private long mListId; private boolean mIsPublic; @@ -470,7 +470,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Bundle bundle = savedInstanceState == null ? getArguments() : savedInstanceState; - mAccountKey = bundle != null ? bundle.getParcelable(EXTRA_ACCOUNT_KEY) : null; + mAccountKey = bundle != null ? bundle.getParcelable(EXTRA_ACCOUNT_KEY) : null; mListId = bundle != null ? bundle.getLong(EXTRA_LIST_ID, -1) : -1; mName = bundle != null ? bundle.getString(EXTRA_LIST_NAME) : null; mDescription = bundle != null ? bundle.getString(EXTRA_DESCRIPTION) : null; @@ -520,13 +520,13 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList private final boolean mOmitIntentExtra; private final Bundle mExtras; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; private final long mListId; private final String mScreenName, mListName; private ParcelableUserListLoader(final Context context, final boolean omitIntentExtra, final Bundle extras, - final AccountKey accountKey, final long listId, final String listName, final long userId, + final UserKey accountKey, final long listId, final String listName, final long userId, final String screenName) { super(context); mOmitIntentExtra = omitIntentExtra; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembersFragment.java index bb3f6e473..e176122d0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembersFragment.java @@ -33,7 +33,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.UserListMembersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.model.util.ParcelableUserListUtils; @@ -62,7 +62,7 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { final long listId = args.getLong(EXTRA_LIST_ID, -1); - final AccountKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final String listName = args.getString(EXTRA_LIST_NAME); @@ -83,7 +83,7 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment { super.onActivityCreated(savedInstanceState); if (mUserList == null && args != null) { final long listId = args.getLong(EXTRA_LIST_ID, -1); - final AccountKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountId = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final String listName = args.getString(EXTRA_LIST_NAME); @@ -113,12 +113,12 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment { private class GetUserListTask extends AsyncTask> { @Nullable - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; private final long mListId; private final String mScreenName, mListName; - private GetUserListTask(@Nullable final AccountKey accountKey, final long listId, + private GetUserListTask(@Nullable final UserKey accountKey, final long listId, final String listName, final long userId, final String screenName) { this.mAccountKey = accountKey; this.mUserId = userId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembershipsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembershipsFragment.java index 631e41bd5..22fdf92b1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembershipsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListMembershipsFragment.java @@ -24,7 +24,7 @@ import android.os.Bundle; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.UserListMembershipsLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import java.util.List; @@ -34,7 +34,7 @@ public class UserListMembershipsFragment extends ParcelableUserListsFragment { @Override public Loader> onCreateUserListsLoader(final Context context, final Bundle args, final boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final long cursor = args.getLong(EXTRA_NEXT_CURSOR, -1); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListSubscribersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListSubscribersFragment.java index 9d9362ffe..7ed5772a5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListSubscribersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListSubscribersFragment.java @@ -25,14 +25,14 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.loader.support.CursorSupportUsersLoader; import org.mariotaku.twidere.loader.support.UserListSubscribersLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; public class UserListSubscribersFragment extends CursorSupportUsersListFragment { @Override public CursorSupportUsersLoader onCreateUsersLoader(final Context context, @NonNull final Bundle args, boolean fromUser) { final long listId = args.getLong(EXTRA_LIST_ID, -1); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final String listName = args.getString(EXTRA_LIST_NAME); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListTimelineFragment.java index 38d44b3f8..7560d75d4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListTimelineFragment.java @@ -25,7 +25,7 @@ import android.support.annotation.NonNull; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.UserListTimelineLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.util.List; @@ -51,7 +51,7 @@ public class UserListTimelineFragment extends ParcelableStatusesFragment { setRefreshing(true); if (args == null) return null; final long listId = args.getLong(EXTRA_LIST_ID, -1); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final long userId = args.getLong(EXTRA_USER_ID, -1); @@ -67,7 +67,7 @@ public class UserListTimelineFragment extends ParcelableStatusesFragment { final Bundle args = getArguments(); assert args != null; final long listId = args.getLong(EXTRA_LIST_ID, -1); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); final String listName = args.getString(EXTRA_LIST_NAME); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java index 9400d4fcc..aa10c12ec 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserListsFragment.java @@ -32,7 +32,7 @@ import com.squareup.otto.Subscribe; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.AbsUserListsAdapter; import org.mariotaku.twidere.loader.support.UserListsLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.message.UserListDestroyedEvent; import org.mariotaku.twidere.util.MenuUtils; @@ -45,7 +45,7 @@ public class UserListsFragment extends ParcelableUserListsFragment { @Override public Loader> onCreateUserListsLoader(final Context context, final Bundle args, final boolean fromUser) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); return new UserListsLoader(getActivity(), accountKey, userId, screenName, true, getData()); @@ -80,7 +80,7 @@ public class UserListsFragment extends ParcelableUserListsFragment { @Override public void onPrepareOptionsMenu(final Menu menu) { final MenuItem item = menu.findItem(R.id.new_user_list); - final AccountKey accountId = getAccountKey(); + final UserKey accountId = getAccountKey(); if (accountId == null || item == null) return; final long userId = getUserId(); if (accountId.getId() == userId) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java index 2b0a8dc68..0bb341ec4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java @@ -19,7 +19,7 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosi import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.loader.iface.IExtendedLoader; import org.mariotaku.twidere.loader.support.MediaTimelineLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.IntentUtils; @@ -98,7 +98,7 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment> onCreateLoader(int id, Bundle args) { final Context context = getActivity(); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final long userId = args.getLong(EXTRA_USER_ID, -1); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMentionsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMentionsFragment.java index af13d5f81..5de3c6781 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMentionsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMentionsFragment.java @@ -25,7 +25,7 @@ import android.support.annotation.NonNull; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.UserMentionsLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.util.List; @@ -40,7 +40,7 @@ public class UserMentionsFragment extends StatusesSearchFragment { final boolean fromUser) { if (args == null) return null; final String screenName = args.getString(EXTRA_SCREEN_NAME); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final int tabPosition = args.getInt(EXTRA_TAB_POSITION, -1); @@ -53,7 +53,7 @@ public class UserMentionsFragment extends StatusesSearchFragment { protected String[] getSavedStatusesFileArgs() { final Bundle args = getArguments(); if (args == null) return null; - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final String screen_name = args.getString(EXTRA_SCREEN_NAME); return new String[]{AUTHORITY_USER_MENTIONS, "account" + accountKey, "screen_name" + screen_name}; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserProfileEditorFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserProfileEditorFragment.java index 76514f45e..35bd284e0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserProfileEditorFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserProfileEditorFragment.java @@ -58,9 +58,9 @@ import org.mariotaku.twidere.api.twitter.model.ProfileUpdate; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.fragment.iface.IBaseFragment; import org.mariotaku.twidere.loader.support.ParcelableUserLoader; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.SingleResponse; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableUserUtils; import org.mariotaku.twidere.util.AsyncTaskUtils; import org.mariotaku.twidere.util.AsyncTwitterWrapper.UpdateProfileBannerImageTask; @@ -104,7 +104,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On private View mEditProfileBanner; private View mSetLinkColor, mSetBackgroundColor; private ForegroundColorView mLinkColor, mBackgroundColor; - private AccountKey mAccountId; + private UserKey mAccountId; private ParcelableUser mUser; private boolean mUserInfoLoaderInitialized; private boolean mGetUserInfoCalled; @@ -174,7 +174,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On @Override public void onLoadFinished(final Loader> loader, final SingleResponse data) { - if (data.getData() != null && data.getData().id > 0) { + if (data.getData() != null && data.getData().key != null) { displayUser(data.getData()); } else if (mUser == null) { } @@ -215,7 +215,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); final Bundle args = getArguments(); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); mAccountId = accountKey; if (!Utils.isMyAccount(getActivity(), accountKey)) { getActivity().finish(); @@ -420,7 +420,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On private final Handler mHandler; // Data fields - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final ParcelableUser mOriginal; private final String mName; private final String mUrl; @@ -430,7 +430,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On private final int mBackgroundColor; public UpdateProfileTaskInternal(final UserProfileEditorFragment fragment, - final AccountKey accountKey, final ParcelableUser original, + final UserKey accountKey, final ParcelableUser original, final String name, final String url, final String location, final String description, final int linkColor, final int backgroundColor) { @@ -512,9 +512,9 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On class RemoveProfileBannerTaskInternal extends AsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; - RemoveProfileBannerTaskInternal(final AccountKey accountKey) { + RemoveProfileBannerTaskInternal(final UserKey accountKey) { this.mAccountKey = accountKey; } @@ -546,7 +546,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On private class UpdateProfileBannerImageTaskInternal extends UpdateProfileBannerImageTask { - public UpdateProfileBannerImageTaskInternal(final Context context, final AccountKey accountKey, + public UpdateProfileBannerImageTaskInternal(final Context context, final UserKey accountKey, final Uri imageUri, final boolean deleteImage) { super(context, accountKey, imageUri, deleteImage); } @@ -568,7 +568,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On private class UpdateProfileImageTaskInternal extends UpdateProfileImageTask { - public UpdateProfileImageTaskInternal(final Context context, final AccountKey accountKey, + public UpdateProfileImageTaskInternal(final Context context, final UserKey accountKey, final Uri imageUri, final boolean deleteImage) { super(context, accountKey, imageUri, deleteImage); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserTimelineFragment.java index 98d3e8b44..ee5828f90 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserTimelineFragment.java @@ -25,7 +25,7 @@ import android.support.annotation.NonNull; import android.support.v4.content.Loader; import org.mariotaku.twidere.loader.support.UserTimelineLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.util.List; @@ -50,7 +50,7 @@ public class UserTimelineFragment extends ParcelableStatusesFragment { final boolean fromUser) { setRefreshing(true); final List data = getAdapterData(); - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long maxId = args.getLong(EXTRA_MAX_ID, -1); final long sinceId = args.getLong(EXTRA_SINCE_ID, -1); final long userId = args.getLong(EXTRA_USER_ID, -1); @@ -64,7 +64,7 @@ public class UserTimelineFragment extends ParcelableStatusesFragment { protected String[] getSavedStatusesFileArgs() { final Bundle args = getArguments(); if (args == null) return null; - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); final long userId = args.getLong(EXTRA_USER_ID, -1); final String screenName = args.getString(EXTRA_SCREEN_NAME); return new String[]{AUTHORITY_USER_TIMELINE, "account" + accountKey, "user" + userId + "name" + screenName}; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/card/CardPollFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/card/CardPollFragment.java index bffead0c5..297358c23 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/card/CardPollFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/card/CardPollFragment.java @@ -51,9 +51,9 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.CardDataMap; import org.mariotaku.twidere.api.twitter.model.CardEntity; import org.mariotaku.twidere.fragment.support.BaseSupportFragment; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCardEntity; import org.mariotaku.twidere.model.ParcelableStatus; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableCardEntityUtils; import org.mariotaku.twidere.task.AbstractTask; import org.mariotaku.twidere.task.util.TaskStarter; @@ -138,7 +138,7 @@ public class CardPollFragment extends BaseSupportFragment implements final int selectedChoice = ParcelableCardEntityUtils.getAsInteger(card, "selected_choice", -1); final Date endDatetimeUtc = ParcelableCardEntityUtils.getAsDate(card, "end_datetime_utc", new Date()); final boolean hasChoice = selectedChoice != -1; - final boolean isMyPoll = status.account_key.getId() == status.user_id; + final boolean isMyPoll = status.account_key.equals(status.user_key); final boolean showResult = countsAreFinal || isMyPoll || hasChoice; for (int i = 0; i < choicesCount; i++) { final int choiceIndex = i + 1; @@ -327,11 +327,11 @@ public class CardPollFragment extends BaseSupportFragment implements } public static class ParcelableCardEntityLoader extends AsyncTaskLoader { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final String mCardUri; private final String mCardName; - public ParcelableCardEntityLoader(Context context, AccountKey accountKey, + public ParcelableCardEntityLoader(Context context, UserKey accountKey, String cardUri, String cardName) { super(context); mAccountKey = accountKey; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java index 81c3a9f29..eabfefe5b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java @@ -24,7 +24,7 @@ import android.content.SharedPreferences; import org.mariotaku.twidere.api.twitter.model.CursorSupport; import org.mariotaku.twidere.loader.support.iface.ICursorSupportLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -38,7 +38,7 @@ public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader private long mNextCursor, mPrevCursor; - public BaseCursorSupportUsersLoader(final Context context, final AccountKey accountKey, + public BaseCursorSupportUsersLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); final SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseUserListsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseUserListsLoader.java index 22cc6bba4..d73a0e2d7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseUserListsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseUserListsLoader.java @@ -30,7 +30,7 @@ import org.mariotaku.twidere.api.twitter.model.CursorSupport; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.loader.support.iface.ICursorSupportLoader; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import org.mariotaku.twidere.model.util.ParcelableUserListUtils; import org.mariotaku.twidere.util.TwitterAPIFactory; @@ -44,12 +44,12 @@ public abstract class BaseUserListsLoader extends AsyncTaskLoader mData = new NoDuplicatesArrayList<>(); - protected final AccountKey mAccountId; + protected final UserKey mAccountId; private final long mCursor; private long mNextCursor, mPrevCursor; - public BaseUserListsLoader(final Context context, final AccountKey accountKey, final long cursor, + public BaseUserListsLoader(final Context context, final UserKey accountKey, final long cursor, final List data) { super(context); if (data != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java index c1ae27f51..5c1995bc4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ConversationLoader.java @@ -46,6 +46,7 @@ public class ConversationLoader extends TwitterAPIStatusesLoader { @NonNull private final ParcelableStatus mStatus; + private boolean mCanLoadAllReplies; public ConversationLoader(final Context context, @NonNull final ParcelableStatus status, final long sinceId, final long maxId, final List data, @@ -58,12 +59,15 @@ public class ConversationLoader extends TwitterAPIStatusesLoader { @NonNull @Override public List getStatuses(@NonNull final Twitter twitter, final Paging paging) throws TwitterException { + mCanLoadAllReplies = false; final ParcelableStatus status = mStatus; final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(getContext(), getAccountKey()); if (credentials == null) throw new TwitterException("Null credentials"); if (Utils.isOfficialCredentials(getContext(), credentials)) { + mCanLoadAllReplies = true; return twitter.showConversation(status.id, paging); - } else if (!TwitterAPIFactory.isTwitterCredentials(credentials)) { + } else if (TwitterAPIFactory.isStatusNetCredentials(credentials)) { + mCanLoadAllReplies = true; return twitter.getStatusNetConversation(status.id, paging); } final List statuses = new ArrayList<>(); @@ -102,6 +106,10 @@ public class ConversationLoader extends TwitterAPIStatusesLoader { return statuses; } + public boolean canLoadAllReplies() { + return mCanLoadAllReplies; + } + @WorkerThread @Override protected boolean shouldFilterStatus(SQLiteDatabase database, ParcelableStatus status) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/CursorSupportUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/CursorSupportUsersLoader.java index f16007532..66bd3616e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/CursorSupportUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/CursorSupportUsersLoader.java @@ -28,14 +28,14 @@ import org.mariotaku.twidere.api.twitter.model.CursorSupport; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; public abstract class CursorSupportUsersLoader extends BaseCursorSupportUsersLoader { - public CursorSupportUsersLoader(final Context context, final AccountKey accountKey, + public CursorSupportUsersLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/IDsUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/IDsUsersLoader.java index 8274598f5..21d1dc006 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/IDsUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/IDsUsersLoader.java @@ -27,14 +27,14 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.IDs; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; public abstract class IDsUsersLoader extends BaseCursorSupportUsersLoader { - public IDsUsersLoader(final Context context, final AccountKey accountKey, + public IDsUsersLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/IncomingFriendshipsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/IncomingFriendshipsLoader.java index 17d3c5cb6..20154f651 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/IncomingFriendshipsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/IncomingFriendshipsLoader.java @@ -26,14 +26,14 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.IDs; import org.mariotaku.twidere.api.twitter.model.Paging; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; public class IncomingFriendshipsLoader extends IDsUsersLoader { - public IncomingFriendshipsLoader(final Context context, final AccountKey accountKey, + public IncomingFriendshipsLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MediaTimelineLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MediaTimelineLoader.java index f072f5f2d..667dc2e3c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MediaTimelineLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MediaTimelineLoader.java @@ -31,9 +31,9 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SearchQuery; import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils; import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.InternalTwitterContentUtils; @@ -51,7 +51,7 @@ public class MediaTimelineLoader extends TwitterAPIStatusesLoader { private User mUser; - public MediaTimelineLoader(final Context context, final AccountKey accountKey, final long userId, + public MediaTimelineLoader(final Context context, final UserKey accountKey, final long userId, final String screenName, final long sinceId, final long maxId, final List data, final String[] savedStatusesArgs, final int tabPosition, final boolean fromUser) { @@ -103,9 +103,9 @@ public class MediaTimelineLoader extends TwitterAPIStatusesLoader { @WorkerThread @Override protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) { - final long retweetUserId = status.is_retweet ? status.user_id : -1; + final UserKey retweetUserId = status.is_retweet ? status.user_key : null; return !isMyTimeline() && InternalTwitterContentUtils.isFiltered(database, retweetUserId, status.text_plain, - status.text_html, status.source, -1, status.quoted_user_id); + status.text_html, status.source, null, status.quoted_user_id); } private boolean isMyTimeline() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java index 6845c0371..870e66eab 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/MutesUsersLoader.java @@ -22,7 +22,7 @@ package org.mariotaku.twidere.loader.support; import android.content.Context; import android.support.annotation.NonNull; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -35,7 +35,7 @@ import org.mariotaku.twidere.api.twitter.model.User; public class MutesUsersLoader extends CursorSupportUsersLoader { - public MutesUsersLoader(final Context context, final AccountKey accountKey, + public MutesUsersLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java index 7d46d5ff5..d84f15f98 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ParcelableStatusLoader.java @@ -25,7 +25,7 @@ import android.support.v4.content.AsyncTaskLoader; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.constant.IntentConstants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.SingleResponse; @@ -41,11 +41,11 @@ public class ParcelableStatusLoader extends AsyncTaskLoader loadInBackground() { final Context context = getContext(); final ContentResolver resolver = context.getContentResolver(); - final AccountKey accountKey = mAccountKey; + final UserKey accountKey = mAccountKey; final int accountColor = DataStoreUtils.getAccountColor(context, accountKey); if (!mOmitIntentExtra && mExtras != null) { final ParcelableUser user = mExtras.getParcelable(EXTRA_USER); @@ -89,7 +89,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader 0) { - where = Expression.equals(CachedUsers.USER_ID, mUserId); + where = Expression.equals(CachedUsers.USER_KEY, mUserId); whereArgs = null; } else { where = Expression.equalsArgs(CachedUsers.SCREEN_NAME); @@ -117,8 +117,7 @@ public final class ParcelableUserLoader extends AsyncTaskLoader data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) { @@ -54,7 +54,7 @@ public class RetweetsOfMeLoader extends TwitterAPIStatusesLoader { @WorkerThread @Override protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) { - return InternalTwitterContentUtils.isFiltered(database, -1, status.text_plain, status.text_html, status.source, - status.retweeted_by_user_id, status.quoted_user_id); + return InternalTwitterContentUtils.isFiltered(database, null, status.text_plain, + status.text_html, status.source, status.retweeted_by_user_id, status.quoted_user_id); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java index fe3159f88..6e11fc712 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/SavedSearchesLoader.java @@ -27,16 +27,16 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.TwitterAPIFactory; import static org.mariotaku.twidere.TwidereConstants.LOGTAG; public class SavedSearchesLoader extends AsyncTaskLoader> { - private final AccountKey mAccountId; + private final UserKey mAccountId; - public SavedSearchesLoader(final Context context, final AccountKey accountKey) { + public SavedSearchesLoader(final Context context, final UserKey accountKey) { super(context); mAccountId = accountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java index d54bf68e3..96be2b5df 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/ScheduledStatusesLoader.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ScheduledStatus; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.TwitterAPIFactory; import java.util.List; @@ -36,13 +36,13 @@ import java.util.List; */ public class ScheduledStatusesLoader extends AsyncTaskLoader> { - private final AccountKey mAccountId; + private final UserKey mAccountId; private final long mSinceId; private final long mMaxId; @ScheduledStatus.State private final String[] mStates; - public ScheduledStatusesLoader(Context context, AccountKey accountId, long sinceId, long maxId, + public ScheduledStatusesLoader(Context context, UserKey accountId, long sinceId, long maxId, @ScheduledStatus.State String[] states, List data) { super(context); mAccountId = accountId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusFavoritersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusFavoritersLoader.java index 637553cff..999b88a79 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusFavoritersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusFavoritersLoader.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.IDs; import org.mariotaku.twidere.api.twitter.model.Paging; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -35,7 +35,7 @@ public class StatusFavoritersLoader extends IDsUsersLoader { private final long mStatusId; - public StatusFavoritersLoader(final Context context, final AccountKey accountKey, final long statusId, + public StatusFavoritersLoader(final Context context, final UserKey accountKey, final long statusId, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); mStatusId = statusId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusRetweetersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusRetweetersLoader.java index 6c0505c6b..7f5c99077 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusRetweetersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/StatusRetweetersLoader.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.IDs; import org.mariotaku.twidere.api.twitter.model.Paging; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -35,7 +35,7 @@ public class StatusRetweetersLoader extends IDsUsersLoader { private final long mStatusId; - public StatusRetweetersLoader(final Context context, final AccountKey accountKey, final long statusId, + public StatusRetweetersLoader(final Context context, final UserKey accountKey, final long statusId, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); mStatusId = statusId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TweetSearchLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TweetSearchLoader.java index 9fc6004f7..fe04ff6c2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TweetSearchLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TweetSearchLoader.java @@ -29,7 +29,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.SearchQuery; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import org.mariotaku.twidere.util.TwitterAPIFactory; @@ -42,7 +42,7 @@ public class TweetSearchLoader extends TwitterAPIStatusesLoader { private final String mQuery; private final boolean mGapEnabled; - public TweetSearchLoader(final Context context, final AccountKey accountKey, @NonNull final String query, + public TweetSearchLoader(final Context context, final UserKey accountKey, @NonNull final String query, final long sinceId, final long maxId, final List data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser, boolean makeGap) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java index 31dfa6699..e19d0f950 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java @@ -37,7 +37,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.app.TwidereApplication; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ListResponse; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableStatus; @@ -69,7 +69,7 @@ import javax.inject.Inject; public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mMaxId, mSinceId; @Nullable private final Object[] mSavedStatusesFileArgs; @@ -80,7 +80,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader SharedPreferencesWrapper mPreferences; public TwitterAPIStatusesLoader(@NonNull final Context context, - @Nullable final AccountKey accountKey, + @Nullable final UserKey accountKey, final long sinceId, final long maxId, final List data, @Nullable final String[] savedStatusesArgs, @@ -216,7 +216,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader return mMaxId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java index 4b113e7cc..f279b8d11 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java @@ -27,7 +27,7 @@ import android.util.Log; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ListResponse; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.util.ParcelableUserUtils; @@ -39,9 +39,9 @@ import java.util.List; public abstract class TwitterAPIUsersLoader extends ParcelableUsersLoader { @Nullable - private final AccountKey mAccountKey; + private final UserKey mAccountKey; - public TwitterAPIUsersLoader(final Context context, @Nullable final AccountKey accountKey, + public TwitterAPIUsersLoader(final Context context, @Nullable final UserKey accountKey, final List data, boolean fromUser) { super(context, data, fromUser); mAccountKey = accountKey; @@ -76,7 +76,7 @@ public abstract class TwitterAPIUsersLoader extends ParcelableUsersLoader { } @Nullable - public final AccountKey getAccountId() { + public final UserKey getAccountId() { return mAccountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserBlocksLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserBlocksLoader.java index e4f7feebc..ef29d19dd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserBlocksLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserBlocksLoader.java @@ -27,14 +27,14 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; public class UserBlocksLoader extends CursorSupportUsersLoader { - public UserBlocksLoader(final Context context, final AccountKey accountKey, + public UserBlocksLoader(final Context context, final UserKey accountKey, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFavoritesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFavoritesLoader.java index 0010f7da2..4302a8049 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFavoritesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFavoritesLoader.java @@ -29,7 +29,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import java.util.List; @@ -39,7 +39,7 @@ public class UserFavoritesLoader extends TwitterAPIStatusesLoader { private final long mUserId; private final String mUserScreenName; - public UserFavoritesLoader(final Context context, final AccountKey accountKey, final long userId, + public UserFavoritesLoader(final Context context, final UserKey accountKey, final long userId, final String screenName, final long sinceId, final long maxId, final List data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFollowersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFollowersLoader.java index 3bd6333da..52c59304f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFollowersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFollowersLoader.java @@ -27,7 +27,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.util.DataStoreUtils; @@ -39,7 +39,7 @@ public class UserFollowersLoader extends CursorSupportUsersLoader { private final long mUserId; private final String mScreenName; - public UserFollowersLoader(final Context context, final AccountKey accountId, final long userId, + public UserFollowersLoader(final Context context, final UserKey accountId, final long userId, final String screenName, final List data, final boolean fromUser) { super(context, accountId, data, fromUser); @@ -51,7 +51,7 @@ public class UserFollowersLoader extends CursorSupportUsersLoader { @Override protected ResponseList getCursoredUsers(@NonNull final Twitter twitter, final Paging paging) throws TwitterException { - final AccountKey accountId = getAccountId(); + final UserKey accountId = getAccountId(); if (accountId == null) throw new TwitterException("No account"); final String accountType = DataStoreUtils.getAccountType(getContext(), accountId); if (mUserId > 0) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFriendsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFriendsLoader.java index 81592627e..5c4bdab54 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFriendsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserFriendsLoader.java @@ -27,7 +27,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.util.DataStoreUtils; @@ -39,7 +39,7 @@ public class UserFriendsLoader extends CursorSupportUsersLoader { private final long mUserId; private final String mScreenName; - public UserFriendsLoader(final Context context, final AccountKey accountKey, final long userId, + public UserFriendsLoader(final Context context, final UserKey accountKey, final long userId, final String screenName, final List userList, boolean fromUser) { super(context, accountKey, userList, fromUser); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembersLoader.java index fbe2531d3..4347ec367 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembersLoader.java @@ -27,7 +27,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -38,7 +38,7 @@ public class UserListMembersLoader extends CursorSupportUsersLoader { private final long mUserId; private final String mScreenName, mListName; - public UserListMembersLoader(final Context context, final AccountKey accountKey, final long listId, + public UserListMembersLoader(final Context context, final UserKey accountKey, final long listId, final long userId, final String screenName, final String listName, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembershipsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembershipsLoader.java index 484ef61d6..4a90b8fa8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembershipsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListMembershipsLoader.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.UserList; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import java.util.List; @@ -36,7 +36,7 @@ public class UserListMembershipsLoader extends BaseUserListsLoader { private final long mUserId; private final String mScreenName; - public UserListMembershipsLoader(final Context context, final AccountKey accountKey, + public UserListMembershipsLoader(final Context context, final UserKey accountKey, final long userId, final String screenName, final long cursor, final List data) { super(context, accountKey, cursor, data); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListSubscribersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListSubscribersLoader.java index bcbc7014b..cb67af4e8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListSubscribersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListSubscribersLoader.java @@ -27,7 +27,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -38,7 +38,7 @@ public class UserListSubscribersLoader extends CursorSupportUsersLoader { private final long mUserId; private final String mScreenName, mListName; - public UserListSubscribersLoader(final Context context, final AccountKey accountKey, final long listId, + public UserListSubscribersLoader(final Context context, final UserKey accountKey, final long listId, final long userId, final String screenName, final String listName, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListTimelineLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListTimelineLoader.java index 867f7e27f..0929867b1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListTimelineLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListTimelineLoader.java @@ -29,7 +29,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.InternalTwitterContentUtils; @@ -41,7 +41,7 @@ public class UserListTimelineLoader extends TwitterAPIStatusesLoader { private final String mScreenName, mListName; private final long mListId; - public UserListTimelineLoader(final Context context, final AccountKey accountKey, final long listId, + public UserListTimelineLoader(final Context context, final UserKey accountKey, final long listId, final long userId, final String screenName, final String listName, final long sinceId, final long maxId, final List data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListsLoader.java index 508e2beb3..d6449f9fa 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserListsLoader.java @@ -21,7 +21,7 @@ package org.mariotaku.twidere.loader.support; import android.content.Context; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUserList; import java.util.List; @@ -37,7 +37,7 @@ public class UserListsLoader extends BaseUserListsLoader { private final String mScreenName; private final boolean mReverse; - public UserListsLoader(final Context context, final AccountKey accountKey, final long userId, + public UserListsLoader(final Context context, final UserKey accountKey, final long userId, final String screenName, final boolean reverse, final List data) { super(context, accountKey, 0, data); mUserId = userId; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserMentionsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserMentionsLoader.java index d17c14501..4388c2072 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserMentionsLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserMentionsLoader.java @@ -22,7 +22,7 @@ package org.mariotaku.twidere.loader.support; import android.content.Context; import android.support.annotation.NonNull; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.TwitterAPIFactory; @@ -31,7 +31,7 @@ import java.util.Locale; public class UserMentionsLoader extends TweetSearchLoader { - public UserMentionsLoader(final Context context, final AccountKey accountId, final String screenName, + public UserMentionsLoader(final Context context, final UserKey accountId, final String screenName, final long maxId, final long sinceId, final List data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser, boolean makeGap) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java index 5b3745074..08e5557f4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableUser; import java.util.List; @@ -36,7 +36,7 @@ public class UserSearchLoader extends TwitterAPIUsersLoader { private final String mQuery; private final int mPage; - public UserSearchLoader(final Context context, final AccountKey accountKey, final String query, + public UserSearchLoader(final Context context, final UserKey accountKey, final String query, final int page, final List data, boolean fromUser) { super(context, accountKey, data, fromUser); mQuery = query; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserTimelineLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserTimelineLoader.java index 6e2a92dd4..cdfae3e2f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserTimelineLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserTimelineLoader.java @@ -29,8 +29,8 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableStatus; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import java.util.List; @@ -41,7 +41,7 @@ public class UserTimelineLoader extends TwitterAPIStatusesLoader { private final String mUserScreenName; private final boolean mIsMyTimeline; - public UserTimelineLoader(final Context context, final AccountKey accountId, final long userId, + public UserTimelineLoader(final Context context, final UserKey accountId, final long userId, final String screenName, final long sinceId, final long maxId, final List data, final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) { @@ -66,8 +66,8 @@ public class UserTimelineLoader extends TwitterAPIStatusesLoader { @Override protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) { if (mIsMyTimeline) return false; - final long retweetUserId = status.is_retweet ? status.user_id : -1; + final UserKey retweetUserId = status.is_retweet ? status.user_key : null; return InternalTwitterContentUtils.isFiltered(database, retweetUserId, status.text_plain, - status.text_html, status.source, -1, status.quoted_user_id); + status.text_html, status.source, null, status.quoted_user_id); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/menu/AccountActionProvider.java b/twidere/src/main/java/org/mariotaku/twidere/menu/AccountActionProvider.java index 41557c89d..adf18472c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/menu/AccountActionProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/menu/AccountActionProvider.java @@ -10,7 +10,7 @@ import android.view.View; import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.twidere.TwidereConstants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.util.ParcelableAccountUtils; @@ -20,7 +20,7 @@ public class AccountActionProvider extends ActionProvider implements TwidereCons private ParcelableAccount[] mAccounts; - private AccountKey[] mAccountIds; + private UserKey[] mAccountIds; private boolean mExclusive; public AccountActionProvider(final Context context, final ParcelableAccount[] accounts) { @@ -79,7 +79,7 @@ public class AccountActionProvider extends ActionProvider implements TwidereCons mExclusive = exclusive; } - public void setSelectedAccountIds(final AccountKey... accountIds) { + public void setSelectedAccountIds(final UserKey... accountIds) { mAccountIds = accountIds; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java b/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java index 514eaa076..d54042c5e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java @@ -29,7 +29,7 @@ import android.view.SubMenu; import android.view.View; import org.mariotaku.twidere.TwidereConstants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; public class AccountToggleProvider extends ActionProvider implements TwidereConstants { @@ -53,16 +53,16 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons } @NonNull - public AccountKey[] getActivatedAccountIds() { - if (mAccounts == null) return new AccountKey[0]; - AccountKey[] temp = new AccountKey[mAccounts.length]; + public UserKey[] getActivatedAccountIds() { + if (mAccounts == null) return new UserKey[0]; + UserKey[] temp = new UserKey[mAccounts.length]; int len = 0; for (ParcelableAccount account : mAccounts) { if (account.is_activated) { temp[len++] = account.account_key; } } - final AccountKey[] result = new AccountKey[len]; + final UserKey[] result = new UserKey[len]; System.arraycopy(temp, 0, result, 0, len); return result; } @@ -110,7 +110,7 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons } } - public void setAccountActivated(AccountKey accountId, boolean isChecked) { + public void setAccountActivated(UserKey accountId, boolean isChecked) { if (mAccounts == null) return; for (final ParcelableAccount account : mAccounts) { if (account.account_key == accountId) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/AccountPreferences.java b/twidere/src/main/java/org/mariotaku/twidere/model/AccountPreferences.java index 171d9cae6..98db30d89 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/AccountPreferences.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/AccountPreferences.java @@ -34,17 +34,17 @@ import org.mariotaku.twidere.model.util.ParcelableAccountUtils; public class AccountPreferences implements Constants { private final Context mContext; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final SharedPreferences mPreferences; - public AccountPreferences(final Context context, final AccountKey accountKey) { + public AccountPreferences(final Context context, final UserKey accountKey) { mContext = context; mAccountKey = accountKey; final String name = ACCOUNT_PREFERENCES_NAME_PREFIX + accountKey; mPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE); } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } @@ -130,14 +130,14 @@ public class AccountPreferences implements Constants { return mPreferences.getBoolean(KEY_NOTIFICATION, DEFAULT_NOTIFICATION); } - public static AccountPreferences getAccountPreferences(final AccountPreferences[] prefs, final AccountKey accountKey) { + public static AccountPreferences getAccountPreferences(final AccountPreferences[] prefs, final UserKey accountKey) { for (final AccountPreferences pref : prefs) { if (pref.getAccountKey() == accountKey) return pref; } return null; } - public static AccountPreferences[] getAccountPreferences(final Context context, final AccountKey[] accountKeys) { + public static AccountPreferences[] getAccountPreferences(final Context context, final UserKey[] accountKeys) { if (context == null || accountKeys == null) return null; final AccountPreferences[] preferences = new AccountPreferences[accountKeys.length]; for (int i = 0, j = preferences.length; i < j; i++) { @@ -147,26 +147,26 @@ public class AccountPreferences implements Constants { } @NonNull - public static AccountKey[] getAutoRefreshEnabledAccountIds(final Context context, final AccountKey[] accountKeys) { - if (context == null || accountKeys == null) return new AccountKey[0]; - final AccountKey[] temp = new AccountKey[accountKeys.length]; + public static UserKey[] getAutoRefreshEnabledAccountIds(final Context context, final UserKey[] accountKeys) { + if (context == null || accountKeys == null) return new UserKey[0]; + final UserKey[] temp = new UserKey[accountKeys.length]; int i = 0; - for (final AccountKey accountKey : accountKeys) { + for (final UserKey accountKey : accountKeys) { if (new AccountPreferences(context, accountKey).isAutoRefreshEnabled()) { temp[i++] = accountKey; } } - final AccountKey[] enabledIds = new AccountKey[i]; + final UserKey[] enabledIds = new UserKey[i]; System.arraycopy(temp, 0, enabledIds, 0, i); return enabledIds; } @NonNull - public static AccountPreferences[] getNotificationEnabledPreferences(final Context context, final AccountKey[] accountKeys) { + public static AccountPreferences[] getNotificationEnabledPreferences(final Context context, final UserKey[] accountKeys) { if (context == null || accountKeys == null) return new AccountPreferences[0]; final AccountPreferences[] temp = new AccountPreferences[accountKeys.length]; int i = 0; - for (final AccountKey accountKey : accountKeys) { + for (final UserKey accountKey : accountKeys) { final AccountPreferences preference = new AccountPreferences(context, accountKey); if (preference.isNotificationEnabled()) { temp[i++] = preference; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java b/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java index 0bd556544..d04f4ed00 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/BaseRefreshTaskParam.java @@ -8,13 +8,13 @@ import android.support.annotation.Nullable; */ public class BaseRefreshTaskParam implements RefreshTaskParam { - private final AccountKey[] accountKeys; + private final UserKey[] accountKeys; private final long[] maxIds; private final long[] sinceIds; @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return accountKeys; } @@ -40,7 +40,7 @@ public class BaseRefreshTaskParam implements RefreshTaskParam { return sinceIds != null; } - public BaseRefreshTaskParam(AccountKey[] accountKeys, long[] maxIds, long[] sinceIds) { + public BaseRefreshTaskParam(UserKey[] accountKeys, long[] maxIds, long[] sinceIds) { this.accountKeys = accountKeys; this.maxIds = maxIds; this.sinceIds = sinceIds; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/CachedRelationship.java b/twidere/src/main/java/org/mariotaku/twidere/model/CachedRelationship.java index 6a684a9c0..23cd7212d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/CachedRelationship.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/CachedRelationship.java @@ -14,7 +14,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships; public class CachedRelationship { @CursorField(CachedRelationships.ACCOUNT_KEY) - public AccountKey account_key; + public UserKey account_key; @CursorField(CachedRelationships.USER_ID) public long user_id; @@ -41,7 +41,7 @@ public class CachedRelationship { } - public CachedRelationship(AccountKey accountId, long userId, @NonNull Relationship relationship) { + public CachedRelationship(UserKey accountId, long userId, @NonNull Relationship relationship) { account_key = accountId; user_id = userId; following = relationship.isSourceFollowingTarget(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java b/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java index 1ce3fe9f8..a79908c71 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/RefreshTaskParam.java @@ -8,7 +8,7 @@ import android.support.annotation.Nullable; */ public interface RefreshTaskParam { @NonNull - AccountKey[] getAccountKeys(); + UserKey[] getAccountKeys(); @Nullable long[] getMaxIds(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteTaskEvent.java index abb07a614..189ae4f16 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteTaskEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FavoriteTaskEvent.java @@ -22,7 +22,7 @@ package org.mariotaku.twidere.model.message; import android.support.annotation.IntDef; import android.support.annotation.Nullable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; /** @@ -31,7 +31,7 @@ import org.mariotaku.twidere.model.ParcelableStatus; public class FavoriteTaskEvent { private int action; - private AccountKey mAccountKey; + private UserKey mAccountKey; private long statusId; @Nullable @@ -39,7 +39,7 @@ public class FavoriteTaskEvent { private boolean finished; private boolean succeeded; - public FavoriteTaskEvent(@Action final int action, final AccountKey accountKey, final long statusId) { + public FavoriteTaskEvent(@Action final int action, final UserKey accountKey, final long statusId) { this.action = action; this.mAccountKey = accountKey; this.statusId = statusId; @@ -49,7 +49,7 @@ public class FavoriteTaskEvent { return action; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java index 0a82218e3..96a5f50b0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FollowRequestTaskEvent.java @@ -2,7 +2,7 @@ package org.mariotaku.twidere.model.message; import android.support.annotation.IntDef; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 16/2/15. @@ -13,10 +13,10 @@ public class FollowRequestTaskEvent { private int action; private boolean finished; private boolean succeeded; - private AccountKey mAccountKey; + private UserKey mAccountKey; private long userId; - public FollowRequestTaskEvent(@Action int action, AccountKey accountKey, long userId) { + public FollowRequestTaskEvent(@Action int action, UserKey accountKey, long userId) { this.action = action; this.mAccountKey = accountKey; this.userId = userId; @@ -35,7 +35,7 @@ public class FollowRequestTaskEvent { this.finished = finished; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java index 8d8776fa6..1f98a5eb8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/FriendshipUpdatedEvent.java @@ -22,7 +22,7 @@ package org.mariotaku.twidere.model.message; import android.support.annotation.NonNull; import org.mariotaku.twidere.api.twitter.model.Relationship; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 14/12/7. @@ -30,19 +30,19 @@ import org.mariotaku.twidere.model.AccountKey; public class FriendshipUpdatedEvent { @NonNull - AccountKey accountKey; + UserKey accountKey; long userId; @NonNull Relationship relationship; - public FriendshipUpdatedEvent(@NonNull AccountKey accountKey, long userId, @NonNull Relationship relationship) { + public FriendshipUpdatedEvent(@NonNull UserKey accountKey, long userId, @NonNull Relationship relationship) { this.accountKey = accountKey; this.userId = userId; this.relationship = relationship; } @NonNull - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return accountKey; } @@ -56,14 +56,14 @@ public class FriendshipUpdatedEvent { } public boolean isAccount(long accountId, String accountHost) { - return accountKey.isAccount(accountId, accountHost); + return accountKey.check(accountId, accountHost); } public boolean isUser(long id) { return userId == id; } - public boolean isAccount(AccountKey accountKey) { + public boolean isAccount(UserKey accountKey) { return this.accountKey.equals(accountKey); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/SavedSearchDestroyedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/SavedSearchDestroyedEvent.java index 8a0f0e979..67f99f2b4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/message/SavedSearchDestroyedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/SavedSearchDestroyedEvent.java @@ -1,20 +1,20 @@ package org.mariotaku.twidere.model.message; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 16/2/26. */ public class SavedSearchDestroyedEvent { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long searchId; - public SavedSearchDestroyedEvent(AccountKey accountKey, long searchId) { + public SavedSearchDestroyedEvent(UserKey accountKey, long searchId) { this.mAccountKey = accountKey; this.searchId = searchId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/message/UsersBlockedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/model/message/UsersBlockedEvent.java index 66c84af0a..1817fcbed 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/message/UsersBlockedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/message/UsersBlockedEvent.java @@ -1,20 +1,20 @@ package org.mariotaku.twidere.model.message; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 16/3/7. */ public class UsersBlockedEvent { - private AccountKey accountKey; + private UserKey accountKey; private long[] userIds; - public UsersBlockedEvent(AccountKey accountKey, long[] userIds) { + public UsersBlockedEvent(UserKey accountKey, long[] userIds) { this.accountKey = accountKey; this.userIds = userIds; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return accountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/Arguments.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/Arguments.java index dd46820bf..c72a5460b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/Arguments.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/tab/Arguments.java @@ -3,7 +3,7 @@ package org.mariotaku.twidere.model.tab; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 16/3/6. @@ -14,7 +14,7 @@ public class Arguments { long accountId; @JsonField(name = "account_key") - AccountKey accountKey; + UserKey accountKey; public long getAccountId() { return accountId; @@ -24,11 +24,11 @@ public class Arguments { this.accountId = accountId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return accountKey; } - public void setAccountKey(AccountKey accountKey) { + public void setAccountKey(UserKey accountKey) { this.accountKey = accountKey; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountKeyUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountKeyUtils.java deleted file mode 100644 index f91086b3e..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountKeyUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.mariotaku.twidere.model.util; - -import android.content.Context; -import android.database.Cursor; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.mariotaku.twidere.model.AccountKey; -import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; -import org.mariotaku.twidere.util.DataStoreUtils; - -import java.util.ArrayList; - -/** - * Created by mariotaku on 16/3/7. - */ -public class AccountKeyUtils { - - @Nullable - public static AccountKey findById(Context context, long id) { - final String[] projection = {Accounts.ACCOUNT_KEY}; - final Cursor cur = DataStoreUtils.findAccountCursorsById(context, projection, id); - if (cur == null) return null; - try { - if (cur.moveToFirst()) return AccountKey.valueOf(cur.getString(0)); - } finally { - cur.close(); - } - return null; - } - - @NonNull - public static AccountKey[] findByIds(Context context, long... id) { - final String[] projection = {Accounts.ACCOUNT_KEY}; - final Cursor cur = DataStoreUtils.findAccountCursorsById(context, projection, id); - if (cur == null) return new AccountKey[0]; - try { - final ArrayList accountKeys = new ArrayList<>(); - cur.moveToFirst(); - while (!cur.isAfterLast()) { - accountKeys.add(AccountKey.valueOf(cur.getString(0))); - cur.moveToNext(); - } - return accountKeys.toArray(new AccountKey[accountKeys.size()]); - } finally { - cur.close(); - } - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableAccountUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableAccountUtils.java index 370fae9a8..96c2a3b02 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableAccountUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableAccountUtils.java @@ -8,7 +8,7 @@ import android.support.annotation.Nullable; import org.mariotaku.sqliteqb.library.ArgsArray; import org.mariotaku.sqliteqb.library.Columns; import org.mariotaku.sqliteqb.library.Expression; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableAccountCursorIndices; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -22,8 +22,8 @@ import java.util.List; */ public class ParcelableAccountUtils { - public static AccountKey[] getAccountKeys(@NonNull ParcelableAccount[] accounts) { - AccountKey[] ids = new AccountKey[accounts.length]; + public static UserKey[] getAccountKeys(@NonNull ParcelableAccount[] accounts) { + UserKey[] ids = new UserKey[accounts.length]; for (int i = 0, j = accounts.length; i < j; i++) { ids[i] = accounts[i].account_key; } @@ -32,7 +32,7 @@ public class ParcelableAccountUtils { @Nullable public static ParcelableAccount getAccount(@NonNull final Context context, - @NonNull final AccountKey accountKey) { + @NonNull final UserKey accountKey) { final Cursor c = DataStoreUtils.getAccountCursor(context, Accounts.COLUMNS_NO_CREDENTIALS, accountKey); if (c == null) return null; @@ -62,7 +62,7 @@ public class ParcelableAccountUtils { } @NonNull - public static ParcelableAccount[] getAccounts(@NonNull final Context context, @NonNull final AccountKey... accountIds) { + public static ParcelableAccount[] getAccounts(@NonNull final Context context, @NonNull final UserKey... accountIds) { final String where = Expression.in(new Columns.Column(Accounts.ACCOUNT_KEY), new ArgsArray(accountIds.length)).getSQL(); final String[] whereArgs = TwidereArrayUtils.toStringArray(accountIds); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableActivityUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableActivityUtils.java index 171319a82..d12987e8b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableActivityUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableActivityUtils.java @@ -6,10 +6,10 @@ import android.support.annotation.Nullable; import org.apache.commons.collections.primitives.ArrayLongList; import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.twidere.api.twitter.model.Activity; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.UserKey; /** * Processing ParcelableActivity @@ -33,8 +33,8 @@ public class ParcelableActivityUtils { if (followingOnly && !user.is_following) { continue; } - if (!ArrayUtils.contains(filteredUserIds, user.id)) { - list.add(user.id); + if (!ArrayUtils.contains(filteredUserIds, user.key.getId())) { + list.add(user.key.getId()); } } activity.after_filtered_source_ids = list.toArray(); @@ -53,7 +53,7 @@ public class ParcelableActivityUtils { ParcelableUser[] result = new ParcelableUser[activity.after_filtered_source_ids.length]; for (int i = 0; i < activity.after_filtered_source_ids.length; i++) { for (ParcelableUser user : activity.sources) { - if (user.id == activity.after_filtered_source_ids[i]) { + if (user.key.getId() == activity.after_filtered_source_ids[i]) { result[i] = user; } } @@ -62,7 +62,7 @@ public class ParcelableActivityUtils { } public static ParcelableActivity fromActivity(final Activity activity, - final AccountKey accountKey, + final UserKey accountKey, final boolean isGap) { ParcelableActivity result = new ParcelableActivity(); result.account_key = accountKey; @@ -80,7 +80,7 @@ public class ParcelableActivityUtils { if (result.sources != null) { result.source_ids = new long[result.sources.length]; for (int i = 0; i < result.sources.length; i++) { - result.source_ids[i] = result.sources[i].id; + result.source_ids[i] = result.sources[i].key.getId(); } } result.is_gap = isGap; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCardEntityUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCardEntityUtils.java index ffbd21165..e87ed0b84 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCardEntityUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCardEntityUtils.java @@ -9,7 +9,7 @@ import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.api.twitter.model.CardEntity; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCardEntity; import java.text.ParseException; @@ -22,7 +22,7 @@ import java.util.Map; public class ParcelableCardEntityUtils implements TwidereConstants { @Nullable - public static ParcelableCardEntity fromCardEntity(@Nullable CardEntity card, @Nullable AccountKey accountKey) { + public static ParcelableCardEntity fromCardEntity(@Nullable CardEntity card, @Nullable UserKey accountKey) { if (card == null) return null; final ParcelableCardEntity obj = new ParcelableCardEntity(); obj.name = card.getName(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCredentialsUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCredentialsUtils.java index a48f24301..3f567eace 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCredentialsUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableCredentialsUtils.java @@ -5,7 +5,7 @@ import android.database.Cursor; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -27,7 +27,7 @@ public class ParcelableCredentialsUtils { @Nullable public static ParcelableCredentials getCredentials(@NonNull final Context context, - @NonNull final AccountKey accountKey) { + @NonNull final UserKey accountKey) { final Cursor c = DataStoreUtils.getAccountCursor(context, Accounts.COLUMNS, accountKey); if (c == null) return null; try { diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java index 082f7a183..f2513bd85 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableDirectMessageUtils.java @@ -2,7 +2,7 @@ package org.mariotaku.twidere.model.util; import org.mariotaku.twidere.api.twitter.model.DirectMessage; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import org.mariotaku.twidere.util.TwitterContentUtils; @@ -16,7 +16,7 @@ import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText; */ public class ParcelableDirectMessageUtils { - public static ParcelableDirectMessage fromDirectMessage(DirectMessage message, AccountKey accountKey, boolean isOutgoing) { + public static ParcelableDirectMessage fromDirectMessage(DirectMessage message, UserKey accountKey, boolean isOutgoing) { ParcelableDirectMessage result = new ParcelableDirectMessage(); result.account_key = accountKey; result.is_outgoing = isOutgoing; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableStatusUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableStatusUtils.java index 7f69a91e6..3e3f291f6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableStatusUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableStatusUtils.java @@ -3,13 +3,14 @@ package org.mariotaku.twidere.model.util; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import org.mariotaku.twidere.api.statusnet.model.Attention; import org.mariotaku.twidere.api.twitter.model.Place; import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import org.mariotaku.twidere.model.ParcelableLocation; import org.mariotaku.twidere.model.ParcelableStatus; -import org.mariotaku.twidere.model.ParcelableUserMention; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.HtmlEscapeHelper; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import org.mariotaku.twidere.util.TwitterContentUtils; @@ -24,7 +25,7 @@ public class ParcelableStatusUtils { public static void makeOriginalStatus(@NonNull ParcelableStatus status) { if (!status.is_retweet) return; status.id = status.retweet_id; - status.retweeted_by_user_id = -1; + status.retweeted_by_user_id = null; status.retweeted_by_user_name = null; status.retweeted_by_user_screen_name = null; status.retweeted_by_user_profile_image = null; @@ -32,7 +33,7 @@ public class ParcelableStatusUtils { status.retweet_id = -1; } - public static ParcelableStatus fromStatus(final Status orig, final AccountKey accountKey, + public static ParcelableStatus fromStatus(final Status orig, final UserKey accountKey, final boolean isGap) { final ParcelableStatus result = new ParcelableStatus(); result.is_gap = isGap; @@ -50,7 +51,7 @@ public class ParcelableStatusUtils { if (retweetedStatus != null) { result.retweet_id = retweetedStatus.getId(); result.retweet_timestamp = getTime(retweetedStatus.getCreatedAt()); - result.retweeted_by_user_id = retweetUser.getId(); + result.retweeted_by_user_id = UserKeyUtils.fromUser(retweetUser); result.retweeted_by_user_name = retweetUser.getName(); result.retweeted_by_user_screen_name = retweetUser.getScreenName(); result.retweeted_by_user_profile_image = TwitterContentUtils.getProfileImageUrl(retweetUser); @@ -70,7 +71,7 @@ public class ParcelableStatusUtils { result.quoted_location = ParcelableLocation.fromGeoLocation(quoted.getGeoLocation()); result.quoted_place_full_name = getPlaceFullName(quoted.getPlace()); - result.quoted_user_id = quoted_user.getId(); + result.quoted_user_id = UserKeyUtils.fromUser(quoted_user); result.quoted_user_name = quoted_user.getName(); result.quoted_user_screen_name = quoted_user.getScreenName(); result.quoted_user_profile_image = TwitterContentUtils.getProfileImageUrl(quoted_user); @@ -86,24 +87,24 @@ public class ParcelableStatusUtils { result.favorite_count = retweetedStatus.getFavoriteCount(); - result.in_reply_to_name = TwitterContentUtils.getInReplyToName(retweetedStatus); + result.in_reply_to_name = getInReplyToName(retweetedStatus); result.in_reply_to_screen_name = retweetedStatus.getInReplyToScreenName(); result.in_reply_to_status_id = retweetedStatus.getInReplyToStatusId(); - result.in_reply_to_user_id = retweetedStatus.getInReplyToUserId(); + result.in_reply_to_user_id = getInReplyToUserId(retweetedStatus, accountKey); } else { status = orig; result.reply_count = orig.getReplyCount(); result.retweet_count = orig.getRetweetCount(); result.favorite_count = orig.getFavoriteCount(); - result.in_reply_to_name = TwitterContentUtils.getInReplyToName(orig); + result.in_reply_to_name = getInReplyToName(orig); result.in_reply_to_screen_name = orig.getInReplyToScreenName(); result.in_reply_to_status_id = orig.getInReplyToStatusId(); - result.in_reply_to_user_id = orig.getInReplyToUserId(); + result.in_reply_to_user_id = getInReplyToUserId(orig, accountKey); } final User user = status.getUser(); - result.user_id = user.getId(); + result.user_key = UserKeyUtils.fromUser(user); result.user_name = user.getName(); result.user_screen_name = user.getScreenName(); result.user_profile_image_url = TwitterContentUtils.getProfileImageUrl(user); @@ -118,13 +119,14 @@ public class ParcelableStatusUtils { result.location = ParcelableLocation.fromGeoLocation(status.getGeoLocation()); result.is_favorite = status.isFavorited(); result.text_unescaped = HtmlEscapeHelper.toPlainText(result.text_html); - if (result.retweeted_by_user_id == result.account_key.getId()) { + if (result.account_key.maybeEquals(result.retweeted_by_user_id)) { result.my_retweet_id = result.id; } else { result.my_retweet_id = status.getCurrentUserRetweet(); } result.is_possibly_sensitive = status.isPossiblySensitive(); - result.mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); + result.mentions = ParcelableUserMentionUtils.fromUserMentionEntities(user, + status.getUserMentionEntities()); result.card = ParcelableCardEntityUtils.fromCardEntity(status.getCard(), accountKey); result.place_full_name = getPlaceFullName(status.getPlace()); result.card_name = result.card != null ? result.card.name : null; @@ -132,7 +134,31 @@ public class ParcelableStatusUtils { return result; } - public static ParcelableStatus[] fromStatuses(Status[] statuses, AccountKey accountKey) { + private static UserKey getInReplyToUserId(Status status, UserKey accountKey) { + final long inReplyToUserId = status.getInReplyToUserId(); + final UserMentionEntity[] entities = status.getUserMentionEntities(); + if (entities != null) { + for (final UserMentionEntity entity : entities) { + if (inReplyToUserId == entity.getId()) { + return new UserKey(inReplyToUserId, accountKey.getHost()); + } + } + } + final Attention[] attentions = status.getAttentions(); + if (attentions != null) { + for (Attention attention : attentions) { + if (inReplyToUserId == attention.getId()) { + final String host = UserKeyUtils.getUserHost(attention.getOstatusUri()); + if (host != null) { + return new UserKey(inReplyToUserId, host); + } + } + } + } + return new UserKey(inReplyToUserId, accountKey.getHost()); + } + + public static ParcelableStatus[] fromStatuses(Status[] statuses, UserKey accountKey) { if (statuses == null) return null; int size = statuses.length; final ParcelableStatus[] result = new ParcelableStatus[size]; @@ -151,4 +177,22 @@ public class ParcelableStatusUtils { private static long getTime(final Date date) { return date != null ? date.getTime() : 0; } + + @NonNull + public static String getInReplyToName(@NonNull final Status status) { + final long inReplyToUserId = status.getInReplyToUserId(); + final UserMentionEntity[] entities = status.getUserMentionEntities(); + if (entities != null) { + for (final UserMentionEntity entity : entities) { + if (inReplyToUserId == entity.getId()) return entity.getName(); + } + } + final Attention[] attentions = status.getAttentions(); + if (attentions != null) { + for (Attention attention : attentions) { + if (inReplyToUserId == attention.getId()) return attention.getFullName(); + } + } + return status.getInReplyToScreenName(); + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserListUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserListUtils.java index a2abf270f..d0348da10 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserListUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserListUtils.java @@ -2,19 +2,19 @@ package org.mariotaku.twidere.model.util; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.api.twitter.model.UserList; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUserList; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.TwitterContentUtils; /** * Created by mariotaku on 16/3/5. */ public class ParcelableUserListUtils { - public static ParcelableUserList from(UserList list, AccountKey accountKey) { + public static ParcelableUserList from(UserList list, UserKey accountKey) { return from(list, accountKey, 0, false); } - public static ParcelableUserList from(UserList list, AccountKey accountKey, long position, boolean isFollowing) { + public static ParcelableUserList from(UserList list, UserKey accountKey, long position, boolean isFollowing) { ParcelableUserList obj = new ParcelableUserList(); final User user = list.getUser(); obj.position = position; @@ -24,7 +24,7 @@ public class ParcelableUserListUtils { obj.is_following = isFollowing; obj.name = list.getName(); obj.description = list.getDescription(); - obj.user_id = user.getId(); + obj.user_key = UserKeyUtils.fromUser(user); obj.user_name = user.getName(); obj.user_screen_name = user.getScreenName(); obj.user_profile_image_url = TwitterContentUtils.getProfileImageUrl(user); @@ -33,7 +33,7 @@ public class ParcelableUserListUtils { return obj; } - public static ParcelableUserList[] fromUserLists(UserList[] userLists, AccountKey accountKey) { + public static ParcelableUserList[] fromUserLists(UserList[] userLists, UserKey accountKey) { if (userLists == null) return null; int size = userLists.length; final ParcelableUserList[] result = new ParcelableUserList[size]; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserMentionUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserMentionUtils.java new file mode 100644 index 000000000..12c354e9b --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserMentionUtils.java @@ -0,0 +1,30 @@ +package org.mariotaku.twidere.model.util; + +import org.mariotaku.twidere.api.twitter.model.User; +import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; +import org.mariotaku.twidere.model.ParcelableUserMention; +import org.mariotaku.twidere.model.UserKey; + +/** + * Created by mariotaku on 16/3/7. + */ +public class ParcelableUserMentionUtils { + public static ParcelableUserMention fromMentionEntity(final User user, + final UserMentionEntity entity) { + ParcelableUserMention obj = new ParcelableUserMention(); + obj.key = new UserKey(entity.getId(), UserKeyUtils.getUserHost(user)); + obj.name = entity.getName(); + obj.screen_name = entity.getScreenName(); + return obj; + } + + public static ParcelableUserMention[] fromUserMentionEntities(final User user, + final UserMentionEntity[] entities) { + if (entities == null) return null; + final ParcelableUserMention[] mentions = new ParcelableUserMention[entities.length]; + for (int i = 0, j = entities.length; i < j; i++) { + mentions[i] = fromMentionEntity(user, entities[i]); + } + return mentions; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserUtils.java index b3285a0cf..2ee175ea7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableUserUtils.java @@ -7,33 +7,31 @@ import android.support.annotation.Nullable; import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.api.twitter.model.UrlEntity; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.provider.TwidereDataStore; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; import org.mariotaku.twidere.util.HtmlEscapeHelper; import org.mariotaku.twidere.util.InternalTwitterContentUtils; import org.mariotaku.twidere.util.ParseUtils; import org.mariotaku.twidere.util.TwitterContentUtils; -import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; /** * Processing ParcelableUser - * + *

    * Created by mariotaku on 16/2/24. */ public class ParcelableUserUtils implements TwidereConstants { - public static ParcelableUser fromUser(@NonNull User user, @Nullable AccountKey accountKey) { + public static ParcelableUser fromUser(@NonNull User user, @Nullable UserKey accountKey) { return fromUser(user, accountKey, 0); } - public static ParcelableUser fromUser(@NonNull User user, @Nullable AccountKey accountKey, long position) { + public static ParcelableUser fromUser(@NonNull User user, @Nullable UserKey accountKey, long position) { final UrlEntity[] urlEntities = user.getUrlEntities(); final ParcelableUser obj = new ParcelableUser(); obj.position = position; obj.account_key = accountKey; - obj.id = user.getId(); + obj.key = UserKeyUtils.fromUser(user); obj.created_at = user.getCreatedAt().getTime(); obj.is_protected = user.isProtected(); obj.is_verified = user.isVerified(); @@ -71,32 +69,24 @@ public class ParcelableUserUtils implements TwidereConstants { extras.profile_image_url_profile_size = user.getProfileImageUrlProfileSize(); extras.groups_count = user.getGroupsCount(); obj.extras = extras; - obj.user_host = getUserHost(extras.ostatus_uri); return obj; } - public static String getUserHost(@Nullable String uri) { - if (uri == null) return USER_TYPE_TWITTER_COM; - final String authority = PreviewMediaExtractor.getAuthority(uri); - if (authority == null) return null; - return authority.replaceAll("[^\\w\\d\\.]", "-"); - } - public static String getUserHost(ParcelableUser user) { if (user.extras == null) return USER_TYPE_TWITTER_COM; - return getUserHost(user.extras.ostatus_uri); + return UserKeyUtils.getUserHost(user.extras.ostatus_uri); } public static ParcelableUser fromDirectMessageConversationEntry(final Cursor cursor) { - final AccountKey accountId = AccountKey.valueOf(cursor.getString(DirectMessages.ConversationEntries.IDX_ACCOUNT_KEY)); - final long id = cursor.getLong(DirectMessages.ConversationEntries.IDX_CONVERSATION_ID); + final UserKey accountId = UserKey.valueOf(cursor.getString(DirectMessages.ConversationEntries.IDX_ACCOUNT_KEY)); + final UserKey id = UserKey.valueOf(cursor.getString(DirectMessages.ConversationEntries.IDX_CONVERSATION_ID)); final String name = cursor.getString(DirectMessages.ConversationEntries.IDX_NAME); final String screenName = cursor.getString(DirectMessages.ConversationEntries.IDX_SCREEN_NAME); final String profileImageUrl = cursor.getString(DirectMessages.ConversationEntries.IDX_PROFILE_IMAGE_URL); return new ParcelableUser(accountId, id, name, screenName, profileImageUrl); } - public static ParcelableUser[] fromUsers(final User[] users, AccountKey accountKey) { + public static ParcelableUser[] fromUsers(final User[] users, UserKey accountKey) { if (users == null) return null; int size = users.length; final ParcelableUser[] result = new ParcelableUser[size]; diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java new file mode 100644 index 000000000..cc9deab16 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java @@ -0,0 +1,68 @@ +package org.mariotaku.twidere.model.util; + +import android.content.Context; +import android.database.Cursor; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import org.mariotaku.twidere.TwidereConstants; +import org.mariotaku.twidere.api.twitter.model.User; +import org.mariotaku.twidere.model.UserKey; +import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; +import org.mariotaku.twidere.util.DataStoreUtils; +import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; + +import java.util.ArrayList; + +/** + * Created by mariotaku on 16/3/7. + */ +public class UserKeyUtils { + + @Nullable + public static UserKey findById(Context context, long id) { + final String[] projection = {Accounts.ACCOUNT_KEY}; + final Cursor cur = DataStoreUtils.findAccountCursorsById(context, projection, id); + if (cur == null) return null; + try { + if (cur.moveToFirst()) return UserKey.valueOf(cur.getString(0)); + } finally { + cur.close(); + } + return null; + } + + @NonNull + public static UserKey[] findByIds(Context context, long... id) { + final String[] projection = {Accounts.ACCOUNT_KEY}; + final Cursor cur = DataStoreUtils.findAccountCursorsById(context, projection, id); + if (cur == null) return new UserKey[0]; + try { + final ArrayList accountKeys = new ArrayList<>(); + cur.moveToFirst(); + while (!cur.isAfterLast()) { + accountKeys.add(UserKey.valueOf(cur.getString(0))); + cur.moveToNext(); + } + return accountKeys.toArray(new UserKey[accountKeys.size()]); + } finally { + cur.close(); + } + } + + public static UserKey fromUser(User user) { + return new UserKey(user.getId(), getUserHost(user)); + } + + public static String getUserHost(User user) { + return getUserHost(user.getOstatusUri()); + } + + @NonNull + public static String getUserHost(@Nullable String uri) { + if (uri == null) return TwidereConstants.USER_TYPE_TWITTER_COM; + final String authority = PreviewMediaExtractor.getAuthority(uri); + if (authority == null) return TwidereConstants.USER_TYPE_TWITTER_COM; + return authority.replaceAll("[^\\w\\d\\.]", "-"); + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java index ede6154e1..a97d33820 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java @@ -81,16 +81,17 @@ import org.mariotaku.twidere.annotation.NotificationType; import org.mariotaku.twidere.annotation.ReadPositionTag; import org.mariotaku.twidere.api.twitter.model.Activity; import org.mariotaku.twidere.app.TwidereApplication; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.ActivityTitleSummaryMessage; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.DraftCursorIndices; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityCursorIndices; +import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.StringLongPair; import org.mariotaku.twidere.model.UnreadItem; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.UnreadCountUpdatedEvent; import org.mariotaku.twidere.model.util.ParcelableActivityUtils; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; @@ -193,13 +194,13 @@ public final class TwidereDataProvider extends ContentProvider implements Consta private boolean mUseStarForLikes; private static PendingIntent getMarkReadDeleteIntent(Context context, @NotificationType String type, - @Nullable AccountKey accountKey, long position, + @Nullable UserKey accountKey, long position, boolean extraUserFollowing) { return getMarkReadDeleteIntent(context, type, accountKey, position, -1, -1, extraUserFollowing); } private static PendingIntent getMarkReadDeleteIntent(Context context, @NotificationType String type, - @Nullable AccountKey accountKey, long position, + @Nullable UserKey accountKey, long position, long extraId, long extraUserId, boolean extraUserFollowing) { // Setup delete intent @@ -224,7 +225,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } private static PendingIntent getMarkReadDeleteIntent(Context context, @NotificationType String notificationType, - @Nullable AccountKey accountId, StringLongPair[] positions) { + @Nullable UserKey accountId, StringLongPair[] positions) { // Setup delete intent final Intent intent = new Intent(context, NotificationReceiver.class); final Uri.Builder linkBuilder = new Uri.Builder(); @@ -348,8 +349,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta mDatabaseWrapper.beginTransaction(); if (tableId == TABLE_ID_CACHED_USERS) { for (final ContentValues values : valuesArray) { - final Expression where = Expression.equals(CachedUsers.USER_ID, - values.getAsLong(CachedUsers.USER_ID)); + final Expression where = Expression.equals(CachedUsers.USER_KEY, + values.getAsLong(CachedUsers.USER_KEY)); mDatabaseWrapper.update(table, values, where.getSQL(), null); newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); @@ -417,7 +418,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta clearNotification(notificationType, null); } else if (segments.size() == 3) { final int notificationType = NumberUtils.toInt(segments.get(1), -1); - final AccountKey accountKey = AccountKey.valueOf(segments.get(2)); + final UserKey accountKey = UserKey.valueOf(segments.get(2)); clearNotification(notificationType, accountKey); } return 1; @@ -467,9 +468,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } final long rowId; if (tableId == TABLE_ID_CACHED_USERS) { - final Expression where = Expression.and(Expression.equalsArgs(CachedUsers.USER_ID), + final Expression where = Expression.and(Expression.equalsArgs(CachedUsers.USER_KEY), Expression.equalsArgs(CachedUsers.USER_HOST)); - final String[] whereArgs = {values.getAsString(CachedUsers.USER_ID), + final String[] whereArgs = {values.getAsString(CachedUsers.USER_KEY), values.getAsString(CachedUsers.USER_HOST)}; mDatabaseWrapper.update(table, values, where.getSQL(), whereArgs); rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, @@ -483,12 +484,12 @@ public final class TwidereDataProvider extends ContentProvider implements Consta SQLiteDatabase.CONFLICT_IGNORE); } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) { final String accountKey = values.getAsString(CachedRelationships.ACCOUNT_KEY); - final long userId = values.getAsLong(CachedRelationships.USER_ID); + final String userId = values.getAsString(CachedRelationships.USER_ID); final Expression where = Expression.and( Expression.equalsArgs(CachedRelationships.ACCOUNT_KEY), Expression.equalsArgs(CachedRelationships.USER_ID) ); - final String[] whereArgs = {accountKey, String.valueOf(userId)}; + final String[] whereArgs = {accountKey, userId}; if (mDatabaseWrapper.update(table, values, where.getSQL(), whereArgs) > 0) { final String[] projection = {CachedRelationships._ID}; final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, @@ -827,7 +828,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta new Column(CachedUsers.NAME, Suggestions.Search.TITLE).getSQL(), new Column(CachedUsers.SCREEN_NAME, Suggestions.Search.SUMMARY).getSQL(), new Column(CachedUsers.PROFILE_IMAGE_URL, Suggestions.Search.ICON).getSQL(), - new Column(CachedUsers.USER_ID, Suggestions.Search.EXTRA_ID).getSQL(), + new Column(CachedUsers.USER_KEY, Suggestions.Search.EXTRA_ID).getSQL(), new Column(SQLConstants.NULL, Suggestions.Search.EXTRA).getSQL(), new Column(CachedUsers.SCREEN_NAME, Suggestions.Search.VALUE).getSQL(), }; @@ -836,7 +837,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta final Expression usersSelection = Expression.or( Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"), Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"), - Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds))); + Expression.in(new Column(CachedUsers.USER_KEY), new RawItemArray(nicknameIds))); final String[] selectionArgs = new String[]{queryTrimmed, queryTrimmed}; final String[] order = {CachedUsers.LAST_SEEN, CachedUsers.SCORE, CachedUsers.SCREEN_NAME, CachedUsers.NAME}; @@ -879,14 +880,14 @@ public final class TwidereDataProvider extends ContentProvider implements Consta final long[] nicknameIds = Utils.getMatchedNicknameIds(query, mUserColorNameManager); final Expression where = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"), Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"), - Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds))); + Expression.in(new Column(CachedUsers.USER_KEY), new RawItemArray(nicknameIds))); final String[] whereArgs = {queryEscaped, queryEscaped}; final String[] mappedProjection = { new Column(CachedUsers._ID, Suggestions._ID).getSQL(), new Column("'" + Suggestions.AutoComplete.TYPE_USERS + "'", Suggestions.TYPE).getSQL(), new Column(CachedUsers.NAME, Suggestions.TITLE).getSQL(), new Column(CachedUsers.SCREEN_NAME, Suggestions.SUMMARY).getSQL(), - new Column(CachedUsers.USER_ID, Suggestions.EXTRA_ID).getSQL(), + new Column(CachedUsers.USER_KEY, Suggestions.EXTRA_ID).getSQL(), new Column(CachedUsers.PROFILE_IMAGE_URL, Suggestions.ICON).getSQL(), new Column(CachedUsers.SCREEN_NAME, Suggestions.VALUE).getSQL(), }; @@ -1073,7 +1074,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta mNotificationManager.cancelAll(); } - private void clearNotification(final int notificationType, final AccountKey accountId) { + private void clearNotification(final int notificationType, final UserKey accountId) { mNotificationManager.cancelById(Utils.getNotificationId(notificationType, accountId)); } @@ -1267,7 +1268,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } } - private long getPositionTag(String tag, AccountKey accountKey) { + private long getPositionTag(String tag, UserKey accountKey) { final long position = mReadStateManager.getPosition(Utils.getReadPositionTagWithAccounts(tag, accountKey)); if (position != -1) return position; @@ -1275,7 +1276,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } private void showTimelineNotification(AccountPreferences pref, long position) { - final AccountKey accountKey = pref.getAccountKey(); + final UserKey accountKey = pref.getAccountKey(); final Context context = getContext(); if (context == null) return; final Resources resources = context.getResources(); @@ -1305,14 +1306,16 @@ public final class TwidereDataProvider extends ContentProvider implements Consta statusesCount, statusesCount); final String notificationContent; userCursor.moveToFirst(); - final String displayName = mUserColorNameManager.getUserNickname(userCursor.getLong(idxUserId), - mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); + final String displayName = mUserColorNameManager.getDisplayName(userCursor.getString(idxUserId), + userCursor.getString(idxUserName), userCursor.getString(idxUserScreenName), + mNameFirst, false); if (usersCount == 1) { notificationContent = context.getString(R.string.from_name, displayName); } else if (usersCount == 2) { userCursor.moveToPosition(1); - final String othersName = mUserColorNameManager.getUserNickname(userCursor.getLong(idxUserId), - mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); + final String othersName = mUserColorNameManager.getDisplayName(userCursor.getString(idxUserId), + userCursor.getString(idxUserName), userCursor.getString(idxUserScreenName), + mNameFirst, false); notificationContent = resources.getString(R.string.from_name_and_name, displayName, othersName); } else { notificationContent = resources.getString(R.string.from_name_and_N_others, displayName, usersCount - 1); @@ -1348,7 +1351,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta private void showInteractionsNotification(AccountPreferences pref, long position, boolean combined) { final Context context = getContext(); if (context == null) return; - final AccountKey accountKey = pref.getAccountKey(); + final UserKey accountKey = pref.getAccountKey(); final String where = Expression.and( Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY), Expression.greaterThanArgs(Activities.TIMESTAMP) @@ -1432,7 +1435,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta private PendingIntent getContentIntent(final Context context, @CustomTabType final String type, @NotificationType final String notificationType, - @Nullable final AccountKey accountKey, final long readPosition) { + @Nullable final UserKey accountKey, final long readPosition) { // Setup click intent final Intent homeIntent = new Intent(context, HomeActivity.class); final Uri.Builder homeLinkBuilder = new Uri.Builder(); @@ -1497,7 +1500,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta private void showMessagesNotification(AccountPreferences pref, StringLongPair[] pairs, ContentValues[] valuesArray) { final Context context = getContext(); assert context != null; - final AccountKey accountKey = pref.getAccountKey(); + final UserKey accountKey = pref.getAccountKey(); final long prevOldestId = mReadStateManager.getPosition(TAG_OLDEST_MESSAGES, String.valueOf(accountKey)); long oldestId = -1; @@ -1552,13 +1555,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta if (messagesCount == 0 || usersCount == 0) return; final String accountName = DataStoreUtils.getAccountName(context, accountKey); final String accountScreenName = DataStoreUtils.getAccountScreenName(context, accountKey); - final int idxMessageText = messageCursor.getColumnIndex(DirectMessages.TEXT_UNESCAPED), - idxMessageTimestamp = messageCursor.getColumnIndex(DirectMessages.MESSAGE_TIMESTAMP), - idxMessageId = messageCursor.getColumnIndex(DirectMessages.MESSAGE_ID), - idxMessageUserId = messageCursor.getColumnIndex(DirectMessages.SENDER_ID), - idxMessageUserName = messageCursor.getColumnIndex(DirectMessages.SENDER_NAME), - idxMessageUserScreenName = messageCursor.getColumnIndex(DirectMessages.SENDER_SCREEN_NAME), - idxUserName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), + final ParcelableDirectMessageCursorIndices messageIndices = new ParcelableDirectMessageCursorIndices(messageCursor); + final int idxUserName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserScreenName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserId = userCursor.getColumnIndex(DirectMessages.SENDER_NAME); @@ -1566,7 +1564,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta messagesCount, messagesCount); final String notificationContent; userCursor.moveToFirst(); - final String displayName = mUserColorNameManager.getUserNickname(userCursor.getLong(idxUserId), + final String displayName = mUserColorNameManager.getUserNickname(userCursor.getString(idxUserId), mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); if (usersCount == 1) { if (messagesCount == 1) { @@ -1586,19 +1584,20 @@ public final class TwidereDataProvider extends ContentProvider implements Consta final InboxStyle style = new InboxStyle(); for (int i = 0; messageCursor.moveToPosition(i) && i < messagesCount; i++) { if (when < 0) { - when = messageCursor.getLong(idxMessageTimestamp); + when = messageCursor.getLong(messageIndices.timestamp); } if (i < 5) { final SpannableStringBuilder sb = new SpannableStringBuilder(); - sb.append(mUserColorNameManager.getUserNickname(messageCursor.getLong(idxUserId), - mNameFirst ? messageCursor.getString(idxMessageUserName) : messageCursor.getString(idxMessageUserScreenName))); + sb.append(mUserColorNameManager.getUserNickname(messageCursor.getString(idxUserId), + mNameFirst ? messageCursor.getString(messageIndices.sender_name) : + messageCursor.getString(messageIndices.sender_screen_name))); sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sb.append(' '); - sb.append(messageCursor.getString(idxMessageText)); + sb.append(messageCursor.getString(messageIndices.text_unescaped)); style.addLine(sb); } - final long userId = messageCursor.getLong(idxMessageUserId); - final long messageId = messageCursor.getLong(idxMessageId); + final long userId = messageCursor.getLong(messageIndices.sender_id); + final long messageId = messageCursor.getLong(messageIndices.id); idsMap.put(userId, Math.max(idsMap.get(userId, -1L), messageId)); } if (mNameFirst) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/receiver/NotificationReceiver.java b/twidere/src/main/java/org/mariotaku/twidere/receiver/NotificationReceiver.java index 4374e69a9..4bce8dc4a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/receiver/NotificationReceiver.java +++ b/twidere/src/main/java/org/mariotaku/twidere/receiver/NotificationReceiver.java @@ -31,7 +31,7 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.annotation.CustomTabType; import org.mariotaku.twidere.annotation.NotificationType; import org.mariotaku.twidere.annotation.ReadPositionTag; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.StringLongPair; import org.mariotaku.twidere.util.CustomTabUtils; import org.mariotaku.twidere.util.ReadStateManager; @@ -57,7 +57,7 @@ public class NotificationReceiver extends BroadcastReceiver implements Constants DependencyHolder holder = DependencyHolder.get(context); @NotificationType final String notificationType = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE); - final AccountKey accountKey = AccountKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); + final UserKey accountKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); final long itemId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_id"), -1); final long itemUserId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_user_id"), -1); final boolean itemUserFollowing = Boolean.parseBoolean(UriExtraUtils.getExtra(uri, "item_user_following")); 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 6e1057a1e..0860a14be 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java @@ -63,7 +63,6 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.StatusUpdate; import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import org.mariotaku.twidere.app.TwidereApplication; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.DraftCursorIndices; import org.mariotaku.twidere.model.DraftValuesCreator; @@ -75,9 +74,11 @@ import org.mariotaku.twidere.model.ParcelableLocation; import org.mariotaku.twidere.model.ParcelableMediaUpdate; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; +import org.mariotaku.twidere.model.ParcelableUserMention; import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.model.StatusShortenResult; import org.mariotaku.twidere.model.UploaderMediaItem; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtra; import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra; import org.mariotaku.twidere.model.util.ParcelableAccountUtils; @@ -85,6 +86,7 @@ import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils; import org.mariotaku.twidere.model.util.ParcelableDirectMessageUtils; import org.mariotaku.twidere.model.util.ParcelableStatusUpdateUtils; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; +import org.mariotaku.twidere.model.util.ParcelableUserMentionUtils; import org.mariotaku.twidere.preference.ServicePickerPreference; import org.mariotaku.twidere.provider.TwidereDataStore.CachedHashtags; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; @@ -269,7 +271,7 @@ public class BackgroundOperationService extends IntentService implements Constan if (ArrayUtils.isEmpty(item.account_ids) || recipientId <= 0) { return; } - final AccountKey accountKey = item.account_ids[0]; + final UserKey accountKey = item.account_ids[0]; final String imageUri = ArrayUtils.isEmpty(item.media) ? null : item.media[0].uri; sendMessage(accountKey, recipientId, item.text, imageUri); break; @@ -289,14 +291,14 @@ public class BackgroundOperationService extends IntentService implements Constan } private void handleSendDirectMessageIntent(final Intent intent) { - final AccountKey accountId = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); + final UserKey accountId = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY); final long recipientId = intent.getLongExtra(EXTRA_RECIPIENT_ID, -1); final String imageUri = intent.getStringExtra(EXTRA_IMAGE_URI); final String text = intent.getStringExtra(EXTRA_TEXT); sendMessage(accountId, recipientId, text, imageUri); } - private void sendMessage(AccountKey accountId, long recipientId, String text, String imageUri) { + private void sendMessage(UserKey accountId, long recipientId, String text, String imageUri) { if (accountId == null || recipientId <= 0 || isEmpty(text)) return; final String title = getString(R.string.sending_direct_message); final Builder builder = new Builder(this); @@ -377,7 +379,7 @@ public class BackgroundOperationService extends IntentService implements Constan boolean failed = false; Exception exception = null; final Expression where = Expression.equals(Drafts._ID, draftId); - final List failedAccountIds = new ArrayList<>(); + final List failedAccountIds = new ArrayList<>(); Collections.addAll(failedAccountIds, ParcelableAccountUtils.getAccountKeys(item.accounts)); for (final SingleResponse response : result) { @@ -444,7 +446,7 @@ public class BackgroundOperationService extends IntentService implements Constan private SingleResponse sendDirectMessage(final NotificationCompat.Builder builder, - final AccountKey accountKey, final long recipientId, + final UserKey accountKey, final long recipientId, final String text, final String imageUri) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(this, accountKey, true, true); final TwitterUpload twitterUpload = TwitterAPIFactory.getTwitterInstance(this, accountKey, true, true, TwitterUpload.class); @@ -471,8 +473,8 @@ public class BackgroundOperationService extends IntentService implements Constan } else { directMessage = ParcelableDirectMessageUtils.fromDirectMessage(twitter.sendDirectMessage(recipientId, text), accountKey, true); } - Utils.setLastSeen(this, recipientId, System.currentTimeMillis()); - + Utils.setLastSeen(this, new UserKey(recipientId, accountKey.getHost()), + System.currentTimeMillis()); return SingleResponse.getInstance(directMessage); } catch (final IOException e) { @@ -690,13 +692,14 @@ public class BackgroundOperationService extends IntentService implements Constan try { final Status resultStatus = twitter.updateStatus(status); if (!mentionedHondaJOJO) { - final UserMentionEntity[] entities = resultStatus.getUserMentionEntities(); - if (entities == null || entities.length == 0) { + ParcelableUserMention[] mentions = ParcelableUserMentionUtils.fromUserMentionEntities(resultStatus.getUser(), + resultStatus.getUserMentionEntities()); + if (ArrayUtils.isEmpty(mentions)) { mentionedHondaJOJO = statusUpdate.text.contains("@" + HONDAJOJO_SCREEN_NAME); - } else if (entities.length == 1 && entities[0].getId() == HONDAJOJO_ID) { + } else if (mentions.length == 1 && mentions[0].key.getId() == HONDAJOJO_ID) { mentionedHondaJOJO = true; } - Utils.setLastSeen(this, entities, System.currentTimeMillis()); + Utils.setLastSeen(this, mentions, System.currentTimeMillis()); } if (!notReplyToOther) { final long inReplyToUserId = resultStatus.getInReplyToUserId(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java b/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java index d037cbd45..5188ae2fe 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java @@ -35,7 +35,7 @@ import android.util.Log; import org.apache.commons.lang3.math.NumberUtils; import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.SimpleRefreshTaskParam; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -91,11 +91,11 @@ public class RefreshService extends Service implements Constants { if (BROADCAST_REFRESH_HOME_TIMELINE.equals(action)) { if (!isHomeTimelineRefreshing()) { mTwitterWrapper.getHomeTimelineAsync(new SimpleRefreshTaskParam() { - private AccountKey[] accountIds; + private UserKey[] accountIds; @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { if (accountIds != null) return accountIds; final AccountPreferences[] prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)); @@ -112,11 +112,11 @@ public class RefreshService extends Service implements Constants { } } else if (BROADCAST_REFRESH_NOTIFICATIONS.equals(action)) { mTwitterWrapper.getActivitiesAboutMeAsync(new SimpleRefreshTaskParam() { - private AccountKey[] accountIds; + private UserKey[] accountIds; @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { if (accountIds != null) return accountIds; final AccountPreferences[] prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)); @@ -133,11 +133,11 @@ public class RefreshService extends Service implements Constants { } else if (BROADCAST_REFRESH_DIRECT_MESSAGES.equals(action)) { if (!isReceivedDirectMessagesRefreshing()) { mTwitterWrapper.getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() { - private AccountKey[] accountIds; + private UserKey[] accountIds; @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { if (accountIds != null) return accountIds; final AccountPreferences[] prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)); @@ -155,7 +155,7 @@ public class RefreshService extends Service implements Constants { } else if (BROADCAST_REFRESH_TRENDS.equals(action)) { final AccountPreferences[] prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)); - final AccountKey[] refreshIds = getRefreshableIds(prefs, TrendsRefreshableFilter.INSTANCE); + final UserKey[] refreshIds = getRefreshableIds(prefs, TrendsRefreshableFilter.INSTANCE); if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Auto refreshing trends for %s", Arrays.toString(refreshIds))); } @@ -275,22 +275,22 @@ public class RefreshService extends Service implements Constants { return isNetworkAvailable(this) && (isBatteryOkay(this) || !shouldStopAutoRefreshOnBatteryLow(this)); } - private void getLocalTrends(final AccountKey[] accountIds) { - final AccountKey account_id = getDefaultAccountKey(this); + private void getLocalTrends(final UserKey[] accountIds) { + final UserKey account_id = getDefaultAccountKey(this); final int woeid = mPreferences.getInt(KEY_LOCAL_TRENDS_WOEID, 1); mTwitterWrapper.getLocalTrendsAsync(account_id, woeid); } - private AccountKey[] getRefreshableIds(final AccountPreferences[] prefs, final RefreshableAccountFilter filter) { + private UserKey[] getRefreshableIds(final AccountPreferences[] prefs, final RefreshableAccountFilter filter) { if (prefs == null) return null; - final AccountKey[] temp = new AccountKey[prefs.length]; + final UserKey[] temp = new UserKey[prefs.length]; int i = 0; for (final AccountPreferences pref : prefs) { if (pref.isAutoRefreshEnabled() && filter.isRefreshable(pref)) { temp[i++] = pref.getAccountKey(); } } - final AccountKey[] result = new AccountKey[i]; + final UserKey[] result = new UserKey[i]; System.arraycopy(temp, 0, result, 0, i); return result; } 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 bc039d9dc..32babc5a0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/StreamingService.java @@ -34,11 +34,10 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.api.twitter.model.Warning; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -59,12 +58,12 @@ public class StreamingService extends Service implements Constants { private static final int NOTIFICATION_SERVICE_STARTED = 1; - private final SimpleArrayMap mCallbacks = new SimpleArrayMap<>(); + private final SimpleArrayMap mCallbacks = new SimpleArrayMap<>(); private ContentResolver mResolver; private NotificationManager mNotificationManager; - private AccountKey[] mAccountKeys; + private UserKey[] mAccountKeys; private static final Uri[] MESSAGES_URIS = new Uri[]{DirectMessages.Inbox.CONTENT_URI, DirectMessages.Outbox.CONTENT_URI}; @@ -129,7 +128,7 @@ public class StreamingService extends Service implements Constants { private boolean setTwitterInstances() { final List accountsList = DataStoreUtils.getCredentialsList(this, true); - final AccountKey[] accountKeys = new AccountKey[accountsList.size()]; + final UserKey[] accountKeys = new UserKey[accountsList.size()]; for (int i = 0, j = accountKeys.length; i < j; i++) { final ParcelableCredentials credentials = accountsList.get(i); accountKeys[i] = credentials.account_key; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java index 30eb96f57..eecd4569d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/CacheUsersStatusesTask.java @@ -27,7 +27,7 @@ import com.twitter.Extractor; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.CachedHashtags; import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses; import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers; @@ -65,7 +65,7 @@ public class CacheUsersStatusesTask extends AbstractTask statusesValues = new HashSet<>(); final Set hashTagValues = new HashSet<>(); - final AccountKey accountKey = params.mAccountKey; + final UserKey accountKey = params.mAccountKey; statusesValues.add(ContentValuesCreator.createStatus(status, accountKey)); final String text = InternalTwitterContentUtils.unescapeTwitterStatusText(status.getText()); for (final String hashtag : extractor.extractHashtags(text)) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetActivitiesAboutMeTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetActivitiesAboutMeTask.java index ece78ce2c..e55157275 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetActivitiesAboutMeTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetActivitiesAboutMeTask.java @@ -12,7 +12,7 @@ import org.mariotaku.twidere.api.twitter.model.CursorTimestampResponse; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.task.twitter.GetActivitiesTask; import org.mariotaku.twidere.util.ErrorInfoStore; @@ -34,7 +34,7 @@ public class GetActivitiesAboutMeTask extends GetActivitiesTask { } @Override - protected void saveReadPosition(@NonNull AccountKey accountId, @NonNull Twitter twitter) { + protected void saveReadPosition(@NonNull UserKey accountId, @NonNull Twitter twitter) { try { CursorTimestampResponse response = twitter.getActivitiesAboutMeUnread(true); final String tag = Utils.getReadPositionTagWithAccounts(ReadPositionTag.ACTIVITIES_ABOUT_ME, accountId); @@ -45,7 +45,7 @@ public class GetActivitiesAboutMeTask extends GetActivitiesTask { } @Override - protected ResponseList getActivities(@NonNull final Twitter twitter, @NonNull final AccountKey accountId, @NonNull final Paging paging) throws TwitterException { + protected ResponseList getActivities(@NonNull final Twitter twitter, @NonNull final UserKey accountId, @NonNull final Paging paging) throws TwitterException { if (Utils.isOfficialCredentials(context, accountId)) { return twitter.getActivitiesAboutMe(paging); } 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 beb9ba529..b70526bed 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetDirectMessagesTask.java @@ -16,7 +16,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.DirectMessage; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.message.GetMessagesTaskEvent; import org.mariotaku.twidere.util.AsyncTwitterWrapper; @@ -63,12 +63,12 @@ public abstract class GetDirectMessagesTask extends AbstractTask doLongOperation(final RefreshTaskParam param) { - final AccountKey[] accountKeys = param.getAccountKeys(); + final UserKey[] accountKeys = param.getAccountKeys(); final long[] sinceIds = param.getSinceIds(), maxIds = param.getMaxIds(); final List result = new ArrayList<>(); int idx = 0; final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); - for (final AccountKey accountKey : accountKeys) { + for (final UserKey accountKey : accountKeys) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountKey, true); if (twitter == null) continue; try { @@ -109,7 +109,7 @@ public abstract class GetDirectMessagesTask extends AbstractTask messages, boolean isOutgoing, boolean notify) { + private boolean storeMessages(UserKey accountKey, List messages, boolean isOutgoing, boolean notify) { if (messages == null) return true; final Uri uri = getDatabaseUri(); final ContentValues[] valuesArray = new ContentValues[messages.size()]; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetLocalTrendsTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetLocalTrendsTask.java index 27f853d49..db48a1940 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetLocalTrendsTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetLocalTrendsTask.java @@ -7,7 +7,7 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Trends; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends; import java.util.List; @@ -19,7 +19,7 @@ public class GetLocalTrendsTask extends GetTrendsTask { private final int woeid; - public GetLocalTrendsTask(final Context context, final AccountKey accountKey, final int woeid) { + public GetLocalTrendsTask(final Context context, final UserKey accountKey, final int woeid) { super(context, accountKey); this.woeid = woeid; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java index bac166101..a55128271 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetSavedSearchesTask.java @@ -12,7 +12,7 @@ import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.provider.TwidereDataStore.SavedSearches; import org.mariotaku.twidere.util.ContentValuesCreator; @@ -22,7 +22,7 @@ import org.mariotaku.twidere.util.content.ContentResolverUtils; /** * Created by mariotaku on 16/2/13. */ -public class GetSavedSearchesTask extends AbstractTask, Object> +public class GetSavedSearchesTask extends AbstractTask, Object> implements Constants { private final Context mContext; @@ -32,9 +32,9 @@ public class GetSavedSearchesTask extends AbstractTask doLongOperation(AccountKey[] params) { + public SingleResponse doLongOperation(UserKey[] params) { final ContentResolver cr = mContext.getContentResolver(); - for (AccountKey accountKey : params) { + for (UserKey accountKey : params) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountKey, true); if (twitter == null) continue; try { diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/GetTrendsTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/GetTrendsTask.java index bb447e175..9803d6511 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/GetTrendsTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/GetTrendsTask.java @@ -9,7 +9,7 @@ import android.support.annotation.NonNull; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Trends; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.TwitterAPIFactory; @@ -24,9 +24,9 @@ import java.util.List; public abstract class GetTrendsTask extends AbstractTask { private final Context mContext; - private final AccountKey mAccountId; + private final UserKey mAccountId; - public GetTrendsTask(Context context, final AccountKey accountKey) { + public GetTrendsTask(Context context, final UserKey accountKey) { this.mContext = context; this.mAccountId = accountKey; } @@ -65,7 +65,7 @@ public abstract class GetTrendsTask extends AbstractTask } cr.delete(uri, null, null); ContentResolverUtils.bulkInsert(cr, uri, valuesArray); - ContentResolverUtils.bulkDelete(cr, TwidereDataStore.CachedHashtags.CONTENT_URI, TwidereDataStore.CachedHashtags.NAME, hashtags, null, true); + ContentResolverUtils.bulkDelete(cr, TwidereDataStore.CachedHashtags.CONTENT_URI, TwidereDataStore.CachedHashtags.NAME, hashtags, null); ContentResolverUtils.bulkInsert(cr, TwidereDataStore.CachedHashtags.CONTENT_URI, hashtagValues.toArray(new ContentValues[hashtagValues.size()])); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java index eabeceb51..63691b12d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java @@ -18,7 +18,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Activity; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.message.GetActivitiesTaskEvent; @@ -63,14 +63,14 @@ public abstract class GetActivitiesTask extends AbstractTask activities) { long[] deleteBound = new long[2]; Arrays.fill(deleteBound, -1); @@ -155,11 +155,11 @@ public abstract class GetActivitiesTask extends AbstractTask getActivities(@NonNull final Twitter twitter, - @NonNull final AccountKey accountId, + @NonNull final UserKey accountId, @NonNull final Paging paging) throws TwitterException; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java index 0ec5640f6..309299896 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java @@ -23,7 +23,7 @@ import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.message.GetStatusesTaskEvent; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; @@ -79,7 +79,7 @@ public abstract class GetStatusesTask extends AbstractTask statuses, + private void storeStatus(final UserKey accountKey, final List statuses, final long sinceId, final long maxId, final boolean notify) { if (statuses == null || statuses.isEmpty() || accountKey == null) { return; @@ -160,13 +160,13 @@ public abstract class GetStatusesTask extends AbstractTask doLongOperation(final RefreshTaskParam param) { - final AccountKey[] accountKeys = param.getAccountKeys(); + final UserKey[] accountKeys = param.getAccountKeys(); final long[] maxIds = param.getMaxIds(); final long[] sinceIds = param.getSinceIds(); final List result = new ArrayList<>(); int idx = 0; final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); - for (final AccountKey accountKey : accountKeys) { + for (final UserKey accountKey : accountKeys) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountKey, true); if (twitter == null) continue; try { diff --git a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java index 495a70820..1e9bc944f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java +++ b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java @@ -25,20 +25,20 @@ import android.text.style.URLSpan; import android.view.View; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener; public class TwidereURLSpan extends URLSpan implements Constants { private final int type, highlightStyle; - private final AccountKey accountKey; + private final UserKey accountKey; private final long extraId; private final String url, orig; private final boolean sensitive; private final OnLinkClickListener listener; private final int start, end; - public TwidereURLSpan(final String url, final String orig, final AccountKey accountKey, final long extraId, + public TwidereURLSpan(final String url, final String orig, final UserKey accountKey, final long extraId, final int type, final boolean sensitive, final int highlightStyle, int start, int end, final OnLinkClickListener listener) { super(url); 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 6fbabf36f..232edb49d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java @@ -53,7 +53,6 @@ import org.mariotaku.twidere.api.twitter.model.SavedSearch; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.api.twitter.model.UserList; import org.mariotaku.twidere.api.twitter.model.UserListUpdate; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.BaseRefreshTaskParam; import org.mariotaku.twidere.model.ListResponse; import org.mariotaku.twidere.model.ParcelableStatus; @@ -63,6 +62,7 @@ import org.mariotaku.twidere.model.RefreshTaskParam; import org.mariotaku.twidere.model.Response; import org.mariotaku.twidere.model.SimpleRefreshTaskParam; import org.mariotaku.twidere.model.SingleResponse; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.message.FavoriteTaskEvent; import org.mariotaku.twidere.model.message.FollowRequestTaskEvent; import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent; @@ -78,6 +78,7 @@ import org.mariotaku.twidere.model.message.UsersBlockedEvent; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; import org.mariotaku.twidere.model.util.ParcelableUserListUtils; import org.mariotaku.twidere.model.util.ParcelableUserUtils; +import org.mariotaku.twidere.model.util.UserKeyUtils; import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; @@ -134,7 +135,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { mAsyncTaskManager = asyncTaskManager; } - public int acceptFriendshipAsync(final AccountKey accountKey, final long userId) { + public int acceptFriendshipAsync(final UserKey accountKey, final UserKey userId) { final AcceptFriendshipTask task = new AcceptFriendshipTask(mContext, accountKey, userId); return mAsyncTaskManager.add(task, true); } @@ -146,12 +147,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } } - public int addUserListMembersAsync(final AccountKey accountKey, final long listId, final ParcelableUser... users) { + public int addUserListMembersAsync(final UserKey accountKey, final long listId, final ParcelableUser... users) { final AddUserListMembersTask task = new AddUserListMembersTask(accountKey, listId, users); return mAsyncTaskManager.add(task, true); } - public int cancelRetweetAsync(AccountKey accountKey, long statusId, long myRetweetId) { + public int cancelRetweetAsync(UserKey accountKey, long statusId, long myRetweetId) { if (myRetweetId > 0) return destroyStatusAsync(accountKey, myRetweetId); else if (statusId > 0) @@ -163,7 +164,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { clearNotificationAsync(notificationType, null); } - public void clearNotificationAsync(final int notificationId, @Nullable final AccountKey accountKey) { + public void clearNotificationAsync(final int notificationId, @Nullable final UserKey accountKey) { final ClearNotificationTask task = new ClearNotificationTask(notificationId, accountKey); AsyncTaskUtils.executeTask(task); } @@ -173,104 +174,104 @@ public class AsyncTwitterWrapper extends TwitterWrapper { AsyncTaskUtils.executeTask(task); } - public int createBlockAsync(final AccountKey accountKey, final long user_id) { + public int createBlockAsync(final UserKey accountKey, final long user_id) { final CreateBlockTask task = new CreateBlockTask(accountKey, user_id); return mAsyncTaskManager.add(task, true); } - public int createFavoriteAsync(final AccountKey accountKey, final long statusId) { + public int createFavoriteAsync(final UserKey accountKey, final long statusId) { final CreateFavoriteTask task = new CreateFavoriteTask(accountKey, statusId); return mAsyncTaskManager.add(task, true); } - public int createFriendshipAsync(final AccountKey accountKey, final long userId) { + public int createFriendshipAsync(final UserKey accountKey, final long userId) { final CreateFriendshipTask task = new CreateFriendshipTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int createMultiBlockAsync(final AccountKey accountKey, final long[] userIds) { + public int createMultiBlockAsync(final UserKey accountKey, final long[] userIds) { final CreateMultiBlockTask task = new CreateMultiBlockTask(accountKey, userIds); return mAsyncTaskManager.add(task, true); } - public int createMuteAsync(final AccountKey accountKey, final long user_id) { + public int createMuteAsync(final UserKey accountKey, final long user_id) { final CreateMuteTask task = new CreateMuteTask(accountKey, user_id); return mAsyncTaskManager.add(task, true); } - public int createSavedSearchAsync(final AccountKey accountKey, final String query) { + public int createSavedSearchAsync(final UserKey accountKey, final String query) { final CreateSavedSearchTask task = new CreateSavedSearchTask(accountKey, query); return mAsyncTaskManager.add(task, true); } - public int createUserListAsync(final AccountKey accountKey, final String listName, final boolean isPublic, + public int createUserListAsync(final UserKey accountKey, final String listName, final boolean isPublic, final String description) { final CreateUserListTask task = new CreateUserListTask(mContext, accountKey, listName, isPublic, description); return mAsyncTaskManager.add(task, true); } - public int createUserListSubscriptionAsync(final AccountKey accountKey, final long listId) { + public int createUserListSubscriptionAsync(final UserKey accountKey, final long listId) { final CreateUserListSubscriptionTask task = new CreateUserListSubscriptionTask(accountKey, listId); return mAsyncTaskManager.add(task, true); } - public int deleteUserListMembersAsync(final AccountKey accountKey, final long listId, final ParcelableUser... users) { + public int deleteUserListMembersAsync(final UserKey accountKey, final long listId, final ParcelableUser... users) { final DeleteUserListMembersTask task = new DeleteUserListMembersTask(accountKey, listId, users); return mAsyncTaskManager.add(task, true); } - public int denyFriendshipAsync(final AccountKey accountKey, final long userId) { - final DenyFriendshipTask task = new DenyFriendshipTask(accountKey, userId); + public int denyFriendshipAsync(final UserKey accountKey, final UserKey userId) { + final DenyFriendshipTask task = new DenyFriendshipTask(mContext, accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int destroyBlockAsync(final AccountKey accountKey, final long userId) { + public int destroyBlockAsync(final UserKey accountKey, final long userId) { final DestroyBlockTask task = new DestroyBlockTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int destroyDirectMessageAsync(final AccountKey accountKey, final long messageId) { + public int destroyDirectMessageAsync(final UserKey accountKey, final long messageId) { final DestroyDirectMessageTask task = new DestroyDirectMessageTask(accountKey, messageId); return mAsyncTaskManager.add(task, true); } - public int destroyMessageConversationAsync(final AccountKey accountKey, final long userId) { + public int destroyMessageConversationAsync(final UserKey accountKey, final long userId) { final DestroyMessageConversationTask task = new DestroyMessageConversationTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int destroyFavoriteAsync(final AccountKey accountKey, final long statusId) { + public int destroyFavoriteAsync(final UserKey accountKey, final long statusId) { final DestroyFavoriteTask task = new DestroyFavoriteTask(accountKey, statusId); return mAsyncTaskManager.add(task, true); } - public int destroyFriendshipAsync(final AccountKey accountKey, final long userId) { + public int destroyFriendshipAsync(final UserKey accountKey, final long userId) { final DestroyFriendshipTask task = new DestroyFriendshipTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int destroyMuteAsync(final AccountKey accountKey, final long userId) { + public int destroyMuteAsync(final UserKey accountKey, final long userId) { final DestroyMuteTask task = new DestroyMuteTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int destroySavedSearchAsync(final AccountKey accountKey, final long searchId) { + public int destroySavedSearchAsync(final UserKey accountKey, final long searchId) { final DestroySavedSearchTask task = new DestroySavedSearchTask(accountKey, searchId); return mAsyncTaskManager.add(task, true); } - public int destroyStatusAsync(final AccountKey accountKey, final long statusId) { + public int destroyStatusAsync(final UserKey accountKey, final long statusId) { final DestroyStatusTask task = new DestroyStatusTask(accountKey, statusId); return mAsyncTaskManager.add(task, true); } - public int destroyUserListAsync(final AccountKey accountKey, final long listId) { + public int destroyUserListAsync(final UserKey accountKey, final long listId) { final DestroyUserListTask task = new DestroyUserListTask(mContext, accountKey, listId); return mAsyncTaskManager.add(task, true); } - public int destroyUserListSubscriptionAsync(final AccountKey accountKey, final long listId) { + public int destroyUserListSubscriptionAsync(final UserKey accountKey, final long listId) { final DestroyUserListSubscriptionTask task = new DestroyUserListSubscriptionTask(accountKey, listId); return mAsyncTaskManager.add(task, true); } @@ -279,7 +280,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return mContext; } - public boolean getHomeTimelineAsync(final AccountKey[] accountKeys, final long[] maxIds, final long[] sinceIds) { + public boolean getHomeTimelineAsync(final UserKey[] accountKeys, final long[] maxIds, final long[] sinceIds) { return getHomeTimelineAsync(new BaseRefreshTaskParam(accountKeys, maxIds, sinceIds)); } @@ -290,7 +291,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return true; } - public void getLocalTrendsAsync(final AccountKey accountId, final int woeid) { + public void getLocalTrendsAsync(final UserKey accountId, final int woeid) { final GetLocalTrendsTask task = new GetLocalTrendsTask(mContext, accountId, woeid); TaskStarter.execute(task); } @@ -307,7 +308,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { TaskStarter.execute(task); } - public int getSavedSearchesAsync(AccountKey[] accountKeys) { + public int getSavedSearchesAsync(UserKey[] accountKeys) { final GetSavedSearchesTask task = new GetSavedSearchesTask(mContext); task.setParams(accountKeys); TaskStarter.execute(task); @@ -319,24 +320,24 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return mSendingDraftIds.toArray(); } - public boolean isCreatingFavorite(final AccountKey accountId, final long statusId) { + public boolean isCreatingFavorite(final UserKey accountId, final long statusId) { return mCreatingFavoriteIds.has(accountId.getId(), statusId); } - public boolean isCreatingFriendship(final AccountKey accountKey, final long userId) { + public boolean isCreatingFriendship(final UserKey accountKey, final long userId) { // TODO implementation return false; } - public boolean isCreatingRetweet(final AccountKey accountKey, final long statusId) { + public boolean isCreatingRetweet(final UserKey accountKey, final long statusId) { return mCreatingRetweetIds.has(accountKey.getId(), statusId); } - public boolean isDestroyingFavorite(final AccountKey accountKey, final long statusId) { + public boolean isDestroyingFavorite(final UserKey accountKey, final long statusId) { return mDestroyingFavoriteIds.has(accountKey.getId(), statusId); } - public boolean isDestroyingFriendship(final AccountKey accountKey, final long userId) { + public boolean isDestroyingFriendship(final UserKey accountKey, final long userId) { for (final ManagedAsyncTask task : mAsyncTaskManager.getTaskSpecList()) { if (task instanceof DestroyFriendshipTask) { final DestroyFriendshipTask destroyFriendshipTask = (DestroyFriendshipTask) task; @@ -349,7 +350,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return false; } - public boolean isDestroyingStatus(final AccountKey accountId, final long statusId) { + public boolean isDestroyingStatus(final UserKey accountId, final long statusId) { return mDestroyingStatusIds.has(accountId.getId(), statusId); } @@ -373,16 +374,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper { public void refreshAll() { refreshAll(new GetAccountKeysClosure() { @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return DataStoreUtils.getActivatedAccountKeys(mContext); } }); } - public boolean refreshAll(final AccountKey[] accountKeys) { + public boolean refreshAll(final UserKey[] accountKeys) { return refreshAll(new GetAccountKeysClosure() { @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return accountKeys; } }); @@ -393,7 +394,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return closure.getAccountKeys(); } @@ -407,7 +408,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { getActivitiesAboutMeAsync(new SimpleRefreshTaskParam() { @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return closure.getAccountKeys(); } @@ -421,14 +422,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper { getReceivedDirectMessagesAsync(new SimpleRefreshTaskParam() { @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return closure.getAccountKeys(); } }); getSentDirectMessagesAsync(new SimpleRefreshTaskParam() { @NonNull @Override - public AccountKey[] getAccountKeys() { + public UserKey[] getAccountKeys() { return closure.getAccountKeys(); } }); @@ -443,26 +444,26 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } } - public void removeUnreadCountsAsync(final int position, final SimpleArrayMap> counts) { + public void removeUnreadCountsAsync(final int position, final SimpleArrayMap> counts) { final RemoveUnreadCountsTask task = new RemoveUnreadCountsTask(position, counts); AsyncTaskUtils.executeTask(task); } - public void reportMultiSpam(final AccountKey accountKey, final long[] userIds) { + public void reportMultiSpam(final UserKey accountKey, final long[] userIds) { // TODO implementation } - public int reportSpamAsync(final AccountKey accountKey, final long userId) { + public int reportSpamAsync(final UserKey accountKey, final long userId) { final ReportSpamTask task = new ReportSpamTask(accountKey, userId); return mAsyncTaskManager.add(task, true); } - public int retweetStatusAsync(final AccountKey accountKey, final long statusId) { + public int retweetStatusAsync(final UserKey accountKey, final long statusId) { final RetweetStatusTask task = new RetweetStatusTask(accountKey, statusId); return mAsyncTaskManager.add(task, true); } - public int sendDirectMessageAsync(final AccountKey accountKey, final long recipientId, final String text, + public int sendDirectMessageAsync(final UserKey accountKey, final long recipientId, final String text, final String imageUri) { final Intent intent = new Intent(mContext, BackgroundOperationService.class); intent.setAction(INTENT_ACTION_SEND_DIRECT_MESSAGE); @@ -474,7 +475,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return 0; } - public int updateUserListDetails(final AccountKey accountKey, final long listId, + public int updateUserListDetails(final UserKey accountKey, final long listId, final UserListUpdate update) { final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(mContext, accountKey, listId, update); @@ -488,7 +489,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return null; } - public void updateFriendship(final AccountKey accountKey, final long userId, final FriendshipUpdate update) { + public void updateFriendship(final UserKey accountKey, final long userId, final FriendshipUpdate update) { final Bus bus = mBus; if (bus == null) return; TaskStarter.execute(new AbstractTask, Bus>() { @@ -521,12 +522,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper { TaskStarter.execute(task); } - public void setActivitiesAboutMeUnreadAsync(final AccountKey[] accountKeys, final long cursor) { + public void setActivitiesAboutMeUnreadAsync(final UserKey[] accountKeys, final long cursor) { AbstractTask task = new AbstractTask() { @Override public Object doLongOperation(Object o) { - for (AccountKey accountId : accountKeys) { + for (UserKey accountId : accountKeys) { Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, accountId, false); if (!Utils.isOfficialCredentials(mContext, accountId)) continue; try { @@ -543,26 +544,26 @@ public class AsyncTwitterWrapper extends TwitterWrapper { TaskStarter.execute(task); } - private void addProcessingFriendshipRequestId(AccountKey accountKey, long userId) { - mProcessingFriendshipRequestIds.add(ParcelableUser.calculateHashCode(accountKey.getId(), userId)); + private void addProcessingFriendshipRequestId(UserKey accountKey, UserKey userId) { + mProcessingFriendshipRequestIds.add(ParcelableUser.calculateHashCode(accountKey, userId)); } - private void removeProcessingFriendshipRequestId(AccountKey accountKey, long userId) { - mProcessingFriendshipRequestIds.removeElement(ParcelableUser.calculateHashCode(accountKey.getId(), userId)); + private void removeProcessingFriendshipRequestId(UserKey accountKey, UserKey userId) { + mProcessingFriendshipRequestIds.removeElement(ParcelableUser.calculateHashCode(accountKey, userId)); } - public boolean isProcessingFollowRequest(AccountKey accountId, long userId) { + public boolean isProcessingFollowRequest(UserKey accountId, UserKey userId) { return mProcessingFriendshipRequestIds.contains(ParcelableUser.calculateHashCode(accountId, userId)); } public static class UpdateProfileBannerImageTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final Uri mImageUri; private final boolean mDeleteImage; private final Context mContext; - public UpdateProfileBannerImageTask(final Context context, final AccountKey accountKey, + public UpdateProfileBannerImageTask(final Context context, final UserKey accountKey, final Uri imageUri, final boolean deleteImage) { super(context); mContext = context; @@ -608,12 +609,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper { public static class UpdateProfileImageTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final Uri mImageUri; private final boolean mDeleteImage; private final Context mContext; - public UpdateProfileImageTask(final Context context, final AccountKey accountKey, + public UpdateProfileImageTask(final Context context, final UserKey accountKey, final Uri imageUri, final boolean deleteImage) { super(context); this.mContext = context; @@ -656,27 +657,27 @@ public class AsyncTwitterWrapper extends TwitterWrapper { static class AcceptFriendshipTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; - private final long mUserId; + private final UserKey mAccountKey; + private final UserKey mUserId; - public AcceptFriendshipTask(final Context context, final AccountKey accountKey, final long userId) { + public AcceptFriendshipTask(final Context context, final UserKey accountKey, final UserKey userId) { super(context); mAccountKey = accountKey; mUserId = userId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } - public long getUserId() { + public UserKey getUserId() { return mUserId; } @Override protected void onPreExecute() { final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, - mAccountKey, mUserId); + mAccountKey, mUserId.getId()); event.setFinished(false); bus.post(event); mAsyncTwitterWrapper.addProcessingFriendshipRequestId(mAccountKey, mUserId); @@ -690,7 +691,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountKey, false); if (twitter == null) return SingleResponse.getInstance(); try { - final User user = twitter.acceptFriendship(mUserId); + final User user = twitter.acceptFriendship(mUserId.getId()); return SingleResponse.getInstance(user, null); } catch (final TwitterException e) { return SingleResponse.getInstance(null, e); @@ -700,7 +701,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { @Override protected void onPostExecute(final SingleResponse result) { final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, - mAccountKey, mUserId); + mAccountKey, mUserId.getId()); event.setFinished(true); if (result.hasData()) { final User user = result.getData(); @@ -723,11 +724,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class AddUserListMembersTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long listId; private final ParcelableUser[] users; - public AddUserListMembersTask(final AccountKey accountKey, final long listId, final ParcelableUser[] users) { + public AddUserListMembersTask(final UserKey accountKey, final long listId, final ParcelableUser[] users) { super(mContext); this.mAccountKey = accountKey; this.listId = listId; @@ -739,11 +740,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountKey, false); if (twitter == null || users == null) return SingleResponse.getInstance(); try { - final long[] userIds = new long[users.length]; + final UserKey[] userIds = new UserKey[users.length]; for (int i = 0, j = users.length; i < j; i++) { - userIds[i] = users[i].id; + userIds[i] = users[i].key; } - final UserList result = twitter.addUserListMembers(listId, userIds); + final UserList result = twitter.addUserListMembers(listId, UserKey.getIds(userIds)); final ParcelableUserList list = ParcelableUserListUtils.from(result, mAccountKey); return SingleResponse.getInstance(list, null); } catch (final TwitterException e) { @@ -759,7 +760,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (users.length == 1) { final ParcelableUser user = users[0]; final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); - final String displayName = mUserColorNameManager.getDisplayName(user.id, user.name, + final String displayName = mUserColorNameManager.getDisplayName(user.key, user.name, user.screen_name, nameFirst, false); message = mContext.getString(R.string.added_user_to_list, displayName, result.getData().name); } else { @@ -782,9 +783,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final class ClearNotificationTask extends AsyncTask { private final int notificationType; - private final AccountKey accountKey; + private final UserKey accountKey; - ClearNotificationTask(final int notificationType, final AccountKey accountKey) { + ClearNotificationTask(final int notificationType, final UserKey accountKey) { this.notificationType = notificationType; this.accountKey = accountKey; } @@ -813,10 +814,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateBlockTask extends ManagedAsyncTask> { @NonNull - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public CreateBlockTask(@NonNull final AccountKey accountKey, final long userId) { + public CreateBlockTask(@NonNull final UserKey accountKey, final long userId) { super(mContext); this.mAccountKey = accountKey; this.mUserId = userId; @@ -828,7 +829,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.createBlock(mUserId); - Utils.setLastSeen(mContext, user.getId(), -1); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), -1); for (final Uri uri : TwidereDataStore.STATUSES_URIS) { final Expression where = Expression.and( Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY), @@ -870,10 +871,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateFavoriteTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mStatusId; - public CreateFavoriteTask(final AccountKey accountKey, final long statusId) { + public CreateFavoriteTask(final UserKey accountKey, final long statusId) { super(mContext); this.mAccountKey = accountKey; this.mStatusId = statusId; @@ -948,16 +949,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateFriendshipTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long user_id; - public CreateFriendshipTask(final AccountKey accountKey, final long userId) { + public CreateFriendshipTask(final UserKey accountKey, final long userId) { super(mContext); this.mAccountKey = accountKey; this.user_id = userId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } @@ -972,7 +973,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.createFriendship(user_id); - Utils.setLastSeen(mContext, user.getId(), System.currentTimeMillis()); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), System.currentTimeMillis()); return SingleResponse.getInstance(ParcelableUserUtils.fromUser(user, mAccountKey), null); } catch (final TwitterException e) { return SingleResponse.getInstance(null, e); @@ -1006,10 +1007,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateMultiBlockTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long[] mUserIds; - public CreateMultiBlockTask(final AccountKey accountKey, final long[] userIds) { + public CreateMultiBlockTask(final UserKey accountKey, final long[] userIds) { super(mContext); this.mAccountKey = accountKey; this.mUserIds = userIds; @@ -1070,10 +1071,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateMuteTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public CreateMuteTask(final AccountKey accountKey, final long userId) { + public CreateMuteTask(final UserKey accountKey, final long userId) { super(mContext); this.mAccountKey = accountKey; this.mUserId = userId; @@ -1085,7 +1086,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.createMute(mUserId); - Utils.setLastSeen(mContext, user.getId(), -1); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), -1); final Expression where = Expression.and(Utils.getAccountCompareExpression(), Expression.equals(Statuses.USER_ID, mUserId)); final String[] whereArgs = {String.valueOf(mAccountKey.getId()), @@ -1118,10 +1119,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateSavedSearchTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final String mQuery; - CreateSavedSearchTask(final AccountKey accountKey, final String query) { + CreateSavedSearchTask(final UserKey accountKey, final String query) { super(mContext); mAccountKey = accountKey; mQuery = query; @@ -1160,10 +1161,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class CreateUserListSubscriptionTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long listId; - public CreateUserListSubscriptionTask(final AccountKey accountKey, final long listId) { + public CreateUserListSubscriptionTask(final UserKey accountKey, final long listId) { super(mContext); this.mAccountKey = accountKey; this.listId = listId; @@ -1201,11 +1202,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper { static class CreateUserListTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final String mListName, mDescription; private final boolean mIsPublic; - public CreateUserListTask(Context context, final AccountKey accountKey, final String listName, + public CreateUserListTask(Context context, final UserKey accountKey, final String listName, final boolean isPublic, final String description) { super(context); this.mAccountKey = accountKey; @@ -1249,11 +1250,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DeleteUserListMembersTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserListId; private final ParcelableUser[] users; - public DeleteUserListMembersTask(final AccountKey accountKey, final long userListId, final ParcelableUser[] users) { + public DeleteUserListMembersTask(final UserKey accountKey, final long userListId, final ParcelableUser[] users) { super(mContext); mAccountKey = accountKey; mUserListId = userListId; @@ -1265,11 +1266,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountKey, false); if (twitter == null) return SingleResponse.getInstance(); try { - final long[] userIds = new long[users.length]; + final UserKey[] userIds = new UserKey[users.length]; for (int i = 0, j = users.length; i < j; i++) { - userIds[i] = users[i].id; + userIds[i] = users[i].key; } - final UserList userList = twitter.deleteUserListMembers(mUserListId, userIds); + final UserList userList = twitter.deleteUserListMembers(mUserListId, UserKey.getIds(userIds)); final ParcelableUserList list = ParcelableUserListUtils.from(userList, mAccountKey); return SingleResponse.getInstance(list, null); } catch (final TwitterException e) { @@ -1285,7 +1286,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (users.length == 1) { final ParcelableUser user = users[0]; final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST); - final String displayName = mUserColorNameManager.getDisplayName(user.id, + final String displayName = mUserColorNameManager.getDisplayName(user.key, user.name, user.screen_name, nameFirst, false); message = mContext.getString(R.string.deleted_user_from_list, displayName, result.getData().name); @@ -1309,30 +1310,23 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DenyFriendshipTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; - private final long mUserId; + private final UserKey mAccountKey; + private final UserKey mUserId; - public DenyFriendshipTask(final AccountKey accountKey, final long userId) { - super(mContext); + public DenyFriendshipTask(final Context context, final UserKey accountKey, final UserKey userId) { + super(context); mAccountKey = accountKey; mUserId = userId; } - public AccountKey getAccountKey() { - return mAccountKey; - } - - public long getUserId() { - return mUserId; - } - @Override protected SingleResponse doInBackground(final Object... params) { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountKey, false); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountKey, + false); if (twitter == null) return SingleResponse.getInstance(); try { - final User user = twitter.denyFriendship(mUserId); + final User user = twitter.denyFriendship(mUserId.getId()); return SingleResponse.getInstance(user, null); } catch (final TwitterException e) { return SingleResponse.getInstance(null, e); @@ -1343,7 +1337,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { protected void onPreExecute() { addProcessingFriendshipRequestId(mAccountKey, mUserId); final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, - mAccountKey, mUserId); + mAccountKey, mUserId.getId()); event.setFinished(false); bus.post(event); super.onPreExecute(); @@ -1352,7 +1346,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { @Override protected void onPostExecute(final SingleResponse result) { final FollowRequestTaskEvent event = new FollowRequestTaskEvent(FollowRequestTaskEvent.Action.ACCEPT, - mAccountKey, mUserId); + mAccountKey, mUserId.getId()); event.setFinished(true); if (result.hasData()) { final User user = result.getData(); @@ -1374,10 +1368,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyBlockTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public DestroyBlockTask(final AccountKey accountKey, final long userId) { + public DestroyBlockTask(final UserKey accountKey, final long userId) { super(mContext); mAccountKey = accountKey; mUserId = userId; @@ -1389,7 +1383,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.destroyBlock(mUserId); - Utils.setLastSeen(mContext, user.getId(), -1); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), -1); return SingleResponse.getInstance(ParcelableUserUtils.fromUser(user, mAccountKey), null); } catch (final TwitterException e) { return SingleResponse.getInstance(null, e); @@ -1417,10 +1411,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyDirectMessageTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mMessageId; - public DestroyDirectMessageTask(final AccountKey accountKey, final long messageId) { + public DestroyDirectMessageTask(final UserKey accountKey, final long messageId) { super(mContext); mAccountKey = accountKey; mMessageId = messageId; @@ -1474,15 +1468,15 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyMessageConversationTask extends ManagedAsyncTask> { private final long mUserId; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; - public DestroyMessageConversationTask(final AccountKey accountKey, final long userId) { + public DestroyMessageConversationTask(final UserKey accountKey, final long userId) { super(mContext); mAccountKey = accountKey; mUserId = userId; } - private void deleteMessages(final AccountKey accountKey, final long userId) { + private void deleteMessages(final UserKey accountKey, final long userId) { final String[] whereArgs = {accountKey.toString(), String.valueOf(userId)}; mResolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and( Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY), @@ -1536,10 +1530,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyFavoriteTask extends ManagedAsyncTask> { @NonNull - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mStatusId; - public DestroyFavoriteTask(@NonNull final AccountKey accountKey, final long statusId) { + public DestroyFavoriteTask(@NonNull final UserKey accountKey, final long statusId) { super(mContext); this.mAccountKey = accountKey; this.mStatusId = statusId; @@ -1608,16 +1602,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyFriendshipTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public DestroyFriendshipTask(final AccountKey accountKey, final long userId) { + public DestroyFriendshipTask(final UserKey accountKey, final long userId) { super(mContext); mAccountKey = accountKey; mUserId = userId; } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return mAccountKey; } @@ -1633,7 +1627,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { try { final User user = twitter.destroyFriendship(mUserId); // remove user tweets and retweets - Utils.setLastSeen(mContext, user.getId(), -1); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), -1); final Expression where = Expression.and( Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY), Expression.or( @@ -1670,10 +1664,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyMuteTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public DestroyMuteTask(final AccountKey accountKey, final long userId) { + public DestroyMuteTask(final UserKey accountKey, final long userId) { super(mContext); mAccountKey = accountKey; mUserId = userId; @@ -1685,7 +1679,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (twitter == null) return SingleResponse.getInstance(); try { final User user = twitter.destroyMute(mUserId); - Utils.setLastSeen(mContext, user.getId(), -1); + Utils.setLastSeen(mContext, UserKeyUtils.fromUser(user), -1); return SingleResponse.getInstance(ParcelableUserUtils.fromUser(user, mAccountKey), null); } catch (final TwitterException e) { return SingleResponse.getInstance(null, e); @@ -1713,10 +1707,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroySavedSearchTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mSearchId; - DestroySavedSearchTask(final AccountKey accountKey, final long searchId) { + DestroySavedSearchTask(final UserKey accountKey, final long searchId) { super(mContext); mAccountKey = accountKey; mSearchId = searchId; @@ -1749,10 +1743,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyStatusTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mStatusId; - public DestroyStatusTask(final AccountKey accountKey, final long statusId) { + public DestroyStatusTask(final UserKey accountKey, final long statusId) { super(mContext); this.mAccountKey = accountKey; this.mStatusId = statusId; @@ -1812,10 +1806,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class DestroyUserListSubscriptionTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mListId; - public DestroyUserListSubscriptionTask(@NonNull final AccountKey accountKey, final long listId) { + public DestroyUserListSubscriptionTask(@NonNull final UserKey accountKey, final long listId) { super(mContext); mAccountKey = accountKey; mListId = listId; @@ -1854,10 +1848,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { static class DestroyUserListTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mListId; - public DestroyUserListTask(Context context, final AccountKey accountKey, final long listId) { + public DestroyUserListTask(Context context, final UserKey accountKey, final long listId) { super(context); mAccountKey = accountKey; mListId = listId; @@ -1954,9 +1948,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper { final class RemoveUnreadCountsTask extends AsyncTask { private final int position; - private final SimpleArrayMap> counts; + private final SimpleArrayMap> counts; - RemoveUnreadCountsTask(final int position, final SimpleArrayMap> counts) { + RemoveUnreadCountsTask(final int position, final SimpleArrayMap> counts) { this.position = position; this.counts = counts; } @@ -1970,10 +1964,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class ReportSpamTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mUserId; - public ReportSpamTask(final AccountKey accountKey, final long userId) { + public ReportSpamTask(final UserKey accountKey, final long userId) { super(mContext); this.mAccountKey = accountKey; this.mUserId = userId; @@ -2011,10 +2005,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { class RetweetStatusTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long statusId; - public RetweetStatusTask(@NonNull final AccountKey accountKey, final long statusId) { + public RetweetStatusTask(@NonNull final UserKey accountKey, final long statusId) { super(mContext); this.mAccountKey = accountKey; this.statusId = statusId; @@ -2078,12 +2072,12 @@ public class AsyncTwitterWrapper extends TwitterWrapper { static class UpdateUserListDetailsTask extends ManagedAsyncTask> { - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long listId; private final UserListUpdate update; private Context mContext; - public UpdateUserListDetailsTask(Context context, final AccountKey accountKey, + public UpdateUserListDetailsTask(Context context, final UserKey accountKey, final long listId, UserListUpdate update) { super(context); this.mAccountKey = accountKey; @@ -2124,6 +2118,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } public interface GetAccountKeysClosure { - AccountKey[] getAccountKeys(); + UserKey[] getAccountKeys(); } } 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 ed732c226..b2d795e1e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ContentValuesCreator.java @@ -30,7 +30,7 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.Trend; import org.mariotaku.twidere.api.twitter.model.Trends; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.Draft; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.model.ParcelableActivityValuesCreator; @@ -66,7 +66,7 @@ import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText; public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createCachedRelationship(final Relationship relationship, - final AccountKey accountKey) { + final UserKey accountKey) { final ContentValues values = new ContentValues(); values.put(CachedRelationships.ACCOUNT_KEY, accountKey.toString()); values.put(CachedRelationships.USER_ID, relationship.getTargetUserId()); @@ -86,7 +86,7 @@ public final class ContentValuesCreator implements TwidereConstants { } public static ContentValues createDirectMessage(final DirectMessage message, - final AccountKey accountKey, + final UserKey accountKey, final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); @@ -131,7 +131,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableStatus status) { if (status == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, status.user_id); + values.put(Filters.Users.USER_ID, status.user_key.toString()); values.put(Filters.Users.NAME, status.user_name); values.put(Filters.Users.SCREEN_NAME, status.user_screen_name); return values; @@ -140,7 +140,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableUser user) { if (user == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, user.id); + values.put(Filters.Users.USER_ID, user.key.toString()); values.put(Filters.Users.NAME, user.name); values.put(Filters.Users.SCREEN_NAME, user.screen_name); return values; @@ -149,13 +149,13 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues createFilteredUser(final ParcelableUserMention user) { if (user == null) return null; final ContentValues values = new ContentValues(); - values.put(Filters.Users.USER_ID, user.id); + values.put(Filters.Users.USER_ID, user.key.toString()); values.put(Filters.Users.NAME, user.name); values.put(Filters.Users.SCREEN_NAME, user.screen_name); return values; } - public static ContentValues createMessageDraft(final AccountKey accountKey, final long recipientId, + public static ContentValues createMessageDraft(final UserKey accountKey, final long recipientId, final String text, final String imageUri) { final ContentValues values = new ContentValues(); values.put(Drafts.ACTION_TYPE, Draft.Action.SEND_DIRECT_MESSAGE); @@ -175,7 +175,7 @@ public final class ContentValuesCreator implements TwidereConstants { } public static ContentValues createSavedSearch(final SavedSearch savedSearch, - final AccountKey accountKey) { + final UserKey accountKey) { final ContentValues values = new ContentValues(); values.put(SavedSearches.ACCOUNT_KEY, accountKey.toString()); values.put(SavedSearches.SEARCH_ID, savedSearch.getId()); @@ -186,7 +186,7 @@ public final class ContentValuesCreator implements TwidereConstants { } public static ContentValues[] createSavedSearches(final List savedSearches, - final AccountKey accountKey) { + final UserKey accountKey) { final ContentValues[] resultValuesArray = new ContentValues[savedSearches.size()]; for (int i = 0, j = savedSearches.size(); i < j; i++) { resultValuesArray[i] = createSavedSearch(savedSearches.get(i), accountKey); @@ -195,7 +195,7 @@ public final class ContentValuesCreator implements TwidereConstants { } @NonNull - public static ContentValues createStatus(final Status orig, final AccountKey accountKey) { + public static ContentValues createStatus(final Status orig, final UserKey accountKey) { return ParcelableStatusValuesCreator.create(ParcelableStatusUtils.fromStatus(orig, accountKey, false)); } @@ -214,14 +214,14 @@ public final class ContentValuesCreator implements TwidereConstants { public static void createStatusActivity(@NonNull final ParcelableStatus status, @NonNull final ContentValues values) { if (status.is_retweet) { - values.put(Activities.STATUS_RETWEETED_BY_USER_ID, status.retweeted_by_user_id); + values.put(Activities.STATUS_RETWEETED_BY_USER_ID, String.valueOf(status.retweeted_by_user_id)); } else if (status.is_quote) { values.put(Activities.STATUS_QUOTE_TEXT_HTML, status.quoted_text_html); values.put(Activities.STATUS_QUOTE_TEXT_PLAIN, status.quoted_text_plain); values.put(Activities.STATUS_QUOTE_SOURCE, status.quoted_source); - values.put(Activities.STATUS_QUOTED_USER_ID, status.quoted_user_id); + values.put(Activities.STATUS_QUOTED_USER_ID, String.valueOf(status.quoted_user_id)); } - values.put(Activities.STATUS_USER_ID, status.user_id); + values.put(Activities.STATUS_USER_ID, String.valueOf(status.user_key)); values.put(Activities.STATUS_USER_FOLLOWING, status.user_is_following); values.put(Activities.STATUS_TEXT_HTML, status.text_html); values.put(Activities.STATUS_TEXT_PLAIN, status.text_plain); @@ -247,7 +247,7 @@ public final class ContentValuesCreator implements TwidereConstants { public static ContentValues makeCachedUserContentValues(final ParcelableUser user) { if (user == null) return null; final ContentValues values = new ContentValues(); - values.put(CachedUsers.USER_ID, user.id); + values.put(CachedUsers.USER_KEY, String.valueOf(user.key)); values.put(CachedUsers.NAME, user.name); values.put(CachedUsers.SCREEN_NAME, user.screen_name); values.put(CachedUsers.PROFILE_IMAGE_URL, user.profile_image_url); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java index e1a31c57c..54dc3946f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java @@ -49,7 +49,7 @@ import org.mariotaku.twidere.fragment.support.TrendsSuggestionsFragment; import org.mariotaku.twidere.fragment.support.UserFavoritesFragment; import org.mariotaku.twidere.fragment.support.UserListTimelineFragment; import org.mariotaku.twidere.fragment.support.UserTimelineFragment; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.CustomTabConfiguration; import org.mariotaku.twidere.model.CustomTabConfiguration.ExtraConfiguration; import org.mariotaku.twidere.model.SupportTabSpec; @@ -292,8 +292,8 @@ public class CustomTabUtils implements Constants { } public static boolean hasAccountId(final Context context, @NonNull final Bundle args, - final AccountKey[] activatedAccountKeys, AccountKey accountKey) { - final AccountKey[] accountKeys = Utils.getAccountKeys(context, args); + final UserKey[] activatedAccountKeys, UserKey accountKey) { + final UserKey[] accountKeys = Utils.getAccountKeys(context, args); if (accountKeys != null) { return ArrayUtils.contains(accountKeys, accountKey); } 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 dd8c4dfa1..b03c32dda 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java @@ -49,7 +49,7 @@ import org.mariotaku.sqliteqb.library.query.SQLSelectQuery; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.api.twitter.model.Activity; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices; @@ -98,9 +98,9 @@ import static org.mariotaku.twidere.provider.TwidereDataStore.STATUSES_URIS; */ public class DataStoreUtils implements Constants { static final UriMatcher CONTENT_PROVIDER_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); - static Map sAccountColors = new HashMap<>(); - static Map sAccountScreenNames = new HashMap<>(); - static Map sAccountNames = new HashMap<>(); + static Map sAccountColors = new HashMap<>(); + static Map sAccountScreenNames = new HashMap<>(); + static Map sAccountNames = new HashMap<>(); static { CONTENT_PROVIDER_URI_MATCHER.addURI(TwidereDataStore.AUTHORITY, Accounts.CONTENT_PATH, @@ -200,14 +200,14 @@ public class DataStoreUtils implements Constants { @NonNull public static long[] getNewestMessageIds(@NonNull final Context context, @NonNull final Uri uri, - @NonNull final AccountKey[] accountKeys) { + @NonNull final UserKey[] accountKeys) { return getLongFieldArray(context, uri, accountKeys, 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) { + @NonNull final UserKey[] accountKeys) { return getLongFieldArray(context, uri, 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) { + @NonNull final UserKey[] accountKeys) { return getLongFieldArray(context, uri, 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) { + @NonNull final UserKey[] accountKeys) { return getLongFieldArray(context, uri, 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) { + final UserKey[] accountKeys) { return getLongFieldArray(context, uri, accountKeys, Activities.ACCOUNT_KEY, Activities.MAX_POSITION, new OrderBy(SQLFunctions.MAX(Activities.TIMESTAMP))); } @@ -237,19 +237,19 @@ public class DataStoreUtils implements Constants { @NonNull public static long[] getOldestActivityMaxPositions(@NonNull final Context context, @NonNull final Uri uri, - @NonNull final AccountKey[] accountKeys) { + @NonNull final UserKey[] accountKeys) { return getLongFieldArray(context, uri, accountKeys, Activities.ACCOUNT_KEY, Activities.MAX_POSITION, new OrderBy(SQLFunctions.MIN(Activities.TIMESTAMP))); } - public static int getStatusCount(final Context context, final Uri uri, final AccountKey accountId) { + public static int getStatusCount(final Context context, final Uri uri, final UserKey accountId) { final String where = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).getSQL(); final String[] whereArgs = {accountId.toString()}; return queryCount(context, uri, where, whereArgs); } public static int getActivitiesCount(@NonNull final Context context, @NonNull final Uri uri, - @NonNull final AccountKey accountKey) { + @NonNull final UserKey accountKey) { final String where = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).getSQL(); return queryCount(context, uri, where, new String[]{accountKey.toString()}); } @@ -287,7 +287,7 @@ public class DataStoreUtils implements Constants { final Expression filteredUsersWhere = Expression.or( Expression.in(new Column(new Table(table), Statuses.USER_ID), filteredUsersQuery), Expression.in(new Column(new Table(table), Statuses.RETWEETED_BY_USER_ID), filteredUsersQuery), - Expression.in(new Column(new Table(table), Statuses.QUOTED_USER_ID), filteredUsersQuery) + Expression.in(new Column(new Table(table), Statuses.QUOTED_USER_KEY), filteredUsersQuery) ); final SQLSelectQuery.Builder filteredIdsQueryBuilder = SQLQueryBuilder .select(new Column(new Table(table), Statuses._ID)) @@ -331,7 +331,7 @@ public class DataStoreUtils implements Constants { } - public static String getAccountDisplayName(final Context context, final AccountKey accountKey, final boolean nameFirst) { + public static String getAccountDisplayName(final Context context, final UserKey accountKey, final boolean nameFirst) { final String name; if (nameFirst) { name = getAccountName(context, accountKey); @@ -341,7 +341,7 @@ public class DataStoreUtils implements Constants { return name; } - public static String getAccountName(final Context context, final AccountKey accountKey) { + public static String getAccountName(final Context context, final UserKey accountKey) { if (context == null) return null; final String cached = sAccountNames.get(accountKey); if (!isEmpty(cached)) return cached; @@ -360,7 +360,7 @@ public class DataStoreUtils implements Constants { } } - public static String getAccountScreenName(final Context context, final AccountKey accountKey) { + public static String getAccountScreenName(final Context context, final UserKey accountKey) { if (context == null) return null; final String cached = sAccountScreenNames.get(accountKey); if (!isEmpty(cached)) return cached; @@ -383,7 +383,7 @@ public class DataStoreUtils implements Constants { return getAccountScreenNames(context, null); } - public static String[] getAccountScreenNames(final Context context, @Nullable final AccountKey[] accountKeys) { + public static String[] getAccountScreenNames(final Context context, @Nullable final UserKey[] 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_KEY), @@ -405,17 +405,17 @@ public class DataStoreUtils implements Constants { } @NonNull - public static AccountKey[] getActivatedAccountKeys(final Context context) { - if (context == null) return new AccountKey[0]; + public static UserKey[] getActivatedAccountKeys(final Context context) { + if (context == null) return new UserKey[0]; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[]{Accounts.ACCOUNT_KEY}, Accounts.IS_ACTIVATED + " = 1", null, null); - if (cur == null) return new AccountKey[0]; + if (cur == null) return new UserKey[0]; try { cur.moveToFirst(); - final AccountKey[] ids = new AccountKey[cur.getCount()]; + final UserKey[] ids = new UserKey[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { - ids[i++] = AccountKey.valueOf(cur.getString(0)); + ids[i++] = UserKey.valueOf(cur.getString(0)); cur.moveToNext(); } return ids; @@ -424,13 +424,13 @@ public class DataStoreUtils implements Constants { } } - public static int getStatusesCount(final Context context, final Uri uri, final long sinceId, final AccountKey... accountKeys) { + public static int getStatusesCount(final Context context, final Uri uri, final long sinceId, final UserKey... accountKeys) { if (context == null) return 0; final RawItemArray idsIn; if (ArrayUtils.isEmpty(accountKeys)) { - idsIn = new RawItemArray(AccountKey.getIds(getActivatedAccountKeys(context))); + idsIn = new RawItemArray(UserKey.getIds(getActivatedAccountKeys(context))); } else { - idsIn = new RawItemArray(AccountKey.getIds(accountKeys)); + idsIn = new RawItemArray(UserKey.getIds(accountKeys)); } final Expression selection = Expression.and( Expression.in(new Column(Statuses.ACCOUNT_KEY), idsIn), @@ -442,13 +442,13 @@ public class DataStoreUtils implements Constants { public static int getActivitiesCount(final Context context, final Uri uri, final Expression extraWhere, final String[] extraWhereArgs, - final long sinceTimestamp, boolean followingOnly, final AccountKey... accountKeys) { + final long sinceTimestamp, boolean followingOnly, final UserKey... accountKeys) { if (context == null) return 0; final RawItemArray idsIn; if (ArrayUtils.isEmpty(accountKeys)) { - idsIn = new RawItemArray(AccountKey.getIds(getActivatedAccountKeys(context))); + idsIn = new RawItemArray(UserKey.getIds(getActivatedAccountKeys(context))); } else { - idsIn = new RawItemArray(AccountKey.getIds(accountKeys)); + idsIn = new RawItemArray(UserKey.getIds(accountKeys)); } Expression[] expressions; if (extraWhere != null) { @@ -615,7 +615,7 @@ public class DataStoreUtils implements Constants { } @WorkerThread - public static int getAccountColor(final Context context, final AccountKey accountKey) { + public static int getAccountColor(final Context context, final UserKey accountKey) { if (context == null) return Color.TRANSPARENT; final Integer cached = sAccountColors.get(accountKey); if (cached != null) return cached; @@ -654,7 +654,7 @@ public class DataStoreUtils implements Constants { } } - public static AccountKey getAccountKey(final Context context, final String screenName) { + public static UserKey getAccountKey(final Context context, final String screenName) { if (context == null || isEmpty(screenName)) return null; final String[] projection = {Accounts.ACCOUNT_KEY}; final String where = Expression.equalsArgs(Accounts.SCREEN_NAME).getSQL(); @@ -664,7 +664,7 @@ public class DataStoreUtils implements Constants { if (cur == null) return null; try { if (cur.moveToFirst()) { - return AccountKey.valueOf(cur.getString(0)); + return UserKey.valueOf(cur.getString(0)); } return null; } finally { @@ -673,18 +673,18 @@ public class DataStoreUtils implements Constants { } @NonNull - public static AccountKey[] getAccountKeys(final Context context) { - if (context == null) return new AccountKey[0]; + public static UserKey[] getAccountKeys(final Context context) { + if (context == null) return new UserKey[0]; 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]; + if (cur == null) return new UserKey[0]; try { cur.moveToFirst(); - final AccountKey[] ids = new AccountKey[cur.getCount()]; + final UserKey[] ids = new UserKey[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { - ids[i++] = AccountKey.valueOf(cur.getString(0)); + ids[i++] = UserKey.valueOf(cur.getString(0)); cur.moveToNext(); } return ids; @@ -711,7 +711,7 @@ public class DataStoreUtils implements Constants { final int itemLimit = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).getInt( KEY_DATABASE_ITEM_LIMIT, DEFAULT_DATABASE_ITEM_LIMIT); - for (final AccountKey accountKey : getAccountKeys(context)) { + for (final UserKey accountKey : getAccountKeys(context)) { // Clean statuses. for (final Uri uri : STATUSES_URIS) { if (CachedStatuses.CONTENT_URI.equals(uri)) { @@ -803,7 +803,7 @@ public class DataStoreUtils implements Constants { @NonNull static long[] getLongFieldArray(@NonNull Context context, @NonNull Uri uri, - @NonNull AccountKey[] keys, @NonNull String keyField, + @NonNull UserKey[] keys, @NonNull String keyField, @NonNull String valueField, @Nullable OrderBy sortExpression) { final ContentResolver resolver = context.getContentResolver(); final long[] messageIds = new long[keys.length]; @@ -821,7 +821,7 @@ public class DataStoreUtils implements Constants { if (cur == null) return messageIds; try { while (cur.moveToNext()) { - final AccountKey accountKey = AccountKey.valueOf(cur.getString(0)); + final UserKey accountKey = UserKey.valueOf(cur.getString(0)); int idx = ArrayUtils.indexOf(keys, accountKey); if (idx < 0) continue; messageIds[idx] = cur.getLong(1); @@ -879,7 +879,7 @@ public class DataStoreUtils implements Constants { @Nullable public static Cursor getAccountCursor(@NonNull final Context context, final String[] columns, - @NonNull final AccountKey accountKey) { + @NonNull final UserKey accountKey) { final ContentResolver cr = context.getContentResolver(); final long accountId = accountKey.getId(); final String accountHost = accountKey.getHost(); @@ -910,7 +910,7 @@ public class DataStoreUtils implements Constants { return cr.query(Accounts.CONTENT_URI, columns, where, whereArgs, null); } - public static String getAccountType(@NonNull final Context context, @NonNull final AccountKey accountKey) { + public static String getAccountType(@NonNull final Context context, @NonNull final UserKey accountKey) { final String[] projection = {Accounts.ACCOUNT_TYPE}; final Cursor cur = getAccountCursor(context, projection, accountKey); if (cur == null) return null; @@ -960,7 +960,7 @@ public class DataStoreUtils implements Constants { } public static int getInteractionsCount(final Context context, @Nullable final Bundle extraArgs, - final AccountKey[] accountIds, final long position) { + final UserKey[] accountIds, final long position) { Expression extraWhere = null; String[] extraWhereArgs = null; boolean followingOnly = false; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java index 7d7e69892..f7778614d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java @@ -7,7 +7,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** @@ -38,7 +38,7 @@ public class ErrorInfoStore { return get(key + "_" + extraId); } - public int get(String key, AccountKey extraId) { + public int get(String key, UserKey extraId) { final String host = extraId.getHost(); if (host == null) { return get(key, extraId.getId()); @@ -55,7 +55,7 @@ public class ErrorInfoStore { put(key + "_" + extraId, code); } - public void put(String key, AccountKey extraId, int code) { + public void put(String key, UserKey extraId, int code) { final String host = extraId.getHost(); if (host == null) { put(key, extraId.getId(), code); @@ -87,7 +87,7 @@ public class ErrorInfoStore { remove(key + "_" + extraId); } - public void remove(String key, AccountKey extraId) { + public void remove(String key, UserKey extraId) { final String host = extraId.getHost(); if (host == null) { remove(key, extraId.getId()); 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 613a154a5..ecac80754 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/IntentUtils.java @@ -24,13 +24,13 @@ import org.mariotaku.twidere.activity.support.MediaViewerActivity; import org.mariotaku.twidere.constant.SharedPreferenceConstants; import org.mariotaku.twidere.fragment.support.SensitiveContentWarningDialogFragment; import org.mariotaku.twidere.fragment.support.UserFragment; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableLocation; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserList; +import org.mariotaku.twidere.model.UserKey; import java.util.ArrayList; import java.util.List; @@ -63,8 +63,8 @@ public class IntentUtils implements Constants { builder.scheme(TwidereConstants.SCHEME_TWIDERE); builder.authority(TwidereConstants.AUTHORITY_USER); builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_KEY, user.account_key.toString()); - if (user.id > 0) { - builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_USER_ID, String.valueOf(user.id)); + if (user.key != null) { + builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_USER_ID, user.key.toString()); } if (user.screen_name != null) { builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_SCREEN_NAME, user.screen_name); @@ -83,7 +83,7 @@ public class IntentUtils implements Constants { } } - public static void openUserProfile(@NonNull final Context context, @Nullable final AccountKey accountKey, + public static void openUserProfile(@NonNull final Context context, @Nullable final UserKey accountKey, final long userId, final String screenName, final Bundle activityOptions, final boolean newDocument, @UserFragment.Referral final String referral) { @@ -113,7 +113,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openUserMentions(@NonNull final Context context, @Nullable final AccountKey accountKey, final String screenName) { + public static void openUserMentions(@NonNull final Context context, @Nullable final UserKey accountKey, final String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(TwidereConstants.SCHEME_TWIDERE); builder.authority(TwidereConstants.AUTHORITY_USER_MENTIONS); @@ -141,13 +141,13 @@ public class IntentUtils implements Constants { getPrimaryMedia(status), options, newDocument); } - public static void openMedia(@NonNull final Context context, @Nullable final AccountKey accountKey, final boolean isPossiblySensitive, + public static void openMedia(@NonNull final Context context, @Nullable final UserKey accountKey, final boolean isPossiblySensitive, final ParcelableMedia current, final ParcelableMedia[] media, final Bundle options, final boolean newDocument) { openMedia(context, accountKey, isPossiblySensitive, null, null, current, media, options, newDocument); } - public static void openMedia(@NonNull final Context context, @Nullable final AccountKey accountKey, final boolean isPossiblySensitive, + public static void openMedia(@NonNull final Context context, @Nullable final UserKey accountKey, final boolean isPossiblySensitive, final ParcelableStatus status, final ParcelableDirectMessage message, final ParcelableMedia current, final ParcelableMedia[] media, final Bundle options, final boolean newDocument) { @@ -179,7 +179,7 @@ public class IntentUtils implements Constants { } } - public static void openMediaDirectly(@NonNull final Context context, @Nullable final AccountKey accountKey, + public static void openMediaDirectly(@NonNull final Context context, @Nullable final UserKey accountKey, final ParcelableStatus status, final ParcelableMedia current, final Bundle options, final boolean newDocument) { openMediaDirectly(context, accountKey, status, null, current, getPrimaryMedia(status), @@ -195,14 +195,14 @@ public class IntentUtils implements Constants { } public static void openMediaDirectly(@NonNull final Context context, - @Nullable final AccountKey accountKey, + @Nullable final UserKey accountKey, final ParcelableDirectMessage message, final ParcelableMedia current, final ParcelableMedia[] media, final Bundle options, final boolean newDocument) { openMediaDirectly(context, accountKey, null, message, current, media, options, newDocument); } - public static void openMediaDirectly(@NonNull final Context context, @Nullable final AccountKey accountKey, + public static void openMediaDirectly(@NonNull final Context context, @Nullable final UserKey accountKey, final ParcelableStatus status, final ParcelableDirectMessage message, final ParcelableMedia current, final ParcelableMedia[] media, final Bundle options, final boolean newDocument) { @@ -230,7 +230,7 @@ public class IntentUtils implements Constants { } public static Uri getMediaViewerUri(@NonNull final String type, final long id, - @Nullable final AccountKey accountKey) { + @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority("media"); @@ -243,7 +243,7 @@ public class IntentUtils implements Constants { } public static void openMessageConversation(@NonNull final Context context, - @Nullable final AccountKey accountKey, + @Nullable final UserKey accountKey, final long recipientId) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -260,7 +260,7 @@ public class IntentUtils implements Constants { } public static void openIncomingFriendships(@NonNull final Context context, - @Nullable final AccountKey accountKey) { + @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_INCOMING_FRIENDSHIPS); @@ -285,7 +285,7 @@ public class IntentUtils implements Constants { } public static void openMutesUsers(@NonNull final Context context, - @Nullable final AccountKey accountKey) { + @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_MUTES_USERS); @@ -298,7 +298,7 @@ public class IntentUtils implements Constants { } public static void openScheduledStatuses(@NonNull final Context context, - @Nullable final AccountKey accountKey) { + @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_SCHEDULED_STATUSES); @@ -310,7 +310,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openSavedSearches(@NonNull final Context context, @Nullable final AccountKey accountKey) { + public static void openSavedSearches(@NonNull final Context context, @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_SAVED_SEARCHES); @@ -322,11 +322,11 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openSearch(@NonNull final Context context, @Nullable final AccountKey accountKey, final String query) { + public static void openSearch(@NonNull final Context context, @Nullable final UserKey accountKey, final String query) { openSearch(context, accountKey, query, null); } - public static void openSearch(@NonNull final Context context, @Nullable final AccountKey accountKey, final String query, String type) { + public static void openSearch(@NonNull final Context context, @Nullable final UserKey accountKey, final String query, String type) { final Intent intent = new Intent(Intent.ACTION_VIEW); // Some devices cannot process query parameter with hashes well, so add this intent extra intent.putExtra(EXTRA_QUERY, query); @@ -350,7 +350,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openStatus(@NonNull final Context context, @Nullable final AccountKey accountKey, final long statusId) { + public static void openStatus(@NonNull final Context context, @Nullable final UserKey accountKey, final long statusId) { if (statusId <= 0) return; final Uri uri = LinkCreator.getTwidereStatusLink(accountKey, statusId); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); @@ -358,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 = status.account_key; + final UserKey accountKey = status.account_key; final long statusId = status.id; final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_STATUS, status); @@ -389,7 +389,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openStatusFavoriters(final Context context, @Nullable final AccountKey accountKey, + public static void openStatusFavoriters(final Context context, @Nullable final UserKey accountKey, final long statusId) { if (context == null) return; final Uri.Builder builder = new Uri.Builder(); @@ -403,7 +403,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openStatusRetweeters(final Context context, @Nullable final AccountKey accountKey, + public static void openStatusRetweeters(final Context context, @Nullable final UserKey accountKey, final long statusId) { if (context == null) return; final Uri.Builder builder = new Uri.Builder(); @@ -417,12 +417,12 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openTweetSearch(final Context context, @Nullable final AccountKey accountKey, + public static void openTweetSearch(final Context context, @Nullable final UserKey accountKey, final String query) { openSearch(context, accountKey, query, QUERY_PARAM_VALUE_TWEETS); } - public static void openUserBlocks(final Activity activity, final AccountKey accountKey) { + public static void openUserBlocks(final Activity activity, final UserKey accountKey) { if (activity == null) return; final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -433,7 +433,7 @@ public class IntentUtils implements Constants { } public static void openUserFavorites(@NonNull final Context context, - @Nullable final AccountKey accountKey, + @Nullable final UserKey accountKey, final long userId, final String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -453,7 +453,7 @@ public class IntentUtils implements Constants { } public static void openUserFollowers(@NonNull final Context context, - @Nullable final AccountKey accountKey, final long userId, + @Nullable final UserKey accountKey, final long userId, final String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -472,7 +472,7 @@ public class IntentUtils implements Constants { } public static void openUserFriends(@NonNull final Context context, - @Nullable final AccountKey accountKey, final long userId, + @Nullable final UserKey accountKey, final long userId, final String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -492,7 +492,7 @@ public class IntentUtils implements Constants { } public static void openUserListDetails(@NonNull final Context context, - @Nullable final AccountKey accountKey, final long listId, + @Nullable final UserKey accountKey, final long listId, final long userId, final String screenName, final String listName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -517,14 +517,14 @@ public class IntentUtils implements Constants { } public static void openUserListDetails(@NonNull final Context context, @NonNull final ParcelableUserList userList) { - final long userId = userList.user_id; + final UserKey userId = userList.user_key; final long listId = userList.id; final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER_LIST, userList); final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_USER_LIST); - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, userList.account_key.toString()); + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, String.valueOf(userList.account_key)); builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(userId)); builder.appendQueryParameter(QUERY_PARAM_LIST_ID, String.valueOf(listId)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); @@ -533,25 +533,25 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openUserLists(@NonNull final Context context, @Nullable final AccountKey accountKey, final long user_id, - final String screen_name) { + public static void openUserLists(@NonNull final Context context, @Nullable final UserKey accountKey, final long userId, + final String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_USER_LISTS); if (accountKey != null) { builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, accountKey.toString()); } - if (user_id > 0) { - builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user_id)); + if (userId > 0) { + builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(userId)); } - if (screen_name != null) { - builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name); + if (screenName != null) { + builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screenName); } final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); context.startActivity(intent); } - public static void openDirectMessages(@NonNull final Context context, @Nullable final AccountKey accountKey) { + public static void openDirectMessages(@NonNull final Context context, @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_DIRECT_MESSAGES); @@ -562,7 +562,7 @@ public class IntentUtils implements Constants { context.startActivity(intent); } - public static void openInteractions(@NonNull final Context context, @Nullable final AccountKey accountKey) { + public static void openInteractions(@NonNull final Context context, @Nullable final UserKey accountKey) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_INTERACTIONS); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java index 17c9be24d..42d472033 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java @@ -19,7 +19,8 @@ import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.UrlEntity; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.model.ParcelableStatus; -import org.mariotaku.twidere.provider.TwidereDataStore; +import org.mariotaku.twidere.model.UserKey; +import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.collection.LongSparseMap; import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; @@ -76,60 +77,68 @@ public class InternalTwitterContentUtils { return list; } - public static boolean isFiltered(final SQLiteDatabase database, final long user_id, final String text_plain, - final String text_html, final String source, final long retweeted_by_id, final long quotedUserId) { - return isFiltered(database, user_id, text_plain, text_html, source, retweeted_by_id, quotedUserId, true); + public static boolean isFiltered(final SQLiteDatabase database, final UserKey userKey, + final String textPlain, final String textHtml, + final String source, final UserKey retweetedById, + final UserKey quotedUserId) { + return isFiltered(database, userKey, textPlain, textHtml, source, retweetedById, + quotedUserId, true); } - public static boolean isFiltered(final SQLiteDatabase database, final long userId, - final String textPlain, final String textHtml, final String source, - final long retweetedById, final long quotedUserId, final boolean filterRts) { + public static boolean isFiltered(final SQLiteDatabase database, final UserKey userKey, + final String textPlain, final String textHtml, + final String source, final UserKey retweetedById, + final UserKey quotedUserId, final boolean filterRts) { if (database == null) return false; - if (textPlain == null && textHtml == null && userId <= 0 && source == null) return false; + if (textPlain == null && textHtml == null && userKey == null && source == null) + return false; final StringBuilder builder = new StringBuilder(); - final List selection_args = new ArrayList<>(); + final List selectionArgs = new ArrayList<>(); builder.append("SELECT NULL WHERE"); if (textPlain != null) { - selection_args.add(textPlain); - builder.append("(SELECT 1 IN (SELECT ? LIKE '%'||" + TwidereDataStore.Filters.Keywords.TABLE_NAME + "." + TwidereDataStore.Filters.VALUE - + "||'%' FROM " + TwidereDataStore.Filters.Keywords.TABLE_NAME + "))"); + selectionArgs.add(textPlain); + builder.append("(SELECT 1 IN (SELECT ? LIKE '%'||" + Filters.Keywords.TABLE_NAME + "." + Filters.VALUE + + "||'%' FROM " + Filters.Keywords.TABLE_NAME + "))"); } if (textHtml != null) { - if (!selection_args.isEmpty()) { + if (!selectionArgs.isEmpty()) { builder.append(" OR "); } - selection_args.add(textHtml); - builder.append("(SELECT 1 IN (SELECT ? LIKE '%%' FROM " + TwidereDataStore.Filters.Links.TABLE_NAME + "))"); + selectionArgs.add(textHtml); + builder.append("(SELECT 1 IN (SELECT ? LIKE '%%' FROM " + Filters.Links.TABLE_NAME + "))"); } - if (userId > 0) { - if (!selection_args.isEmpty()) { + if (userKey != null) { + if (!selectionArgs.isEmpty()) { builder.append(" OR "); } - builder.append("(SELECT ").append(userId).append(" IN (SELECT ").append(TwidereDataStore.Filters.Users.USER_ID).append(" FROM ").append(TwidereDataStore.Filters.Users.TABLE_NAME).append("))"); + selectionArgs.add(String.valueOf(selectionArgs)); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } - if (retweetedById > 0) { - if (!selection_args.isEmpty()) { + if (retweetedById != null) { + if (!selectionArgs.isEmpty()) { builder.append(" OR "); } - builder.append("(SELECT ").append(retweetedById).append(" IN (SELECT ").append(TwidereDataStore.Filters.Users.USER_ID).append(" FROM ").append(TwidereDataStore.Filters.Users.TABLE_NAME).append("))"); + selectionArgs.add(String.valueOf(retweetedById)); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } - if (quotedUserId > 0) { - if (!selection_args.isEmpty()) { + if (quotedUserId != null) { + if (!selectionArgs.isEmpty()) { builder.append(" OR "); } - builder.append("(SELECT ").append(quotedUserId).append(" IN (SELECT ").append(TwidereDataStore.Filters.Users.USER_ID).append(" FROM ").append(TwidereDataStore.Filters.Users.TABLE_NAME).append("))"); + selectionArgs.add(String.valueOf(quotedUserId)); + builder.append("(SELECT ").append("?").append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))"); } if (source != null) { - if (!selection_args.isEmpty()) { + if (!selectionArgs.isEmpty()) { builder.append(" OR "); } - selection_args.add(source); - builder.append("(SELECT 1 IN (SELECT ? LIKE '%>'||" + TwidereDataStore.Filters.Sources.TABLE_NAME + "." + TwidereDataStore.Filters.VALUE - + "||'%' FROM " + TwidereDataStore.Filters.Sources.TABLE_NAME + "))"); + selectionArgs.add(source); + builder.append("(SELECT 1 IN (SELECT ? LIKE '%>'||" + Filters.Sources.TABLE_NAME + "." + Filters.VALUE + + "||'%' FROM " + Filters.Sources.TABLE_NAME + "))"); } final Cursor cur = database.rawQuery(builder.toString(), - selection_args.toArray(new String[selection_args.size()])); + selectionArgs.toArray(new String[selectionArgs.size()])); if (cur == null) return false; try { return cur.getCount() > 0; @@ -141,7 +150,7 @@ public class InternalTwitterContentUtils { public static boolean isFiltered(final SQLiteDatabase database, final ParcelableStatus status, final boolean filter_rts) { if (database == null || status == null) return false; - return isFiltered(database, status.user_id, status.text_plain, status.text_html, status.source, + return isFiltered(database, status.user_key, status.text_plain, status.text_html, status.source, status.retweeted_by_user_id, status.quoted_user_id, filter_rts); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java b/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java index 1c268a777..39103af4c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/LinkCreator.java @@ -24,7 +24,7 @@ import android.support.annotation.Nullable; import android.text.TextUtils; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; /** @@ -44,7 +44,7 @@ public class LinkCreator implements Constants { return builder.build(); } - public static Uri getTwidereStatusLink(AccountKey accountKey, long statusId) { + public static Uri getTwidereStatusLink(UserKey accountKey, long statusId) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_STATUS); @@ -55,7 +55,7 @@ public class LinkCreator implements Constants { return builder.build(); } - public static Uri getTwidereUserLink(@Nullable AccountKey accountKey, long userId, String screenName) { + public static Uri getTwidereUserLink(@Nullable UserKey accountKey, long userId, String screenName) { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_USER); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java index 5a5d227f0..146daa6d7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MediaLoaderWrapper.java @@ -33,7 +33,7 @@ import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; @@ -111,7 +111,7 @@ public class MediaLoaderWrapper implements Constants { } public void displayPreviewImageWithCredentials(final ImageView view, final String url, - final AccountKey accountKey, + final UserKey accountKey, final MediaLoadingHandler loadingHandler) { if (accountKey == null) { displayPreviewImage(view, url, loadingHandler); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MenuUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/MenuUtils.java index dc087215c..e1c99fd6a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MenuUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MenuUtils.java @@ -301,7 +301,7 @@ public class MenuUtils implements Constants { } case R.id.set_color: { final Intent intent = new Intent(context, ColorPickerDialogActivity.class); - final int color = colorNameManager.getUserColor(status.user_id, true); + final int color = colorNameManager.getUserColor(status.user_key, true); if (color != 0) { intent.putExtra(IntentConstants.EXTRA_COLOR, color); } @@ -315,12 +315,12 @@ public class MenuUtils implements Constants { break; } case R.id.clear_nickname: { - colorNameManager.clearUserNickname(status.user_id); + colorNameManager.clearUserNickname(status.user_key); break; } case R.id.set_nickname: { - final String nick = colorNameManager.getUserNickname(status.user_id, true); - SetUserNicknameDialogFragment.show(fm, status.user_id, nick); + final String nick = colorNameManager.getUserNickname(status.user_key, true); + SetUserNicknameDialogFragment.show(fm, status.user_key, nick); break; } case R.id.open_with_account: { 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 c66353dc3..7d5e31160 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectEventHandler.java @@ -35,10 +35,10 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.support.BaseAppCompatActivity; import org.mariotaku.twidere.menu.AccountActionProvider; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; @@ -134,27 +134,28 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback, case R.id.mute_user: { final ContentResolver resolver = mActivity.getContentResolver(); final ArrayList valuesList = new ArrayList<>(); - final Set userIds = new HashSet<>(); + final Set userIds = new HashSet<>(); for (final Object object : selectedItems) { if (object instanceof ParcelableStatus) { final ParcelableStatus status = (ParcelableStatus) object; - userIds.add(status.user_id); + userIds.add(status.user_key); valuesList.add(ContentValuesCreator.createFilteredUser(status)); } else if (object instanceof ParcelableUser) { final ParcelableUser user = (ParcelableUser) object; - userIds.add(user.id); + userIds.add(user.key); valuesList.add(ContentValuesCreator.createFilteredUser(user)); } } - ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, Filters.Users.USER_ID, userIds, null, false); + ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI, + Filters.Users.USER_ID, userIds, null); ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, valuesList); Toast.makeText(mActivity, R.string.message_users_muted, Toast.LENGTH_SHORT).show(); mode.finish(); break; } case R.id.block: { - final AccountKey accountKey = mMultiSelectManager.getAccountKey(); - final long[] userIds = MultiSelectManager.getSelectedUserIds(selectedItems); + final UserKey accountKey = mMultiSelectManager.getAccountKey(); + final long[] userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems)); if (accountKey != null && userIds != null) { mTwitterWrapper.createMultiBlockAsync(accountKey, userIds); } @@ -162,8 +163,8 @@ public class MultiSelectEventHandler implements Constants, ActionMode.Callback, break; } case R.id.report_spam: { - final AccountKey accountKey = mMultiSelectManager.getAccountKey(); - final long[] userIds = MultiSelectManager.getSelectedUserIds(selectedItems); + final UserKey accountKey = mMultiSelectManager.getAccountKey(); + final long[] userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems)); if (accountKey != null && userIds != null) { mTwitterWrapper.reportMultiSpam(accountKey, userIds); } 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 c1d354287..16a992dd1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MultiSelectManager.java @@ -20,9 +20,9 @@ package org.mariotaku.twidere.util; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList; import java.util.ArrayList; @@ -31,16 +31,16 @@ import java.util.List; public class MultiSelectManager implements Constants { private final NoDuplicatesArrayList mSelectedStatusIds = new NoDuplicatesArrayList<>(); - private final NoDuplicatesArrayList mSelectedUserIds = new NoDuplicatesArrayList<>(); + private final NoDuplicatesArrayList mSelectedUserIds = new NoDuplicatesArrayList<>(); private final NoDuplicatesArrayList mCallbacks = new NoDuplicatesArrayList<>(); private final ItemsList mSelectedItems = new ItemsList(this); - private AccountKey mAccountKey; + private UserKey mAccountKey; public void clearSelectedItems() { mSelectedItems.clear(); } - public AccountKey getAccountKey() { + public UserKey getAccountKey() { if (mAccountKey == null) return getFirstSelectAccountKey(mSelectedItems); return mAccountKey; } @@ -49,7 +49,7 @@ public class MultiSelectManager implements Constants { return mSelectedItems.size(); } - public AccountKey getFirstSelectAccountKey() { + public UserKey getFirstSelectAccountKey() { return getFirstSelectAccountKey(mSelectedItems); } @@ -65,12 +65,12 @@ public class MultiSelectManager implements Constants { return mSelectedItems.contains(object); } - public boolean isStatusSelected(final long status_id) { - return mSelectedStatusIds.contains(status_id); + public boolean isStatusSelected(final long statusId) { + return mSelectedStatusIds.contains(statusId); } - public boolean isUserSelected(final long user_id) { - return mSelectedUserIds.contains(user_id); + public boolean isUserSelected(final UserKey userKey) { + return mSelectedUserIds.contains(userKey); } public void registerCallback(final Callback callback) { @@ -82,7 +82,7 @@ public class MultiSelectManager implements Constants { return mSelectedItems.add(item); } - public void setAccountKey(final AccountKey accountKey) { + public void setAccountKey(final UserKey accountKey) { mAccountKey = accountKey; } @@ -113,7 +113,7 @@ public class MultiSelectManager implements Constants { } } - public static AccountKey getFirstSelectAccountKey(final List selectedItems) { + public static UserKey getFirstSelectAccountKey(final List selectedItems) { final Object obj = selectedItems.get(0); if (obj instanceof ParcelableUser) { final ParcelableUser user = (ParcelableUser) obj; @@ -125,16 +125,16 @@ public class MultiSelectManager implements Constants { return null; } - public static long[] getSelectedUserIds(final List selected_items) { - final ArrayList ids_list = new ArrayList<>(); - for (final Object item : selected_items) { + public static UserKey[] getSelectedUserIds(final List selectedItems) { + final ArrayList userKeys = new ArrayList<>(); + for (final Object item : selectedItems) { if (item instanceof ParcelableUser) { - ids_list.add(((ParcelableUser) item).id); + userKeys.add(((ParcelableUser) item).key); } else if (item instanceof ParcelableStatus) { - ids_list.add(((ParcelableStatus) item).user_id); + userKeys.add(((ParcelableStatus) item).user_key); } } - return TwidereArrayUtils.fromList(ids_list); + return userKeys.toArray(new UserKey[userKeys.size()]); } public interface Callback { @@ -161,7 +161,7 @@ public class MultiSelectManager implements Constants { if (object instanceof ParcelableStatus) { manager.mSelectedStatusIds.add(((ParcelableStatus) object).id); } else if (object instanceof ParcelableUser) { - manager.mSelectedUserIds.add(((ParcelableUser) object).id); + manager.mSelectedUserIds.add(((ParcelableUser) object).key); } else return false; final boolean ret = super.add(object); @@ -183,7 +183,7 @@ public class MultiSelectManager implements Constants { if (object instanceof ParcelableStatus) { manager.mSelectedStatusIds.remove(((ParcelableStatus) object).id); } else if (object instanceof ParcelableUser) { - manager.mSelectedUserIds.remove(((ParcelableUser) object).id); + manager.mSelectedUserIds.remove(((ParcelableUser) object).key); } if (ret) { if (isEmpty()) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java index 314ea74f4..f9bb9a6bb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java @@ -29,7 +29,7 @@ import android.support.annotation.Nullable; import org.apache.commons.lang3.math.NumberUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.fragment.support.UserFragment; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener; @@ -51,7 +51,7 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { } @Override - public void onLinkClick(final String link, final String orig, final AccountKey accountKey, + public void onLinkClick(final String link, final String orig, final UserKey accountKey, final long extraId, final int type, final boolean sensitive, final int start, final int end) { if (manager != null && manager.isActive()) return; @@ -108,7 +108,7 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { return false; } - protected void openMedia(AccountKey accountKey, long extraId, boolean sensitive, String link, int start, int end) { + protected void openMedia(UserKey accountKey, long extraId, boolean sensitive, String link, int start, int end) { final ParcelableMedia[] media = {ParcelableMediaUtils.image(link)}; IntentUtils.openMedia(context, accountKey, sensitive, null, media, null, true); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.java index 989a62401..63c4ade0d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.java @@ -22,7 +22,7 @@ package org.mariotaku.twidere.util; import android.support.v7.widget.RecyclerView; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; @@ -39,7 +39,7 @@ public class StatusAdapterLinkClickHandler extends OnLinkClickHandler { } @Override - protected void openMedia(final AccountKey accountKey, final long extraId, final boolean sensitive, + protected void openMedia(final UserKey accountKey, final long extraId, final boolean sensitive, final String link, final int start, final int end) { if (extraId == RecyclerView.NO_POSITION) return; final ParcelableStatus status = adapter.getStatus((int) extraId); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java index d45516884..6b903cf5d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java @@ -21,7 +21,7 @@ package org.mariotaku.twidere.util; import android.content.Context; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; @@ -33,7 +33,7 @@ public class StatusLinkClickHandler extends OnLinkClickHandler { private ParcelableStatus mStatus; @Override - protected void openMedia(final AccountKey accountId, final long extraId, final boolean sensitive, + protected void openMedia(final UserKey accountId, final long extraId, final boolean sensitive, final String link, final int start, final int end) { final ParcelableStatus status = mStatus; final ParcelableMedia current = findByLink(status.media, link); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusShortenerInterface.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusShortenerInterface.java index 710fa1c39..32ff42bec 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusShortenerInterface.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusShortenerInterface.java @@ -32,7 +32,7 @@ import android.util.Log; import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.IStatusShortener; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.StatusShortenResult; @@ -51,7 +51,7 @@ public final class StatusShortenerInterface extends AbsServiceInterface T getTwitterInstance(@NonNull final Context context, - @NonNull final AccountKey accountKey, + @NonNull final UserKey accountKey, final boolean includeEntities, final boolean includeRetweets, @NonNull Class cls) { @@ -196,7 +196,7 @@ public class TwitterAPIFactory implements TwidereConstants { isTwitterCredentials(credentials)); } - public static boolean isTwitterCredentials(Context context, AccountKey accountId) { + public static boolean isTwitterCredentials(Context context, UserKey accountId) { return isTwitterCredentials(ParcelableCredentialsUtils.getCredentials(context, accountId)); } @@ -205,6 +205,10 @@ public class TwitterAPIFactory implements TwidereConstants { ParcelableCredentials.ACCOUNT_TYPE_TWITTER.equals(credentials.account_type); } + public static boolean isStatusNetCredentials(ParcelableCredentials credentials) { + return ParcelableCredentials.ACCOUNT_TYPE_STATUSNET.equals(credentials.account_type); + } + @WorkerThread static T getInstance(final Context context, final ParcelableCredentials credentials, final Class cls) { @@ -418,7 +422,7 @@ public class TwitterAPIFactory implements TwidereConstants { } @NonNull - public static ConsumerKeyType getOfficialKeyType(final Context context, final AccountKey accountKey) { + public static ConsumerKeyType getOfficialKeyType(final Context context, final UserKey accountKey) { if (context == null) return ConsumerKeyType.UNKNOWN; final String[] projection = {Accounts.CONSUMER_KEY, Accounts.CONSUMER_SECRET, Accounts.AUTH_TYPE}; final String selection = Expression.equalsArgs(Accounts.ACCOUNT_KEY).getSQL(); 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 71d186939..b9064f672 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterWrapper.java @@ -22,7 +22,6 @@ package org.mariotaku.twidere.util; 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; @@ -35,7 +34,7 @@ import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.Status; import org.mariotaku.twidere.api.twitter.model.User; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ListResponse; import org.mariotaku.twidere.model.SingleResponse; import org.mariotaku.twidere.provider.TwidereDataStore.Notifications; @@ -49,7 +48,7 @@ import java.util.Set; public class TwitterWrapper implements Constants { - public static int clearNotification(final Context context, final int notificationType, final AccountKey accountId) { + public static int clearNotification(final Context context, final int notificationType, final UserKey accountId) { final Uri.Builder builder = Notifications.CONTENT_URI.buildUpon(); builder.appendPath(String.valueOf(notificationType)); if (accountId != null) { @@ -65,7 +64,7 @@ public class TwitterWrapper implements Constants { } public static SingleResponse deleteProfileBannerImage(final Context context, - final AccountKey accountKey) { + final UserKey accountKey) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountKey, false); if (twitter == null) return new SingleResponse<>(false, null); try { @@ -90,11 +89,11 @@ public class TwitterWrapper implements Constants { } public static int removeUnreadCounts(final Context context, final int position, - final SimpleArrayMap> counts) { + 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 AccountKey key = counts.keyAt(i); + final UserKey key = counts.keyAt(i); final Set value = counts.valueAt(i); final Uri.Builder builder = UnreadCounts.CONTENT_URI.buildUpon(); builder.appendPath(String.valueOf(position)); @@ -202,20 +201,20 @@ public class TwitterWrapper implements Constants { public final boolean truncated; - public MessageListResponse(final AccountKey accountKey, final Exception exception) { + public MessageListResponse(final UserKey accountKey, final Exception exception) { this(accountKey, -1, -1, null, false, exception); } - public MessageListResponse(final AccountKey accountKey, final List list) { + public MessageListResponse(final UserKey accountKey, final List list) { this(accountKey, -1, -1, list, false, null); } - public MessageListResponse(final AccountKey accountKey, final long maxId, final long sinceId, + public MessageListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list, final boolean truncated) { this(accountKey, maxId, sinceId, list, truncated, null); } - MessageListResponse(final AccountKey accountKey, final long maxId, final long sinceId, + MessageListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list, final boolean truncated, final Exception exception) { super(accountKey, maxId, sinceId, list, exception); this.truncated = truncated; @@ -227,20 +226,20 @@ public class TwitterWrapper implements Constants { public final boolean truncated; - public StatusListResponse(final AccountKey accountKey, final Exception exception) { + public StatusListResponse(final UserKey accountKey, final Exception exception) { this(accountKey, -1, -1, null, false, exception); } - public StatusListResponse(final AccountKey accountKey, final List list) { + public StatusListResponse(final UserKey accountKey, final List list) { this(accountKey, -1, -1, list, false, null); } - public StatusListResponse(final AccountKey accountKey, final long maxId, final long sinceId, + public StatusListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list, final boolean truncated) { this(accountKey, maxId, sinceId, list, truncated, null); } - StatusListResponse(final AccountKey accountKey, final long maxId, final long sinceId, final List list, + StatusListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list, final boolean truncated, final Exception exception) { super(accountKey, maxId, sinceId, list, exception); this.truncated = truncated; @@ -250,21 +249,21 @@ public class TwitterWrapper implements Constants { public static class TwitterListResponse extends ListResponse { - public final AccountKey mAccountKey; + public final UserKey mAccountKey; public final long maxId; public final long sinceId; - public TwitterListResponse(final AccountKey accountKey, + public TwitterListResponse(final UserKey accountKey, final Exception exception) { this(accountKey, -1, -1, null, exception); } - public TwitterListResponse(final AccountKey accountKey, final long maxId, + public TwitterListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list) { this(accountKey, maxId, sinceId, list, null); } - TwitterListResponse(final AccountKey accountKey, final long maxId, + TwitterListResponse(final UserKey accountKey, final long maxId, final long sinceId, final List list, final Exception exception) { super(list, exception); this.mAccountKey = accountKey; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java index c3fb583f3..5ed06aab5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java @@ -23,15 +23,17 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.graphics.Color; -import android.support.v4.util.LongSparseArray; +import android.support.annotation.NonNull; +import android.support.v4.util.SimpleArrayMap; import android.text.TextUtils; -import org.apache.commons.lang3.math.NumberUtils; import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.api.twitter.model.User; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserList; +import org.mariotaku.twidere.model.UserKey; +import org.mariotaku.twidere.model.util.UserKeyUtils; import java.util.Map; import java.util.Set; @@ -40,8 +42,8 @@ import static android.text.TextUtils.isEmpty; public class UserColorNameManager implements TwidereConstants { - private final LongSparseArray mUserColors = new LongSparseArray<>(); - private final LongSparseArray mUserNicknames = new LongSparseArray<>(); + private final SimpleArrayMap mUserColors = new SimpleArrayMap<>(); + private final SimpleArrayMap mUserNicknames = new SimpleArrayMap<>(); private final SharedPreferences mColorPreferences, mNicknamePreferences; public UserColorNameManager(Context context) { @@ -59,55 +61,65 @@ public class UserColorNameManager implements TwidereConstants { mNicknamePreferences.registerOnSharedPreferenceChangeListener(new OnNickPreferenceChangeListener(listener)); } - public void clearUserColor(final long userId) { - if (userId < 0) return; + public void clearUserColor(@NonNull final UserKey userId) { mUserColors.remove(userId); final SharedPreferences.Editor editor = mColorPreferences.edit(); - editor.remove(Long.toString(userId)); + editor.remove(userId.toString()); editor.apply(); } - public void setUserColor(final long userId, final int color) { - if (userId < 0) return; + public void setUserColor(@NonNull final UserKey userId, final int color) { + setUserColor(userId.toString(), color); + } + + public void setUserColor(@NonNull final String userId, final int color) { mUserColors.put(userId, color); final SharedPreferences.Editor editor = mColorPreferences.edit(); - editor.putInt(String.valueOf(userId), color); + editor.putInt(userId, color); editor.apply(); } - public void setUserNickname(final long userId, final String nickname) { - if (userId < 0) return; + public void setUserNickname(@NonNull final UserKey userId, final String nickname) { + setUserNickname(userId.toString(), nickname); + } + + public void setUserNickname(@NonNull final String userId, final String nickname) { mUserNicknames.put(userId, nickname); final SharedPreferences.Editor editor = mNicknamePreferences.edit(); - editor.putString(String.valueOf(userId), nickname); + editor.putString(userId, nickname); editor.apply(); } - public void clearUserNickname(final long userId) { - if (userId < 0) return; + public void clearUserNickname(@NonNull final UserKey userId) { mUserNicknames.remove(userId); final SharedPreferences.Editor editor = mNicknamePreferences.edit(); - editor.remove(Long.toString(userId)); + editor.remove(userId.toString()); editor.apply(); } public String getDisplayName(final ParcelableUser user, final boolean nameFirst, final boolean ignoreCache) { - return getDisplayName(user.id, user.name, user.screen_name, nameFirst, ignoreCache); + return getDisplayName(user.key, user.name, user.screen_name, nameFirst, ignoreCache); } public String getDisplayName(final User user, final boolean nameFirst, final boolean ignoreCache) { - return getDisplayName(user.getId(), user.getName(), user.getScreenName(), nameFirst, ignoreCache); + return getDisplayName(UserKeyUtils.fromUser(user), user.getName(), user.getScreenName(), nameFirst, ignoreCache); } public String getDisplayName(final ParcelableUserList user, final boolean nameFirst, final boolean ignoreCache) { - return getDisplayName(user.user_id, user.user_name, user.user_screen_name, nameFirst, ignoreCache); + return getDisplayName(user.user_key, user.user_name, user.user_screen_name, nameFirst, ignoreCache); } public String getDisplayName(final ParcelableStatus status, final boolean nameFirst, final boolean ignoreCache) { - return getDisplayName(status.user_id, status.user_name, status.user_screen_name, nameFirst, ignoreCache); + return getDisplayName(status.user_key, status.user_name, status.user_screen_name, nameFirst, ignoreCache); } - public String getDisplayName(final long userId, final String name, + public String getDisplayName(@NonNull final UserKey userId, final String name, + final String screenName, final boolean nameFirst, + final boolean ignoreCache) { + return getDisplayName(userId.toString(), name, screenName, nameFirst, ignoreCache); + } + + public String getDisplayName(@NonNull final String userId, final String name, final String screenName, final boolean nameFirst, final boolean ignoreCache) { final String nick = getUserNickname(userId, ignoreCache); @@ -115,32 +127,50 @@ public class UserColorNameManager implements TwidereConstants { return nameFirst && !isEmpty(name) ? name : "@" + screenName; } - public int getUserColor(final long userId, final boolean ignoreCache) { - if (userId == -1) return Color.TRANSPARENT; + public static String getDisplayName(final String name, final String screenName, final boolean nameFirst) { + return nameFirst && !isEmpty(name) ? name : "@" + screenName; + } + + public int getUserColor(@NonNull final UserKey userId, final boolean ignoreCache) { + return getUserColor(userId.toString(), ignoreCache); + } + + public int getUserColor(@NonNull final String userId, final boolean ignoreCache) { if (!ignoreCache && mUserColors.indexOfKey(userId) >= 0) return mUserColors.get(userId); - final int color = mColorPreferences.getInt(Long.toString(userId), Color.TRANSPARENT); + final int color = mColorPreferences.getInt(userId, Color.TRANSPARENT); mUserColors.put(userId, color); return color; } - public String getUserNickname(final long userId) { + public String getUserNickname(@NonNull final UserKey userId) { return getUserNickname(userId, false); } - public String getUserNickname(final long userId, final boolean ignoreCache) { - if (userId == -1) return null; - if (!ignoreCache && LongSparseArrayUtils.hasKey(mUserNicknames, userId)) + public String getUserNickname(@NonNull final UserKey userId, final boolean ignoreCache) { + return getUserNickname(userId.toString(), ignoreCache); + } + + public String getUserNickname(@NonNull final String userId, final boolean ignoreCache) { + if (!ignoreCache && mUserNicknames.containsKey(userId)) return mUserNicknames.get(userId); - final String nickname = mNicknamePreferences.getString(Long.toString(userId), null); + final String nickname = mNicknamePreferences.getString(userId, null); mUserNicknames.put(userId, nickname); return nickname; } - public String getUserNickname(final long userId, final String name) { + public String getUserNickname(@NonNull final UserKey userId, final String name) { return getUserNickname(userId, name, false); } - public String getUserNickname(final long userId, final String name, final boolean ignoreCache) { + public String getUserNickname(@NonNull final String userId, final String name) { + return getUserNickname(userId, name, false); + } + + public String getUserNickname(@NonNull final UserKey userId, final String name, final boolean ignoreCache) { + return getUserNickname(userId.toString(), name, ignoreCache); + } + + public String getUserNickname(@NonNull final String userId, final String name, final boolean ignoreCache) { final String nick = getUserNickname(userId, ignoreCache); return isEmpty(nick) ? name : nick; } @@ -149,17 +179,17 @@ public class UserColorNameManager implements TwidereConstants { return mNicknamePreferences.getAll().entrySet(); } - public String getName(long id, String name) { + public String getName(@NonNull final UserKey id, String name) { final String nick = getUserNickname(id, true); return TextUtils.isEmpty(nick) ? name : nick; } public interface UserColorChangedListener { - void onUserColorChanged(long userId, int color); + void onUserColorChanged(@NonNull UserKey userId, int color); } public interface UserNicknameChangedListener { - void onUserNicknameChanged(long userId, String nick); + void onUserNicknameChanged(@NonNull UserKey userId, String nick); } private static final class OnColorPreferenceChangeListener implements OnSharedPreferenceChangeListener { @@ -172,9 +202,8 @@ public class UserColorNameManager implements TwidereConstants { @Override public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) { - final long def = -1; - final long userId = NumberUtils.toLong(key, def); - if (mListener != null) { + final UserKey userId = UserKey.valueOf(key); + if (mListener != null && userId != null) { mListener.onUserColorChanged(userId, sharedPreferences.getInt(key, 0)); } } @@ -191,9 +220,8 @@ public class UserColorNameManager implements TwidereConstants { @Override public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) { - final long def = -1; - final long userId = NumberUtils.toLong(key, def); - if (mListener != null) { + final UserKey userId = UserKey.valueOf(key); + if (mListener != null && userId != null) { mListener.onUserNicknameChanged(userId, sharedPreferences.getString(key, null)); } } 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 1166a82e0..2ef422fec 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -127,7 +127,6 @@ import org.mariotaku.twidere.api.twitter.model.GeoLocation; import org.mariotaku.twidere.api.twitter.model.RateLimitStatus; import org.mariotaku.twidere.api.twitter.model.Relationship; import org.mariotaku.twidere.api.twitter.model.Status; -import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback; import org.mariotaku.twidere.fragment.support.AccountsManagerFragment; import org.mariotaku.twidere.fragment.support.DirectMessagesFragment; @@ -161,7 +160,6 @@ import org.mariotaku.twidere.fragment.support.UserProfileEditorFragment; import org.mariotaku.twidere.fragment.support.UserTimelineFragment; import org.mariotaku.twidere.fragment.support.UsersListFragment; import org.mariotaku.twidere.graphic.PaddingDrawable; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.ParcelableAccount; import org.mariotaku.twidere.model.ParcelableCredentials; @@ -174,10 +172,11 @@ import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUserMention; import org.mariotaku.twidere.model.PebbleMessage; import org.mariotaku.twidere.model.TwitterAccountExtra; -import org.mariotaku.twidere.model.util.AccountKeyUtils; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils; import org.mariotaku.twidere.model.util.ParcelableStatusUtils; import org.mariotaku.twidere.model.util.ParcelableUserUtils; +import org.mariotaku.twidere.model.util.UserKeyUtils; import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; @@ -748,14 +747,14 @@ public final class Utils implements Constants { if (isAccountIdRequired) { final String paramAccountKey = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY); if (paramAccountKey != null) { - args.putParcelable(EXTRA_ACCOUNT_KEY, AccountKey.valueOf(paramAccountKey)); + args.putParcelable(EXTRA_ACCOUNT_KEY, UserKey.valueOf(paramAccountKey)); } else { final String paramAccountName = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME); if (paramAccountName != null) { args.putParcelable(EXTRA_ACCOUNT_KEY, DataStoreUtils.getAccountKey(context, paramAccountName)); } else { - final AccountKey accountKey = getDefaultAccountKey(context); + final UserKey accountKey = getDefaultAccountKey(context); if (isMyAccount(context, accountKey)) { args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); } @@ -780,37 +779,37 @@ public final class Utils implements Constants { } @Nullable - public static AccountKey[] getAccountKeys(@NonNull Context context, @Nullable Bundle args) { + public static UserKey[] getAccountKeys(@NonNull Context context, @Nullable Bundle args) { if (args == null) return null; if (args.containsKey(EXTRA_ACCOUNT_KEYS)) { - return newParcelableArray(args.getParcelableArray(EXTRA_ACCOUNT_KEYS), AccountKey.CREATOR); + return newParcelableArray(args.getParcelableArray(EXTRA_ACCOUNT_KEYS), UserKey.CREATOR); } else if (args.containsKey(EXTRA_ACCOUNT_KEY)) { - final AccountKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); - if (accountKey == null) return new AccountKey[0]; - return new AccountKey[]{accountKey}; + final UserKey accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY); + if (accountKey == null) return new UserKey[0]; + return new UserKey[]{accountKey}; } else if (args.containsKey(EXTRA_ACCOUNT_IDS)) { final long[] accountIds = args.getLongArray(EXTRA_ACCOUNT_IDS); if (accountIds == null) return null; - final AccountKey[] accountKeys = AccountKeyUtils.findByIds(context, accountIds); + final UserKey[] accountKeys = UserKeyUtils.findByIds(context, accountIds); args.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountKeys); return accountKeys; } else if (args.containsKey(EXTRA_ACCOUNT_ID)) { final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1); if (accountId <= 0) return null; - final AccountKey accountKey = AccountKeyUtils.findById(context, accountId); + final UserKey accountKey = UserKeyUtils.findById(context, accountId); args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); - if (accountKey == null) return new AccountKey[0]; - return new AccountKey[]{accountKey}; + if (accountKey == null) return new UserKey[0]; + return new UserKey[]{accountKey}; } return null; } @Nullable public static String getReadPositionTagWithAccounts(@Nullable final String tag, - final AccountKey... accountKeys) { + final UserKey... accountKeys) { if (tag == null) return null; if (ArrayUtils.isEmpty(accountKeys)) return tag; - final AccountKey[] accountIdsClone = accountKeys.clone(); + final UserKey[] accountIdsClone = accountKeys.clone(); Arrays.sort(accountIdsClone); return tag + "_" + TwidereArrayUtils.toString(accountIdsClone, '_', false); } @@ -818,14 +817,14 @@ public final class Utils implements Constants { @Nullable public static String getReadPositionTagWithAccounts(Context context, boolean activatedIfMissing, @Nullable @ReadPositionTag String tag, - AccountKey... accountKeys) { + UserKey... accountKeys) { if (tag == null) return null; if (ArrayUtils.isEmpty(accountKeys)) { - final AccountKey[] activatedIds = DataStoreUtils.getActivatedAccountKeys(context); + final UserKey[] activatedIds = DataStoreUtils.getActivatedAccountKeys(context); Arrays.sort(activatedIds); return tag + "_" + TwidereArrayUtils.toString(activatedIds, '_', false); } - final AccountKey[] accountIdsClone = accountKeys.clone(); + final UserKey[] accountIdsClone = accountKeys.clone(); Arrays.sort(accountIdsClone); return tag + "_" + TwidereArrayUtils.toString(accountIdsClone, '_', false); } @@ -853,7 +852,7 @@ public final class Utils implements Constants { } public static ParcelableDirectMessage findDirectMessageInDatabases(final Context context, - final AccountKey accountKey, + final UserKey accountKey, final long messageId) { if (context == null) return null; final ContentResolver resolver = context.getContentResolver(); @@ -875,7 +874,7 @@ public final class Utils implements Constants { } @NonNull - public static ParcelableStatus findStatus(final Context context, final AccountKey accountKey, + public static ParcelableStatus findStatus(final Context context, final UserKey accountKey, final long statusId) throws TwitterException { if (context == null) throw new NullPointerException(); @@ -893,7 +892,7 @@ public final class Utils implements Constants { } @Nullable - public static ParcelableStatus findStatusInDatabases(final Context context, final AccountKey accountKey, + public static ParcelableStatus findStatusInDatabases(final Context context, final UserKey accountKey, final long statusId) { if (context == null) return null; final ContentResolver resolver = context.getContentResolver(); @@ -975,7 +974,7 @@ public final class Utils implements Constants { return hasNavBar(context); } - public static boolean isOfficialCredentials(@NonNull final Context context, final AccountKey accountKey) { + public static boolean isOfficialCredentials(@NonNull final Context context, final UserKey accountKey) { final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, accountKey); if (credentials == null) return false; return isOfficialCredentials(context, credentials); @@ -1009,21 +1008,12 @@ public final class Utils implements Constants { if (entities == null) return false; boolean result = false; for (ParcelableUserMention entity : entities) { - result |= setLastSeen(context, entity.id, time); + result |= setLastSeen(context, entity.key, time); } return result; } - public static boolean setLastSeen(Context context, UserMentionEntity[] entities, long time) { - if (entities == null) return false; - boolean result = false; - for (UserMentionEntity entity : entities) { - result |= setLastSeen(context, entity.getId(), time); - } - return result; - } - - public static boolean setLastSeen(Context context, long userId, long time) { + public static boolean setLastSeen(Context context, UserKey userId, long time) { final ContentResolver cr = context.getContentResolver(); final ContentValues values = new ContentValues(); if (time > 0) { @@ -1032,8 +1022,9 @@ public final class Utils implements Constants { // Zero or negative value means remove last seen values.putNull(CachedUsers.LAST_SEEN); } - final Expression where = Expression.equals(CachedUsers.USER_ID, userId); - return cr.update(CachedUsers.CONTENT_URI, values, where.getSQL(), null) != 0; + final String where = Expression.equalsArgs(CachedUsers.USER_KEY).getSQL(); + final String[] selectionArgs = {userId.toString()}; + return cr.update(CachedUsers.CONTENT_URI, values, where, selectionArgs) > 0; } public static File getBestCacheDir(final Context context, final String cacheDirName) { @@ -1121,12 +1112,12 @@ public final class Utils implements Constants { } @Nullable - public static AccountKey getDefaultAccountKey(final Context context) { + public static UserKey getDefaultAccountKey(final Context context) { if (context == null) return null; final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); - AccountKey accountKey = AccountKey.valueOf(prefs.getString(KEY_DEFAULT_ACCOUNT_KEY, null)); - final AccountKey[] accountKeys = DataStoreUtils.getAccountKeys(context); + UserKey accountKey = UserKey.valueOf(prefs.getString(KEY_DEFAULT_ACCOUNT_KEY, null)); + final UserKey[] accountKeys = DataStoreUtils.getAccountKeys(context); int idMatchIdx = -1; for (int i = 0, accountIdsLength = accountKeys.length; i < accountIdsLength; i++) { if (accountKeys[i].equals(accountKey)) { @@ -1548,7 +1539,7 @@ public final class Utils implements Constants { } public static boolean hasAutoRefreshAccounts(final Context context) { - final AccountKey[] accountKeys = DataStoreUtils.getAccountKeys(context); + final UserKey[] accountKeys = DataStoreUtils.getAccountKeys(context); return !ArrayUtils.isEmpty(AccountPreferences.getAutoRefreshEnabledAccountIds(context, accountKeys)); } @@ -1585,7 +1576,7 @@ public final class Utils implements Constants { } } - public static boolean isMyAccount(final Context context, @Nullable final AccountKey accountKey) { + public static boolean isMyAccount(final Context context, @Nullable final UserKey accountKey) { if (context == null || accountKey == null) return false; final String[] projection = new String[]{SQLFunctions.COUNT()}; final Cursor cur = DataStoreUtils.getAccountCursor(context, projection, accountKey); @@ -1614,11 +1605,12 @@ public final class Utils implements Constants { } public static boolean isMyRetweet(final ParcelableStatus status) { - return status != null && isMyRetweet(status.account_key.getId(), status.retweeted_by_user_id, status.my_retweet_id); + return status != null && isMyRetweet(status.account_key, status.retweeted_by_user_id, + status.my_retweet_id); } - public static boolean isMyRetweet(final long accountId, final long retweetedById, final long myRetweetId) { - return retweetedById == accountId || myRetweetId > 0; + public static boolean isMyRetweet(final UserKey accountId, final UserKey retweetedById, final long myRetweetId) { + return accountId.equals(retweetedById) || myRetweetId > 0; } public static boolean isNetworkAvailable(final Context context) { @@ -1627,23 +1619,10 @@ public final class Utils implements Constants { return info != null && info.isConnected(); } - public static boolean isRedirected(final int code) { - return code == 301 || code == 302 || code == 307; - } - - public static boolean isRTL(final Context context) { - if (context == null) return false; - final Resources res = context.getResources(); - return "ar".equals(res.getConfiguration().locale.getLanguage()); - // return - // ConfigurationAccessor.getLayoutDirection(res.getConfiguration()) == - // SCREENLAYOUT_LAYOUTDIR_RTL; - } - public static boolean isUserLoggedIn(final Context context, final long accountId) { if (context == null) return false; - final AccountKey[] ids = DataStoreUtils.getAccountKeys(context); - for (final AccountKey id : ids) { + final UserKey[] ids = DataStoreUtils.getAccountKeys(context); + for (final UserKey id : ids) { if (id.getId() == accountId) return true; } return false; @@ -1797,7 +1776,7 @@ public final class Utils implements Constants { static boolean isMyStatus(ParcelableStatus status) { if (isMyRetweet(status)) return true; - return status.account_key.getId() == status.user_id; + return status.account_key.maybeEquals(status.user_key); } public static boolean shouldStopAutoRefreshOnBatteryLow(final Context context) { @@ -2022,7 +2001,7 @@ public final class Utils implements Constants { return in.size() != out.size(); } - public static void updateRelationship(Context context, Relationship relationship, AccountKey accountId) { + public static void updateRelationship(Context context, Relationship relationship, UserKey accountId) { final ContentResolver resolver = context.getContentResolver(); final ContentValues values = ContentValuesCreator.createCachedRelationship(relationship, accountId); resolver.insert(CachedRelationships.CONTENT_URI, values); @@ -2097,7 +2076,7 @@ public final class Utils implements Constants { @Nullable public static ParcelableUser getUserForConversation(@NonNull final Context context, - @NonNull final AccountKey accountKey, + @NonNull final UserKey accountKey, final long conversationId) { final ContentResolver cr = context.getContentResolver(); final Expression where = Expression.and(Expression.equalsArgs(ConversationEntries.ACCOUNT_KEY), @@ -2147,7 +2126,7 @@ public final class Utils implements Constants { context.startActivity(intent); } - public static void openProfileEditor(Context context, @Nullable AccountKey accountId) { + public static void openProfileEditor(Context context, @Nullable UserKey accountId) { final Intent intent = new Intent(); final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); @@ -2217,7 +2196,7 @@ public final class Utils implements Constants { public static void logOpenNotificationFromUri(Context context, Uri uri) { if (!uri.getBooleanQueryParameter(QUERY_PARAM_FROM_NOTIFICATION, false)) return; final String type = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE); - final AccountKey accountKey = AccountKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); + final UserKey accountKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)); final long itemId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_id"), -1); final long itemUserId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_user_id"), -1); final boolean itemUserFollowing = Boolean.parseBoolean(UriExtraUtils.getExtra(uri, "item_user_following")); @@ -2242,7 +2221,7 @@ public final class Utils implements Constants { return isOAuth && TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret); } - public static int getNotificationId(int baseId, @Nullable AccountKey accountId) { + public static int getNotificationId(int baseId, @Nullable UserKey accountId) { int result = baseId; result = 31 * result + (accountId != null ? accountId.hashCode() : 0); return result; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java index bf09aae1c..bd730cee5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/content/ContentResolverUtils.java @@ -25,6 +25,9 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.text.TextUtils; +import org.mariotaku.sqliteqb.library.ArgsArray; +import org.mariotaku.sqliteqb.library.Columns; +import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.twidere.util.TwidereArrayUtils; import java.lang.reflect.Array; @@ -36,35 +39,27 @@ public class ContentResolverUtils { public static int bulkDelete(@NonNull final ContentResolver resolver, @NonNull final Uri uri, @NonNull final String inColumn, final Collection colValues, - final String extraWhere, final boolean valuesIsString) { + final String extraWhere) { if (colValues == null) return 0; - return bulkDelete(resolver, uri, inColumn, colValues.toArray(), extraWhere, valuesIsString); + return bulkDelete(resolver, uri, inColumn, colValues.toArray(), extraWhere); } public static int bulkDelete(@NonNull final ContentResolver resolver, @NonNull final Uri uri, - @NonNull final String inColumn, final Object colValues, - final String extraWhere, final boolean valuesIsString) { + @NonNull final String inColumn, final Object colValues, + final String extraWhere) { if (colValues == null) return 0; final int colValuesLength = Array.getLength(colValues), blocksCount = colValuesLength / MAX_BULK_COUNT + 1; int rowsDeleted = 0; for (int i = 0; i < blocksCount; i++) { - final int start = i * MAX_BULK_COUNT, end = Math.min(start + MAX_BULK_COUNT, colValuesLength); + final int start = i * MAX_BULK_COUNT, end = Math.min(start + MAX_BULK_COUNT, + colValuesLength); final String[] block = TwidereArrayUtils.toStringArray(colValues, start, end); - if (valuesIsString) { - final StringBuilder where = new StringBuilder(inColumn + " IN(" + TwidereArrayUtils.toStringForSQL(block) - + ")"); - if (!TextUtils.isEmpty(extraWhere)) { - where.append("AND ").append(extraWhere); - } - rowsDeleted += resolver.delete(uri, where.toString(), block); - } else { - final StringBuilder where = new StringBuilder(inColumn + " IN(" - + TwidereArrayUtils.toString(block, ',', true) + ")"); - if (!TextUtils.isEmpty(extraWhere)) { - where.append("AND ").append(extraWhere); - } - rowsDeleted += resolver.delete(uri, where.toString(), null); + final StringBuilder where = new StringBuilder(Expression.in(new Columns.Column(inColumn), + new ArgsArray(block.length)).getSQL()); + if (!TextUtils.isEmpty(extraWhere)) { + where.append(" AND ").append(extraWhere); } + rowsDeleted += resolver.delete(uri, where.toString(), block); } return rowsDeleted; } 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 ebdd9879e..63c5925c1 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 @@ -32,6 +32,7 @@ import org.mariotaku.sqliteqb.library.Constraint; import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.sqliteqb.library.NewColumn; import org.mariotaku.sqliteqb.library.OnConflict; +import org.mariotaku.sqliteqb.library.RawSQLLang; import org.mariotaku.sqliteqb.library.SQLQuery; import org.mariotaku.sqliteqb.library.SQLQueryBuilder; import org.mariotaku.sqliteqb.library.SetValue; @@ -82,7 +83,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C db.execSQL(createTable(Activities.ByFriends.TABLE_NAME, Activities.ByFriends.COLUMNS, Activities.ByFriends.TYPES, true)); db.execSQL(createTable(Drafts.TABLE_NAME, Drafts.COLUMNS, Drafts.TYPES, true)); db.execSQL(createTable(CachedUsers.TABLE_NAME, CachedUsers.COLUMNS, CachedUsers.TYPES, true, - createConflictReplaceConstraint(CachedUsers.USER_ID, CachedUsers.USER_HOST))); + createConflictReplaceConstraint(CachedUsers.USER_KEY, CachedUsers.USER_HOST))); 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, @@ -150,7 +151,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C .actions(SQLQueryBuilder.update(OnConflict.REPLACE, filteredUsersTable) .set(new SetValue(new Column(Filters.Users.NAME), new Column(Table.NEW, CachedUsers.NAME)), new SetValue(new Column(Filters.Users.SCREEN_NAME), new Column(Table.NEW, CachedUsers.SCREEN_NAME))) - .where(Expression.equals(new Column(Filters.Users.USER_ID), new Column(Table.NEW, CachedUsers.USER_ID))) + .where(Expression.equals(new Column(Filters.Users.USER_ID), new Column(Table.NEW, CachedUsers.USER_KEY))) .build()) .buildSQL()); @@ -233,7 +234,7 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C Activities.ByFriends.TYPES, true, null); safeUpgrade(db, Drafts.TABLE_NAME, Drafts.COLUMNS, Drafts.TYPES, false, draftsAlias); safeUpgrade(db, CachedUsers.TABLE_NAME, CachedUsers.COLUMNS, CachedUsers.TYPES, true, null, - createConflictReplaceConstraint(CachedUsers.USER_ID, CachedUsers.USER_HOST)); + createConflictReplaceConstraint(CachedUsers.USER_KEY, CachedUsers.USER_HOST)); 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, @@ -255,6 +256,11 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C safeUpgrade(db, Tabs.TABLE_NAME, Tabs.COLUMNS, Tabs.TYPES, false, null); safeUpgrade(db, SavedSearches.TABLE_NAME, SavedSearches.COLUMNS, SavedSearches.TYPES, true, null); safeUpgrade(db, SearchHistory.TABLE_NAME, SearchHistory.COLUMNS, SearchHistory.TYPES, true, null); + + if (oldVersion < 131) { + migrateFilteredUsers(db); + } + db.beginTransaction(); db.execSQL(SQLQueryBuilder.dropTable(true, "network_usages").getSQL()); db.execSQL(SQLQueryBuilder.dropTable(true, "mentions").getSQL()); @@ -265,6 +271,14 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C db.endTransaction(); } + private void migrateFilteredUsers(SQLiteDatabase db) { + db.execSQL(SQLQueryBuilder.update(OnConflict.REPLACE, Filters.Users.TABLE_NAME) + .set(new SetValue(Filters.Users.USER_ID, new RawSQLLang(Filters.Users.USER_ID + "||?"))) + .where(Expression.notLikeArgs(new Column(Filters.Users.USER_ID))) + .buildSQL(), + new Object[]{"@twitter.com", "%@%"}); + } + private static String createTable(final String tableName, final String[] columns, final String[] types, final boolean createIfNotExists, final Constraint... constraints) { final SQLCreateTableQuery.Builder qb = SQLQueryBuilder.createTable(createIfNotExists, tableName); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java b/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java index ec392e637..fee3eb027 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/media/MediaExtra.java @@ -1,21 +1,21 @@ package org.mariotaku.twidere.util.media; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; /** * Created by mariotaku on 16/1/28. */ public class MediaExtra { - AccountKey accountKey; + UserKey accountKey; boolean useThumbor = true; String fallbackUrl; boolean skipUrlReplacing; - public AccountKey getAccountKey() { + public UserKey getAccountKey() { return accountKey; } - public void setAccountKey(AccountKey accountKey) { + public void setAccountKey(UserKey accountKey) { this.accountKey = accountKey; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java index ef9ab90e6..cef59fb7b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java @@ -35,7 +35,7 @@ import android.widget.TextView; import org.apache.commons.lang3.ObjectUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.util.ParcelableMediaUtils; import org.mariotaku.twidere.util.MediaLoaderWrapper; @@ -91,7 +91,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { public void displayMedia(@Nullable final ParcelableMedia[] mediaArray, @NonNull final MediaLoaderWrapper loader, - final AccountKey accountId, final long extraId, + final UserKey accountId, final long extraId, final OnMediaClickListener mediaClickListener, final MediaLoadingHandler loadingHandler) { displayMedia(mediaArray, loader, accountId, extraId, false, mediaClickListener, @@ -100,7 +100,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { public void displayMedia(@Nullable final ParcelableMedia[] mediaArray, @NonNull final MediaLoaderWrapper loader, - final AccountKey accountId, final long extraId, boolean withCredentials, + final UserKey accountId, final long extraId, boolean withCredentials, final OnMediaClickListener mediaClickListener, final MediaLoadingHandler loadingHandler) { if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) { @@ -301,15 +301,15 @@ public class CardMediaContainer extends ViewGroup implements Constants { } public interface OnMediaClickListener { - void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long id); + void onMediaClick(View view, ParcelableMedia media, UserKey accountKey, long id); } private static class ImageGridClickListener implements View.OnClickListener { private final WeakReference mListenerRef; - private final AccountKey mAccountKey; + private final UserKey mAccountKey; private final long mExtraId; - ImageGridClickListener(final OnMediaClickListener listener, final AccountKey accountKey, + ImageGridClickListener(final OnMediaClickListener listener, final UserKey accountKey, final long extraId) { mListenerRef = new WeakReference<>(listener); mAccountKey = accountKey; diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ComposeEditText.java b/twidere/src/main/java/org/mariotaku/twidere/view/ComposeEditText.java index 1c923d22a..a3c3c7e25 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ComposeEditText.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ComposeEditText.java @@ -33,7 +33,7 @@ import android.widget.AdapterView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.EmojiSupportUtils; import org.mariotaku.twidere.util.widget.StatusTextTokenizer; import org.mariotaku.twidere.view.iface.IThemeBackgroundTintView; @@ -41,7 +41,7 @@ import org.mariotaku.twidere.view.iface.IThemeBackgroundTintView; public class ComposeEditText extends AppCompatMultiAutoCompleteTextView implements IThemeBackgroundTintView { private ComposeAutoCompleteAdapter mAdapter; - private AccountKey mAccountKey; + private UserKey mAccountKey; public ComposeEditText(final Context context) { this(context, null); @@ -70,7 +70,7 @@ public class ComposeEditText extends AppCompatMultiAutoCompleteTextView implemen setSupportBackgroundTintList(color); } - public void setAccountKey(AccountKey accountKey) { + public void setAccountKey(UserKey accountKey) { mAccountKey = accountKey; updateAccountId(); } 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 ef4f82b27..bd866331f 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 @@ -30,7 +30,7 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.MessageEntriesAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.ConversationEntries; import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.MediaLoaderWrapper; @@ -69,8 +69,8 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene final MediaLoaderWrapper loader = adapter.getMediaLoader(); final UserColorNameManager manager = adapter.getUserColorNameManager(); - final AccountKey accountKey = AccountKey.valueOf(cursor.getString(ConversationEntries.IDX_ACCOUNT_KEY)); - final long conversationId = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID); + final UserKey accountKey = UserKey.valueOf(cursor.getString(ConversationEntries.IDX_ACCOUNT_KEY)); + final UserKey conversationId = UserKey.valueOf(cursor.getString(ConversationEntries.IDX_CONVERSATION_ID)); final long timestamp = cursor.getLong(ConversationEntries.IDX_MESSAGE_TIMESTAMP); final boolean isOutgoing = cursor.getInt(ConversationEntries.IDX_IS_OUTGOING) == 1; diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageViewHolder.java index 11c092588..c8c5f6a5a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageViewHolder.java @@ -31,7 +31,7 @@ import android.widget.TextView; import org.mariotaku.messagebubbleview.library.MessageBubbleView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.MessageConversationAdapter; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.util.HtmlSpanBuilder; @@ -78,7 +78,7 @@ public class MessageViewHolder extends ViewHolder { final TwidereLinkify linkify = adapter.getLinkify(); final MediaLoaderWrapper loader = adapter.getMediaLoader(); - final AccountKey accountKey = AccountKey.valueOf(cursor.getString(indices.account_key)); + final UserKey accountKey = UserKey.valueOf(cursor.getString(indices.account_key)); final long timestamp = cursor.getLong(indices.timestamp); final ParcelableMedia[] media = JsonSerializer.parseArray(cursor.getString(indices.media), ParcelableMedia.class); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java index d7f49f0ce..96debd706 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java @@ -21,12 +21,11 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable; -import org.mariotaku.twidere.model.AccountKey; import org.mariotaku.twidere.model.ParcelableLocation; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.util.AsyncTwitterWrapper; -import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.HtmlSpanBuilder; import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.TwidereLinkify; @@ -234,7 +233,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi if (statusContentUpperSpace != null) { statusContentUpperSpace.setVisibility(View.GONE); } - } else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id > 0 && displayInReplyTo) { + } else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id != null && displayInReplyTo) { final String inReplyTo = manager.getDisplayName(status.in_reply_to_user_id, status.in_reply_to_name, status.in_reply_to_screen_name, nameFirst, false); statusInfoLabel.setText(context.getString(R.string.in_reply_to_name, formatter.unicodeWrap(inReplyTo))); @@ -280,7 +279,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi } quoteIndicator.setColor(manager.getUserColor(status.quoted_user_id, false)); - itemContent.drawStart(manager.getUserColor(status.user_id, false)); + itemContent.drawStart(manager.getUserColor(status.user_key, false)); } else { quotedNameView.setVisibility(View.GONE); @@ -289,9 +288,9 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi if (status.is_retweet) { itemContent.drawStart(manager.getUserColor(status.retweeted_by_user_id, false), - manager.getUserColor(status.user_id, false)); + manager.getUserColor(status.user_key, false)); } else { - itemContent.drawStart(manager.getUserColor(status.user_id, false)); + itemContent.drawStart(manager.getUserColor(status.user_key, false)); } } @@ -300,7 +299,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi } else { timeView.setTime(status.timestamp); } - nameView.setName(manager.getUserNickname(status.user_id, status.user_name, false)); + nameView.setName(manager.getUserNickname(status.user_key, status.user_name, false)); nameView.setScreenName("@" + status.user_screen_name); if (statusInfoSpace != null) { @@ -391,7 +390,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi } else { final boolean creatingRetweet = twitter.isCreatingRetweet(status.account_key, status.id); retweetIconView.setActivated(creatingRetweet || status.retweeted || - Utils.isMyRetweet(status.account_key.getId(), status.retweeted_by_user_id, + Utils.isMyRetweet(status.account_key, status.retweeted_by_user_id, status.my_retweet_id)); retweetCount = status.retweet_count + (creatingRetweet ? 1 : 0); } @@ -439,7 +438,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi } @Override - public void onMediaClick(View view, ParcelableMedia media, AccountKey accountId, long extraId) { + public void onMediaClick(View view, ParcelableMedia media, UserKey accountId, long extraId) { if (statusClickListener == null) return; final int position = getLayoutPosition(); statusClickListener.onMediaClick(this, view, media, position); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserListViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserListViewHolder.java index 2516ea382..199c67730 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserListViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/UserListViewHolder.java @@ -72,7 +72,7 @@ public class UserListViewHolder extends ViewHolder implements View.OnClickListen final MediaLoaderWrapper loader = adapter.getMediaLoader(); final UserColorNameManager manager = adapter.getUserColorNameManager(); - itemContent.drawStart(manager.getUserColor(userList.user_id, false)); + itemContent.drawStart(manager.getUserColor(userList.user_key, false)); nameView.setText(userList.name); final boolean nameFirst = adapter.isNameFirst(); final String createdByDisplayName = manager.getDisplayName(userList, nameFirst, false); 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 61186a512..d70761712 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 @@ -87,7 +87,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper(); - itemContent.drawStart(manager.getUserColor(user.id, false)); + itemContent.drawStart(manager.getUserColor(user.key, false)); final int userTypeRes = getUserTypeIconRes(user.is_verified, user.is_protected); if (userTypeRes != 0) { @@ -95,7 +95,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon } else { profileTypeView.setImageDrawable(null); } - nameView.setName(manager.getUserNickname(user.id, user.name, false)); + nameView.setName(manager.getUserNickname(user.key, user.name, false)); nameView.setScreenName("@" + user.screen_name); nameView.updateText(adapter.getBidiFormatter()); descriptionView.setVisibility(TextUtils.isEmpty(user.description_unescaped) ? View.GONE : View.VISIBLE); @@ -116,7 +116,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon loader.cancelDisplayTask(profileImageView); } - if (twitter.isProcessingFollowRequest(user.account_key, user.id)) { + if (twitter.isProcessingFollowRequest(user.account_key, user.key)) { processingRequestProgress.setVisibility(View.VISIBLE); acceptRequestButton.setVisibility(View.GONE); denyRequestButton.setVisibility(View.GONE); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java index 94eb84cb5..2abf931fe 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.java @@ -27,7 +27,7 @@ import android.widget.ImageView; import org.mariotaku.twidere.adapter.iface.ContentCardClickListener; import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable; -import org.mariotaku.twidere.model.AccountKey; +import org.mariotaku.twidere.model.UserKey; import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.view.CardMediaContainer; @@ -48,7 +48,7 @@ public interface IStatusViewHolder extends CardMediaContainer.OnMediaClickListen ImageView getProfileTypeView(); @Override - void onMediaClick(View view, ParcelableMedia media, AccountKey accountKey, long extraId); + void onMediaClick(View view, ParcelableMedia media, UserKey accountKey, long extraId); void setStatusClickListener(StatusClickListener listener); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/iface/IColorLabelView.java b/twidere/src/main/java/org/mariotaku/twidere/view/iface/IColorLabelView.java index 4b9b26939..e3527579b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/iface/IColorLabelView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/iface/IColorLabelView.java @@ -24,13 +24,12 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; +import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.view.View; import org.mariotaku.twidere.R; -import static org.mariotaku.twidere.util.Utils.isRTL; - public interface IColorLabelView { float LABEL_WIDTH = 3.5f; @@ -76,7 +75,7 @@ public interface IColorLabelView { a.recycle(); final Resources res = context.getResources(); mDensity = res.getDisplayMetrics().density; - mIsRTL = isRTL(context); + mIsRTL = ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; } public void dispatchDrawBackground(final Canvas canvas) {