fixed user id crashes

This commit is contained in:
Mariotaku Lee 2016-03-31 08:09:41 +08:00
parent 84b5748e2c
commit bf2311d5c9
7 changed files with 73 additions and 48 deletions

View File

@ -6,11 +6,8 @@ package org.mariotaku.twidere.constant;
public interface CompatibilityConstants {
String QUERY_PARAM_ACCOUNT_ID = "account_id";
String QUERY_PARAM_ACCOUNT_IDS = "account_ids";
String QUERY_PARAM_USER_ID = "user_id";
String EXTRA_ACCOUNT_ID = "account_id";
String EXTRA_ACCOUNT_IDS = "account_ids";
String EXTRA_USER_ID = "user_id";
}

View File

@ -56,12 +56,14 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
}
};
public static final Creator<ParcelableStatus> CREATOR = new Creator<ParcelableStatus>() {
@Override
public ParcelableStatus createFromParcel(Parcel source) {
ParcelableStatus target = new ParcelableStatus();
ParcelableStatusParcelablePlease.readFromParcel(target, source);
return target;
}
@Override
public ParcelableStatus[] newArray(int size) {
return new ParcelableStatus[size];
}
@ -385,22 +387,24 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
@Override
public String toString() {
return "ParcelableStatus{" +
"id=" + id +
"id='" + id + '\'' +
", sort_id=" + sort_id +
", account_key=" + account_key +
", timestamp=" + timestamp +
", user_id=" + user_key +
", retweet_id=" + retweet_id +
", retweeted_by_user_id=" + retweeted_by_user_key +
", position_key=" + position_key +
", user_key=" + user_key +
", retweet_id='" + retweet_id + '\'' +
", retweeted_by_user_key=" + retweeted_by_user_key +
", retweet_timestamp=" + retweet_timestamp +
", retweet_count=" + retweet_count +
", favorite_count=" + favorite_count +
", reply_count=" + reply_count +
", in_reply_to_status_id=" + in_reply_to_status_id +
", in_reply_to_status_id='" + in_reply_to_status_id + '\'' +
", in_reply_to_user_id=" + in_reply_to_user_id +
", my_retweet_id=" + my_retweet_id +
", quoted_id=" + quoted_id +
", my_retweet_id='" + my_retweet_id + '\'' +
", quoted_id='" + quoted_id + '\'' +
", quoted_timestamp=" + quoted_timestamp +
", quoted_user_id=" + quoted_user_key +
", quoted_user_key=" + quoted_user_key +
", is_gap=" + is_gap +
", is_retweet=" + is_retweet +
", retweeted=" + retweeted +
@ -440,6 +444,17 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
", quoted_media=" + Arrays.toString(quoted_media) +
", card=" + card +
", extras=" + extras +
", spans=" + Arrays.toString(spans) +
", quoted_spans=" + Arrays.toString(quoted_spans) +
", is_filtered=" + is_filtered +
", account_color=" + account_color +
", user_color=" + user_color +
", quoted_user_color=" + quoted_user_color +
", retweet_user_color=" + retweet_user_color +
", user_nickname='" + user_nickname + '\'' +
", quoted_user_nickname='" + quoted_user_nickname + '\'' +
", retweet_user_nickname='" + retweet_user_nickname + '\'' +
", in_reply_to_user_nickname='" + in_reply_to_user_nickname + '\'' +
", _id=" + _id +
'}';
}
@ -486,12 +501,14 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
public static class Extras implements Parcelable {
public static final Creator<Extras> CREATOR = new Creator<Extras>() {
@Override
public Extras createFromParcel(Parcel source) {
Extras target = new Extras();
ParcelableStatus$ExtrasParcelablePlease.readFromParcel(target, source);
return target;
}
@Override
public Extras[] newArray(int size) {
return new Extras[size];
}

View File

@ -460,7 +460,6 @@ public class ComposeActivity extends BaseActivity implements OnMenuItemClickList
if (INTENT_ACTION_EXTENSION_COMPOSE.equals(action)) {
final UserKey[] accountKeys = mAccountsAdapter.getSelectedAccountKeys();
intent.putExtra(EXTRA_TEXT, ParseUtils.parseString(mEditText.getText()));
intent.putExtra(EXTRA_ACCOUNT_IDS, UserKey.getIds(accountKeys));
intent.putExtra(EXTRA_ACCOUNT_KEYS, accountKeys);
if (accountKeys.length > 0) {
final UserKey accountKey = accountKeys[0];

View File

@ -114,9 +114,11 @@ public final class ParcelableUserLoader extends AsyncTaskLoader<SingleResponse<P
if (mUserKey != null) {
where = Expression.equalsArgs(CachedUsers.USER_KEY);
whereArgs = new String[]{mUserKey.toString()};
} else {
} else if (mScreenName != null) {
where = Expression.equalsArgs(CachedUsers.SCREEN_NAME);
whereArgs = new String[]{mScreenName};
} else {
return SingleResponse.getInstance();
}
final Cursor cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS,
where.getSQL(), whereArgs, null);

View File

@ -8,6 +8,7 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.model.UserKey;
@ -19,19 +20,11 @@ import java.util.Arrays;
@JsonObject
public class TabArguments implements TwidereConstants {
@JsonField(name = "account_id")
String accountId = null;
String accountId;
@JsonField(name = "account_keys")
UserKey[] accountKeys;
public String getAccountId() {
return accountId;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
}
public UserKey[] getAccountKeys() {
return accountKeys;
}
@ -40,6 +33,10 @@ public class TabArguments implements TwidereConstants {
this.accountKeys = accountKeys;
}
public String getAccountId() {
return accountId;
}
@CallSuper
public void copyToBundle(@NonNull Bundle bundle) {
if (!ArrayUtils.isEmpty(accountKeys)) {
@ -48,7 +45,12 @@ public class TabArguments implements TwidereConstants {
}
bundle.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountKeys);
} else if (accountId != null) {
bundle.putString(EXTRA_ACCOUNT_ID, accountId);
final long id = NumberUtils.toLong(accountId, Long.MIN_VALUE);
if (id != Long.MIN_VALUE && id <= 0) {
bundle.putParcelableArray(EXTRA_ACCOUNT_KEYS, new UserKey[0]);
return;
}
bundle.putParcelableArray(EXTRA_ACCOUNT_KEYS, new UserKey[]{UserKey.valueOf(accountId)});
}
}

View File

@ -502,7 +502,7 @@ public final class Utils implements Constants {
case LINK_ID_USER: {
fragment = new UserFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -515,7 +515,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LIST_MEMBERSHIPS: {
fragment = new UserListMembershipsFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -527,7 +527,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_TIMELINE: {
fragment = new UserTimelineFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -540,7 +540,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_MEDIA_TIMELINE: {
fragment = new UserMediaTimelineFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -553,7 +553,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_FAVORITES: {
fragment = new UserFavoritesFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -567,7 +567,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_FOLLOWERS: {
fragment = new UserFollowersFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -580,7 +580,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_FRIENDS: {
fragment = new UserFriendsFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -633,7 +633,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LIST: {
fragment = new UserListFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
if ((isEmpty(paramListName) || isEmpty(paramScreenName) && paramUserKey == null)
@ -658,7 +658,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LISTS: {
fragment = new ListsFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -671,7 +671,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_GROUPS: {
fragment = new UserGroupsFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
if (!args.containsKey(EXTRA_SCREEN_NAME)) {
args.putString(EXTRA_SCREEN_NAME, paramScreenName);
}
@ -684,7 +684,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LIST_TIMELINE: {
fragment = new UserListTimelineFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
if ((isEmpty(paramListName) || isEmpty(paramScreenName) && paramUserKey == null)
@ -700,7 +700,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LIST_MEMBERS: {
fragment = new UserListMembersFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
if ((isEmpty(paramListName) || isEmpty(paramScreenName) && paramUserKey == null)
@ -715,7 +715,7 @@ public final class Utils implements Constants {
case LINK_ID_USER_LIST_SUBSCRIBERS: {
fragment = new UserListSubscribersFragment();
final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
final UserKey paramUserKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_USER_KEY));
final UserKey paramUserKey = UserKey.valueOf(getUserKeyParam(uri));
final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
if (isEmpty(paramListId)
@ -801,6 +801,14 @@ public final class Utils implements Constants {
return fragment;
}
public static String getUserKeyParam(Uri uri) {
final String paramUserKey = uri.getQueryParameter(QUERY_PARAM_USER_KEY);
if (paramUserKey == null) {
return uri.getQueryParameter(QUERY_PARAM_USER_ID);
}
return paramUserKey;
}
public static Intent createStatusShareIntent(@NonNull final Context context, @NonNull final ParcelableStatus status) {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");

View File

@ -14,14 +14,14 @@
android:title="@string/project_account">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=583328497&amp;finish_only=true"/>
android:data="twidere://user?user_key=583328497@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="@string/developer_name"
android:title="@string/developed_by">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=57610574&amp;finish_only=true"/>
android:data="twidere://user?user_key=57610574@twitter.com&amp;finish_only=true"/>
</Preference>
</PreferenceCategory>
<PreferenceCategory
@ -37,7 +37,7 @@
android:title="@string/translators">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user_list_members?list_id=99024901&amp;user_id=583328497&amp;finish_only=true"/>
android:data="twidere://user_list_members?list_id=99024901&amp;user_key=583328497@twitter.com&amp;finish_only=true"/>
</Preference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/special_thanks_to">
@ -53,49 +53,49 @@
android:title="ilovinheart">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=144878723&amp;finish_only=true"/>
android:data="twidere://user?user_key=144878723@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="Adjusted icon from 0.0.13 version to 0.2.9.10 version"
android:title="lordfriend">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=450691326&amp;finish_only=true"/>
android:data="twidere://user?user_key=450691326@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="Designed 3D Twidere icon"
android:title="Linkzero">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=12630242&amp;finish_only=true"/>
android:data="twidere://user?user_key=12630242@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="He taught me some useful things about SQLite"
android:title="impulseplus">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=332135263&amp;finish_only=true"/>
android:data="twidere://user?user_key=332135263@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="Checked Japanese translation for Luigi Van"
android:title="Lin Yan">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=218536728&amp;finish_only=true"/>
android:data="twidere://user?user_key=218536728@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="Redesigned interface, polished settings &amp; writing style"
android:title="Uucky Lee">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=1062473329&amp;finish_only=true"/>
android:data="twidere://user?user_key=1062473329@twitter.com&amp;finish_only=true"/>
</Preference>
<Preference
android:summary="Special birthday banner image"
android:title="sacrish">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=7758552&amp;finish_only=true"/>
android:data="twidere://user?user_key=7758552@twitter.com&amp;finish_only=true"/>
</Preference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/sponsored_by">
@ -104,7 +104,7 @@
android:title="@string/kuma_union">
<intent
android:action="android.intent.action.VIEW"
android:data="twidere://user?user_id=514378421&amp;finish_only=true"/>
android:data="twidere://user?user_key=514378421@twitter.com&amp;finish_only=true"/>
</Preference>
</PreferenceCategory>