Example usage for twitter4j Twitter destroyBlock

List of usage examples for twitter4j Twitter destroyBlock

Introduction

In this page you can find the example usage for twitter4j Twitter destroyBlock.

Prototype

User destroyBlock(long userId) throws TwitterException;

Source Link

Document

Un-blocks the user specified in the ID parameter as the authenticating user.

Usage

From source file:com.github.moko256.twitlatte.ShowUserActivity.java

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ThrowableFunc throwableFunc = null;/*  ww  w . j  av a  2 s .co  m*/
    @StringRes
    int didAction = -1;
    Twitter twitter = GlobalApplication.twitter;

    switch (item.getItemId()) {
    case R.id.action_share:
        startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND).setType("text/plain")
                .putExtra(Intent.EXTRA_TEXT, getShareUrl()), getString(R.string.share)));
        break;
    case R.id.action_open_in_browser:
        AppCustomTabsKt.launchChromeCustomTabs(this, getShareUrl());
        break;
    case R.id.action_create_follow:
        throwableFunc = () -> twitter.createFriendship(user.getId());
        didAction = R.string.did_follow;
        break;
    case R.id.action_destroy_follow:
        throwableFunc = () -> twitter.destroyFriendship(user.getId());
        didAction = R.string.did_unfollow;
        break;
    case R.id.action_create_mute:
        throwableFunc = () -> twitter.createMute(user.getId());
        didAction = R.string.did_mute;
        break;
    case R.id.action_destroy_mute:
        throwableFunc = () -> twitter.destroyMute(user.getId());
        didAction = R.string.did_unmute;
        break;
    case R.id.action_create_block:
        throwableFunc = () -> twitter.createBlock(user.getId());
        didAction = R.string.did_block;
        break;
    case R.id.action_destroy_block:
        throwableFunc = () -> twitter.destroyBlock(user.getId());
        didAction = R.string.did_unblock;
        break;
    case R.id.action_destroy_follow_follower:
        throwableFunc = () -> {
            twitter.createBlock(user.getId());
            twitter.destroyBlock(user.getId());
        };
        didAction = R.string.did_destroy_ff;
        break;
    case R.id.action_spam_report:
        throwableFunc = () -> GlobalApplication.twitter.reportSpam(user.getId());
        break;
    }

    if (throwableFunc != null && didAction != -1) {
        ThrowableFunc finalThrowableFunc = throwableFunc;
        int finalDidAction = didAction;
        confirmDialog(item.getTitle(), getString(R.string.confirm_message),
                () -> runAsWorkerThread(finalThrowableFunc, finalDidAction));
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.javielinux.utils.UserActions.java

License:Apache License

public static void goToCreateBlock(Context context, InfoUsers infoUsers) {
    ConnectionManager.getInstance().open(context);
    Twitter twitter = ConnectionManager.getInstance()
            .getTwitter(DBUtils.getIdFromUserName(infoUsers.getName()));
    try {//from   w  ww . j ava2 s .  c  o m
        boolean isBlock = false;
        for (long id : twitter.getBlocksIDs().getIDs()) {
            if (id == infoUsers.getId()) {
                isBlock = true;
                break;
            }
        }
        if (true) {
            twitter.destroyBlock(infoUsers.getName());
            Utils.showMessage(context, context.getString(R.string.user_unlock));
        } else {
            twitter.createBlock(infoUsers.getName());
            Utils.showMessage(context, context.getString(R.string.user_block));
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}

From source file:twitter4j.examples.block.DestroyBlock.java

License:Apache License

/**
 * Usage: java twitter4j.examples.block.DestroyBlock [screen name]
 *
 * @param args message//from  w  w w .  j  a  v a 2 s  . com
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.block.DestroyBlock [screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.destroyBlock(args[0]);
        System.out.println("Successfully unblocked user [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to unblock user: " + te.getMessage());
        System.exit(-1);
    }
}