This commit is contained in:
Mariotaku Lee 2016-04-17 11:00:47 +08:00
parent d7bf0a1c7a
commit a6d24f81a3
3 changed files with 62 additions and 45 deletions

View File

@ -266,7 +266,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mFollowProgress.setVisibility(View.GONE); mFollowProgress.setVisibility(View.GONE);
final ParcelableUser user = getUser(); final ParcelableUser user = getUser();
final UserRelationship relationship = data.getData(); final UserRelationship relationship = data.getData();
showRelationship(user, relationship); displayRelationship(user, relationship);
updateOptionsMenuVisibility();
} }
}; };
@ -315,13 +316,13 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, true); args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, true);
getLoaderManager().restartLoader(LOADER_ID_USER, args, this); getLoaderManager().restartLoader(LOADER_ID_USER, args, this);
} }
setHasOptionsMenu(true); updateOptionsMenuVisibility();
} else if (mUser != null && mUser.is_cache) { } else if (mUser != null && mUser.is_cache) {
mCardContent.setVisibility(View.VISIBLE); mCardContent.setVisibility(View.VISIBLE);
mHeaderErrorContainer.setVisibility(View.GONE); mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE); mProgressContainer.setVisibility(View.GONE);
displayUser(mUser); displayUser(mUser);
setHasOptionsMenu(true); updateOptionsMenuVisibility();
} else { } else {
if (data.hasException()) { if (data.hasException()) {
mHeaderErrorTextView.setText(Utils.getErrorMessage(activity, data.getException())); mHeaderErrorTextView.setText(Utils.getErrorMessage(activity, data.getException()));
@ -331,14 +332,18 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mHeaderErrorContainer.setVisibility(View.VISIBLE); mHeaderErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE); mProgressContainer.setVisibility(View.GONE);
displayUser(null); displayUser(null);
setHasOptionsMenu(false); updateOptionsMenuVisibility();
} }
} }
}; };
private void showRelationship(@Nullable final ParcelableUser user, private void updateOptionsMenuVisibility() {
@Nullable final UserRelationship userRelationship) { setHasOptionsMenu(mUser != null && mRelationship != null);
}
private void displayRelationship(@Nullable final ParcelableUser user,
@Nullable final UserRelationship userRelationship) {
if (user == null) { if (user == null) {
mRelationship = null; mRelationship = null;
return; return;
@ -346,7 +351,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (user.account_key.maybeEquals(user.key)) { if (user.account_key.maybeEquals(user.key)) {
mFollowButton.setText(R.string.edit); mFollowButton.setText(R.string.edit);
mFollowButton.setVisibility(View.VISIBLE); mFollowButton.setVisibility(View.VISIBLE);
mRelationship = null; mRelationship = userRelationship;
return; return;
} }
if (userRelationship == null || !userRelationship.check(user)) { if (userRelationship == null || !userRelationship.check(user)) {
@ -898,39 +903,43 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
MenuUtils.setMenuItemAvailability(menu, R.id.saved_searches, isMyself); MenuUtils.setMenuItemAvailability(menu, R.id.saved_searches, isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.scheduled_statuses, isMyself MenuUtils.setMenuItemAvailability(menu, R.id.scheduled_statuses, isMyself
&& TwitterAPIFactory.getOfficialKeyType(getActivity(), user.account_key) == ConsumerKeyType.TWEETDECK); && TwitterAPIFactory.getOfficialKeyType(getActivity(), user.account_key) == ConsumerKeyType.TWEETDECK);
MenuUtils.setMenuItemAvailability(menu, R.id.muted_users, isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.blocked_users, isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.block, !isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.mute_user, !isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.report_spam, !isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.enable_retweets, !isMyself);
final UserRelationship userRelationship = mRelationship; final UserRelationship userRelationship = mRelationship;
if (!isMyself && userRelationship != null) { if (userRelationship != null) {
MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, userRelationship.can_dm);
MenuUtils.setMenuItemAvailability(menu, R.id.block, true);
MenuUtils.setMenuItemAvailability(menu, R.id.mute_user, true);
final MenuItem blockItem = menu.findItem(R.id.block);
if (blockItem != null) {
ActionIconDrawable.setMenuHighlight(blockItem, new TwidereMenuInfo(userRelationship.blocking));
blockItem.setTitle(userRelationship.blocking ? R.string.unblock : R.string.block);
}
final MenuItem muteItem = menu.findItem(R.id.mute_user);
if (muteItem != null) {
muteItem.setChecked(userRelationship.muting);
}
final MenuItem filterItem = menu.findItem(R.id.add_to_filter); final MenuItem filterItem = menu.findItem(R.id.add_to_filter);
if (filterItem != null) { if (filterItem != null) {
ActionIconDrawable.setMenuHighlight(filterItem, new TwidereMenuInfo(userRelationship.filtering)); filterItem.setChecked(userRelationship.filtering);
filterItem.setTitle(userRelationship.filtering ? R.string.remove_from_filter : R.string.add_to_filter);
} }
final MenuItem wantRetweetsItem = menu.findItem(R.id.enable_retweets); if (isMyself) {
if (wantRetweetsItem != null) { MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, false);
wantRetweetsItem.setChecked(userRelationship.retweet_enabled); } else {
MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, userRelationship.can_dm);
MenuUtils.setMenuItemAvailability(menu, R.id.block, true);
final MenuItem blockItem = menu.findItem(R.id.block);
if (blockItem != null) {
ActionIconDrawable.setMenuHighlight(blockItem, new TwidereMenuInfo(userRelationship.blocking));
blockItem.setTitle(userRelationship.blocking ? R.string.unblock : R.string.block);
}
final MenuItem muteItem = menu.findItem(R.id.mute_user);
if (muteItem != null) {
muteItem.setChecked(userRelationship.muting);
}
final MenuItem wantRetweetsItem = menu.findItem(R.id.enable_retweets);
if (wantRetweetsItem != null) {
wantRetweetsItem.setChecked(userRelationship.retweet_enabled);
}
} }
} else { } else {
MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, false); MenuUtils.setMenuItemAvailability(menu, R.id.send_direct_message, false);
MenuUtils.setMenuItemAvailability(menu, R.id.enable_retweets, false);
MenuUtils.setMenuItemAvailability(menu, R.id.block, false);
MenuUtils.setMenuItemAvailability(menu, R.id.mute_user, false);
MenuUtils.setMenuItemAvailability(menu, R.id.report_spam, false);
} }
MenuUtils.setMenuItemAvailability(menu, R.id.muted_users, isMyself);
MenuUtils.setMenuItemAvailability(menu, R.id.blocked_users, isMyself);
final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
final Bundle extras = new Bundle(); final Bundle extras = new Bundle();
extras.putParcelable(EXTRA_USER, user); extras.putParcelable(EXTRA_USER, user);
@ -978,6 +987,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user)); cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false); Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
} }
getFriendship();
break; break;
} }
case R.id.mute_user: { case R.id.mute_user: {
@ -1749,9 +1759,12 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (mAccountKey == null || mUser == null) { if (mAccountKey == null || mUser == null) {
return SingleResponse.getInstance(new TwitterException("Null parameters")); return SingleResponse.getInstance(new TwitterException("Null parameters"));
} }
final boolean isFiltering = DataStoreUtils.isFilteringUser(context, mUser.key); final UserKey userKey = mUser.key;
if (mAccountKey.equals(mUser.key)) final boolean isFiltering = DataStoreUtils.isFilteringUser(context, userKey);
return SingleResponse.getInstance(); if (mAccountKey.equals(mUser.key)) {
return SingleResponse.getInstance(new UserRelationship(mAccountKey, userKey,
null, isFiltering));
}
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
mAccountKey); mAccountKey);
if (credentials == null) { if (credentials == null) {
@ -1768,7 +1781,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
} }
try { try {
final Relationship relationship = twitter.showFriendship(mUser.key.getId()); final Relationship relationship = twitter.showFriendship(mUser.key.getId());
final UserKey userKey = mUser.key;
if (relationship.isSourceBlockingTarget() || relationship.isSourceBlockedByTarget()) { if (relationship.isSourceBlockingTarget() || relationship.isSourceBlockedByTarget()) {
Utils.setLastSeen(context, userKey, -1); Utils.setLastSeen(context, userKey, -1);
} else { } else {
@ -1793,10 +1805,12 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
boolean can_dm; boolean can_dm;
public UserRelationship(@NonNull UserKey accountKey, @NonNull UserKey userKey, public UserRelationship(@NonNull UserKey accountKey, @NonNull UserKey userKey,
@NonNull Relationship relationship, boolean filtering) { @Nullable Relationship relationship, boolean filtering) {
super(relationship, accountKey, userKey); super(relationship, accountKey, userKey);
this.filtering = filtering; this.filtering = filtering;
this.can_dm = relationship.canSourceDMTarget(); if (relationship != null) {
this.can_dm = relationship.canSourceDMTarget();
}
} }
public UserRelationship(@NonNull ParcelableUser user, boolean filtering) { public UserRelationship(@NonNull ParcelableUser user, boolean filtering) {

View File

@ -1,12 +1,12 @@
package org.mariotaku.twidere.model; package org.mariotaku.twidere.model;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorField;
import org.mariotaku.library.objectcursor.annotation.CursorObject; import org.mariotaku.library.objectcursor.annotation.CursorObject;
import org.mariotaku.twidere.api.twitter.model.Relationship; import org.mariotaku.twidere.api.twitter.model.Relationship;
import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter; import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter;
import org.mariotaku.twidere.provider.TwidereDataProvider;
import org.mariotaku.twidere.provider.TwidereDataStore; import org.mariotaku.twidere.provider.TwidereDataStore;
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships; import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
@ -47,14 +47,16 @@ public class CachedRelationship {
} }
public CachedRelationship(@NonNull Relationship relationship, @NonNull UserKey accountKey, @NonNull UserKey userKey) { public CachedRelationship(@Nullable Relationship relationship, @NonNull UserKey accountKey, @NonNull UserKey userKey) {
account_key = accountKey; account_key = accountKey;
user_key = userKey; user_key = userKey;
following = relationship.isSourceFollowingTarget(); if (relationship != null) {
followed_by = relationship.isSourceFollowedByTarget(); following = relationship.isSourceFollowingTarget();
blocking = relationship.isSourceBlockingTarget(); followed_by = relationship.isSourceFollowedByTarget();
blocked_by = relationship.isSourceBlockedByTarget(); blocking = relationship.isSourceBlockingTarget();
muting = relationship.isSourceMutingTarget(); blocked_by = relationship.isSourceBlockedByTarget();
retweet_enabled = relationship.isSourceWantRetweetsFromTarget(); muting = relationship.isSourceMutingTarget();
retweet_enabled = relationship.isSourceWantRetweetsFromTarget();
}
} }
} }

View File

@ -26,6 +26,7 @@
android:title="@string/set_nickname"/> android:title="@string/set_nickname"/>
<item <item
android:id="@id/add_to_filter" android:id="@id/add_to_filter"
android:checkable="true"
android:icon="@drawable/ic_action_speaker_muted" android:icon="@drawable/ic_action_speaker_muted"
android:title="@string/add_to_filter"/> android:title="@string/add_to_filter"/>
<item <item