Search in sources :

Example 1 with PostedTweetEvent

use of com.birbit.android.jobqueue.examples.twitter.events.PostedTweetEvent in project android-priority-jobqueue by yigit.

the class PostTweetJob method onRun.

@Override
public void onRun() throws Throwable {
    Status status = TwitterController.getInstance().postTweet(text);
    Tweet newTweet = new Tweet(status);
    TweetModel tweetModel = TweetModel.getInstance();
    Tweet existingTweet = tweetModel.getTweetByLocalId(localId);
    if (existingTweet != null) {
        existingTweet.updateNotNull(newTweet);
        //don't set local to false. this way, next time we ask for history update, we'll send proper tweet id
        tweetModel.insertOrReplace(existingTweet);
    } else {
        //somewhat local tweet does not exist. we might have crashed before onAdded is called.
        //just insert as if it is a new tweet
        tweetModel.insertOrReplace(newTweet);
    }
    EventBus.getDefault().post(new PostedTweetEvent(newTweet, localId));
}
Also used : Status(twitter4j.Status) Tweet(com.birbit.android.jobqueue.examples.twitter.entities.Tweet) PostedTweetEvent(com.birbit.android.jobqueue.examples.twitter.events.PostedTweetEvent) TweetModel(com.birbit.android.jobqueue.examples.twitter.models.TweetModel)

Aggregations

Tweet (com.birbit.android.jobqueue.examples.twitter.entities.Tweet)1 PostedTweetEvent (com.birbit.android.jobqueue.examples.twitter.events.PostedTweetEvent)1 TweetModel (com.birbit.android.jobqueue.examples.twitter.models.TweetModel)1 Status (twitter4j.Status)1