Example usage for twitter4j Relationship isSourceFollowingTarget

List of usage examples for twitter4j Relationship isSourceFollowingTarget

Introduction

In this page you can find the example usage for twitter4j Relationship isSourceFollowingTarget.

Prototype

boolean isSourceFollowingTarget();

Source Link

Document

Checks if source user is following target user

Usage

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

License:Open Source License

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }/*  w  w w . j a v  a 2 s  . com*/
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
        final ContentResolver cr = getContentResolver();
        if (filtering) {
            final Expression where = Expression.equals(Filters.Users.USER_ID, user.id);
            cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null);
            showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        break;
    }
    case MENU_MUTE_USER: {
        if (mRelationship != null) {
            if (mRelationship.isSourceMutingTarget()) {
                twitter.destroyMuteAsync(user.account_id, user.id);
            } else {
                CreateUserMuteDialogFragment.show(getFragmentManager(), user);
            }
        }
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_FIRETWEET);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    case MENU_OPEN_WITH_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    case R.id.muted_users: {
        openMutesUsers(getActivity(), user.account_id);
        return true;
    }
    case R.id.blocked_users: {
        openUserBlocks(getActivity(), user.account_id);
        return true;
    }
    case R.id.incoming_friendships: {
        openIncomingFriendships(getActivity(), user.account_id);
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

License:Open Source License

@Override
public void onClick(final View view) {
    final FragmentActivity activity = getActivity();
    final ParcelableUser user = getUser();
    if (activity == null || user == null)
        return;/*from  w  w  w  .j  a v  a2 s  .  c  o m*/
    switch (view.getId()) {
    case R.id.retry: {
        getUserInfo(true);
        break;
    }
    case R.id.follow: {
        if (user.id == user.account_id) {
            final Bundle extras = new Bundle();
            extras.putLong(EXTRA_ACCOUNT_ID, user.account_id);
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), UserProfileEditorActivity.class);
            intent.putExtras(extras);
            startActivity(intent);
            break;
        }
        final Relationship relationship = mRelationship;
        final AsyncTwitterWrapper twitter = getTwitterWrapper();
        if (relationship == null || twitter == null)
            return;
        if (relationship.isSourceBlockingTarget()) {
            twitter.destroyBlockAsync(user.account_id, user.id);
        } else if (relationship.isSourceFollowingTarget()) {
            DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
        } else {
            twitter.createFriendshipAsync(user.account_id, user.id);
        }
        break;
    }
    case R.id.profile_image: {
        final String url = getOriginalTwitterProfileImage(user.profile_image_url);
        final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) };
        Utils.openMedia(activity, user.account_id, false, null, media);
        break;
    }
    case R.id.profile_banner: {
        if (user.profile_banner_url == null)
            return;
        final String url = user.profile_banner_url + "/ipad_retina";
        final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) };
        Utils.openMedia(activity, user.account_id, false, null, media);
        break;
    }
    case R.id.listed_container: {
        openUserLists(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.followers_container: {
        openUserFollowers(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.friends_container: {
        openUserFriends(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.name_container: {
        if (user.account_id != user.id)
            return;
        startActivity(new Intent(getActivity(), UserProfileEditorActivity.class));
        break;
    }
    }

}

From source file:org.getlantern.firetweet.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues createCachedRelationship(final Relationship relationship, final long accountId) {
    final ContentValues values = new ContentValues();
    values.put(CachedRelationships.ACCOUNT_ID, accountId);
    values.put(CachedRelationships.USER_ID, relationship.getTargetUserId());
    values.put(CachedRelationships.FOLLOWING, relationship.isSourceFollowingTarget());
    values.put(CachedRelationships.FOLLOWED_BY, relationship.isSourceFollowedByTarget());
    values.put(CachedRelationships.BLOCKING, relationship.isSourceBlockingTarget());
    values.put(CachedRelationships.BLOCKED_BY, relationship.isSourceBlockedByTarget());
    values.put(CachedRelationships.MUTING, relationship.isSourceMutingTarget());
    return values;
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

License:Open Source License

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }/*from   w w  w. j av a 2 s.co m*/
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
        final ContentResolver cr = getContentResolver();
        if (filtering) {
            final Expression where = Expression.equals(Filters.Users.USER_ID, user.id);
            cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null);
            Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        break;
    }
    case MENU_MUTE_USER: {
        if (mRelationship != null) {
            if (mRelationship.isSourceMutingTarget()) {
                twitter.destroyMuteAsync(user.account_id, user.id);
            } else {
                CreateUserMuteDialogFragment.show(getFragmentManager(), user);
            }
        }
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWIDERE);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
        manager.clearUserNickname(user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = mUserColorNameManager.getUserNickname(user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, Utils.getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    case MENU_OPEN_WITH_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    case R.id.muted_users: {
        Utils.openMutesUsers(getActivity(), user.account_id);
        return true;
    }
    case R.id.blocked_users: {
        Utils.openUserBlocks(getActivity(), user.account_id);
        return true;
    }
    case R.id.incoming_friendships: {
        Utils.openIncomingFriendships(getActivity(), user.account_id);
        return true;
    }
    case R.id.user_mentions: {
        Utils.openUserMentions(getActivity(), user.account_id, user.screen_name);
        return true;
    }
    case R.id.saved_searches: {
        Utils.openSavedSearches(getActivity(), user.account_id);
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

License:Open Source License

@Override
public void onClick(final View view) {
    final FragmentActivity activity = getActivity();
    final ParcelableUser user = getUser();
    if (activity == null || user == null)
        return;/*w  w  w. j av  a2s . c  o  m*/
    switch (view.getId()) {
    case R.id.error_container: {
        getUserInfo(true);
        break;
    }
    case R.id.follow: {
        if (user.id == user.account_id) {
            Utils.openProfileEditor(getActivity(), user.account_id);
            break;
        }
        final Relationship relationship = mRelationship;
        final AsyncTwitterWrapper twitter = getTwitterWrapper();
        if (relationship == null || twitter == null)
            return;
        if (relationship.isSourceBlockingTarget()) {
            twitter.destroyBlockAsync(user.account_id, user.id);
        } else if (relationship.isSourceFollowingTarget()) {
            DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
        } else {
            twitter.createFriendshipAsync(user.account_id, user.id);
        }
        break;
    }
    case R.id.profile_image: {
        final String url = Utils.getOriginalTwitterProfileImage(user.profile_image_url);
        final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) };
        //TODO open media animation
        Bundle options = null;
        Utils.openMedia(activity, user.account_id, false, null, media, options);
        break;
    }
    case R.id.profile_banner: {
        if (user.profile_banner_url == null)
            return;
        final String url = user.profile_banner_url + "/ipad_retina";
        final ParcelableMedia[] media = { ParcelableMedia.newImage(url, url) };
        //TODO open media animation
        Bundle options = null;
        Utils.openMedia(activity, user.account_id, false, null, media, options);
        break;
    }
    case R.id.listed_container: {
        Utils.openUserLists(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.followers_container: {
        Utils.openUserFollowers(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.friends_container: {
        Utils.openUserFriends(getActivity(), user.account_id, user.id, user.screen_name);
        break;
    }
    case R.id.name_container: {
        if (user.account_id != user.id)
            return;
        Utils.openProfileEditor(getActivity(), user.account_id);
        break;
    }
    }

}

From source file:twitter4j.examples.friendship.ShowFriendship.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.ShowFriendship  [source screen name] [target screen name]
 *
 * @param args message// ww  w .  jav a 2  s  .co m
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println(
                "Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Relationship relationship = twitter.showFriendship(args[0], args[1]);
        System.out.println("isSourceBlockingTarget: " + relationship.isSourceBlockingTarget());
        System.out.println("isSourceFollowedByTarget: " + relationship.isSourceFollowedByTarget());
        System.out.println("isSourceFollowingByTarget: " + relationship.isSourceFollowingTarget());
        System.out.println("isSourceNotificationsEnabled: " + relationship.isSourceNotificationsEnabled());
        System.out.println("canSourceDm: " + relationship.canSourceDm());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show friendship: " + te.getMessage());
        System.exit(-1);
    }
}