com.ahuralab.mozaic.ReTweetTask.java Source code

Java tutorial

Introduction

Here is the source code for com.ahuralab.mozaic.ReTweetTask.java

Source

/* 
 Copyright (c) 2013, Panteha Saeedi All rights reserved.
     
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package com.ahuralab.mozaic;

import twitter4j.Twitter;
import twitter4j.TwitterException;

import com.ahuralab.mozaic.app.TwitterClient;
import com.ahuralab.mozaic.auth.TwitterAuthenticator;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

/**
 * @author pani
 *
 */
public class ReTweetTask extends AsyncTask<Void, Void, Boolean> {

    private final Context context;
    private final long tweetId;

    public ReTweetTask(Context context, long tweetId) {
        this.context = context;
        this.tweetId = tweetId;
    }

    @Override
    protected Boolean doInBackground(Void... params) {

        // TODO use global authenticator
        TwitterAuthenticator auth = new TwitterAuthenticator();
        Twitter twitter = auth.createTwitter(context);

        TwitterClient client = new TwitterClient(twitter);
        try {
            client.reTweet(tweetId);
        } catch (TwitterException e) {
            Log.e(TimelineActivity.TAG, "" + e.getMessage(), e);
            return false;
        }
        return true;
    }

}