1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-18 19:43:35 +01:00

fixed 'open with account' in status fragment

This commit is contained in:
Mariotaku Lee 2015-03-31 17:51:22 +08:00
parent 770bb81c89
commit 18aa437d7b
4 changed files with 41 additions and 27 deletions

View File

@ -83,7 +83,8 @@ public abstract class AbsStatusesFragment<Data> extends BaseSupportFragment impl
public boolean onMenuItemClick(MenuItem item) {
final ParcelableStatus status = mSelectedStatus;
if (status == null) return false;
return Utils.handleMenuItemClick(getActivity(), getFragmentManager(), getTwitterWrapper(), status, item);
return Utils.handleMenuItemClick(getActivity(), AbsStatusesFragment.this,
getFragmentManager(), getTwitterWrapper(), status, item);
}
};

View File

@ -1031,12 +1031,12 @@ public class StatusFragment extends BaseSupportFragment
@Override
public boolean onMenuItemClick(MenuItem item) {
final StatusFragment fragment = adapter.getFragment();
final ParcelableStatus status = adapter.getStatus(getPosition());
final ParcelableStatus status = adapter.getStatus(getAdapterPosition());
if (status == null || fragment == null) return false;
final AsyncTwitterWrapper twitter = fragment.getTwitterWrapper();
final FragmentActivity activity = fragment.getActivity();
final FragmentManager fm = fragment.getFragmentManager();
return Utils.handleMenuItemClick(activity, fm, twitter, status, item);
return Utils.handleMenuItemClick(activity, fragment, fm, twitter, status, item);
}
public void showStatus(ParcelableStatus status) {

View File

@ -107,9 +107,13 @@ public class TwitterWrapper implements Constants {
@NonNull
public static User showUser(final Twitter twitter, final long id, final String screenName) throws TwitterException {
if (id != -1)
if (twitter.getId() == id || twitter.getScreenName().equalsIgnoreCase(screenName)) {
return twitter.verifyCredentials();
} else if (id != -1) {
return twitter.showUser(id);
else if (screenName != null) return twitter.showUser(screenName);
} else if (screenName != null) {
return twitter.showUser(screenName);
}
throw new IllegalArgumentException();
}
@ -140,7 +144,8 @@ public class TwitterWrapper implements Constants {
}
}
for (final User user : twitter.searchUsers(searchScreenName, 1)) {
if (user.getId() == id || searchScreenName.equalsIgnoreCase(user.getScreenName())) return user;
if (user.getId() == id || searchScreenName.equalsIgnoreCase(user.getScreenName()))
return user;
}
throw new TwitterException("can't find user");
}

View File

@ -3920,11 +3920,11 @@ public final class Utils implements Constants, TwitterConstants {
return pm.getDrawable(info.packageName, info.metaData.getInt(key), info.applicationInfo);
}
public static boolean handleMenuItemClick(FragmentActivity activity, FragmentManager fm, AsyncTwitterWrapper twitter, ParcelableStatus status, MenuItem item) {
public static boolean handleMenuItemClick(Context context, Fragment fragment, FragmentManager fm, AsyncTwitterWrapper twitter, ParcelableStatus status, MenuItem item) {
switch (item.getItemId()) {
case MENU_COPY: {
if (ClipboardUtils.setText(activity, status.text_plain)) {
showOkMessage(activity, R.string.text_copied, false);
if (ClipboardUtils.setText(context, status.text_plain)) {
showOkMessage(context, R.string.text_copied, false);
}
break;
}
@ -3939,25 +3939,25 @@ public final class Utils implements Constants, TwitterConstants {
case MENU_QUOTE: {
final Intent intent = new Intent(INTENT_ACTION_QUOTE);
intent.putExtra(EXTRA_STATUS, status);
activity.startActivity(intent);
context.startActivity(intent);
break;
}
case MENU_REPLY: {
final Intent intent = new Intent(INTENT_ACTION_REPLY);
intent.putExtra(EXTRA_STATUS, status);
activity.startActivity(intent);
context.startActivity(intent);
break;
}
case MENU_FAVORITE: {
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_id, status.id);
//spice
SpiceProfilingUtil.profile(activity,
SpiceProfilingUtil.profile(context,
status.account_id, status.id + ",Unfavor," + status.account_id
+ "," + status.user_id + "," + status.reply_count
+ "," + status.retweet_count + "," + status.favorite_count
+ "," + status.timestamp);
SpiceProfilingUtil.log(activity, status.id + ",Unfavor," + status.account_id
SpiceProfilingUtil.log(context, status.id + ",Unfavor," + status.account_id
+ "," + status.user_id + "," + status.reply_count
+ "," + status.retweet_count + "," + status.favorite_count
+ "," + status.timestamp);
@ -3965,12 +3965,12 @@ public final class Utils implements Constants, TwitterConstants {
} else {
twitter.createFavoriteAsync(status.account_id, status.id);
//spice
SpiceProfilingUtil.profile(activity,
SpiceProfilingUtil.profile(context,
status.account_id, status.id + ",Favor,"
+ status.account_id + "," + status.user_id + "," + status.reply_count
+ "," + status.retweet_count + "," + status.favorite_count
+ "," + status.timestamp);
SpiceProfilingUtil.log(activity, status.id + ",Favor,"
SpiceProfilingUtil.log(context, status.id + ",Favor,"
+ status.account_id + "," + status.user_id + "," + status.reply_count
+ "," + status.retweet_count + "," + status.favorite_count + "," + status.timestamp);
//end
@ -3986,32 +3986,36 @@ public final class Utils implements Constants, TwitterConstants {
break;
}
case MENU_SET_COLOR: {
final Intent intent = new Intent(activity, ColorPickerDialogActivity.class);
final int color = getUserColor(activity, status.user_id, true);
final Intent intent = new Intent(context, ColorPickerDialogActivity.class);
final int color = getUserColor(context, status.user_id, true);
if (color != 0) {
intent.putExtra(EXTRA_COLOR, color);
}
intent.putExtra(EXTRA_CLEAR_BUTTON, color != 0);
intent.putExtra(EXTRA_ALPHA_SLIDER, false);
activity.startActivityForResult(intent, REQUEST_SET_COLOR);
if (fragment != null) {
fragment.startActivityForResult(intent, REQUEST_SET_COLOR);
} else if (context instanceof Activity) {
((Activity) context).startActivityForResult(intent, REQUEST_SET_COLOR);
}
break;
}
case MENU_CLEAR_NICKNAME: {
clearUserNickname(activity, status.user_id);
clearUserNickname(context, status.user_id);
break;
}
case MENU_SET_NICKNAME: {
final String nick = getUserNickname(activity, status.user_id, true);
final String nick = getUserNickname(context, status.user_id, true);
SetUserNicknameDialogFragment.show(fm, status.user_id, nick);
break;
}
case MENU_TRANSLATE: {
final ParcelableCredentials account
= ParcelableAccount.getCredentials(activity, status.account_id);
if (isOfficialCredentials(activity, account)) {
= ParcelableAccount.getCredentials(context, status.account_id);
if (isOfficialCredentials(context, account)) {
StatusTranslateDialogFragment.show(fm, status);
} else {
final Resources resources = activity.getResources();
final Resources resources = context.getResources();
final Locale locale = resources.getConfiguration().locale;
try {
final String template = "http://translate.google.com/#%s|%s|%s";
@ -4021,7 +4025,7 @@ public final class Utils implements Constants, TwitterConstants {
final Uri uri = Uri.parse(String.format(Locale.ROOT, template, sourceLang, targetLang, text));
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
activity.startActivity(intent);
context.startActivity(intent);
} catch (UnsupportedEncodingException ignore) {
}
@ -4030,15 +4034,19 @@ public final class Utils implements Constants, TwitterConstants {
}
case MENU_OPEN_WITH_ACCOUNT: {
final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
intent.setClass(activity, AccountSelectorActivity.class);
intent.setClass(context, AccountSelectorActivity.class);
intent.putExtra(EXTRA_SINGLE_SELECTION, true);
activity.startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
if (fragment != null) {
fragment.startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
} else if (context instanceof Activity) {
((Activity) context).startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
}
break;
}
default: {
if (item.getIntent() != null) {
try {
activity.startActivity(item.getIntent());
context.startActivity(item.getIntent());
} catch (final ActivityNotFoundException e) {
Log.w(LOGTAG, e);
return false;