Example usage for twitter4j Paging setMaxId

List of usage examples for twitter4j Paging setMaxId

Introduction

In this page you can find the example usage for twitter4j Paging setMaxId.

Prototype

public void setMaxId(long maxId) 

Source Link

Usage

From source file:it.greenvulcano.gvesb.social.twitter.directcall.TwitterOperationGetUserTimeline.java

License:Open Source License

@Override
public void execute(SocialAdapterAccount account) throws SocialAdapterException {
    try {//w w w. j  a  va2 s.com
        Twitter twitter = (Twitter) account.getProxyObject();
        Paging paging = new Paging();
        if ((sinceId != null) && !"".equals(sinceId)) {
            paging.setSinceId(Long.parseLong(sinceId));
        }
        if ((maxId != null) && !"".equals(maxId)) {
            paging.setMaxId(Long.parseLong(maxId));
        }
        if ((count != null) && !"".equals(count)) {
            paging.setCount(Integer.parseInt(count));
        }
        if ((userId == null) || "".equals(userId)) {
            dataUser = twitter.getScreenName();
            dataUserId = String.valueOf(twitter.getId());
            statusList = twitter.getUserTimeline(paging);
        } else {
            User user = null;
            try {
                long id = Long.parseLong(userId);
                user = twitter.showUser(id);
                statusList = twitter.getUserTimeline(id, paging);
            } catch (NumberFormatException exc) {
                user = twitter.showUser(userId);
                statusList = twitter.getUserTimeline(userId, paging);
            }
            dataUser = user.getScreenName();
            dataUserId = String.valueOf(user.getId());
        }
    } catch (NumberFormatException exc) {
        logger.error("Call to TwitterOperationGetUserTimeline failed. Check userId[" + userId + "], sinceId["
                + sinceId + "], maxId[" + maxId + "] and count[" + count + "] format.", exc);
        throw new SocialAdapterException("Call to TwitterOperationGetUserTimeline failed. Check followingId["
                + userId + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] format.",
                exc);
    } catch (TwitterException exc) {
        logger.error("Call to TwitterOperationGetUserTimeline followingId[" + userId + "], sinceId[" + sinceId
                + "], maxId[" + maxId + "] and count[" + count + "] failed.", exc);
        throw new SocialAdapterException("Call to TwitterOperationGetUserTimeline followingId[" + userId
                + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] failed.", exc);
    }
}

From source file:jp.gihyo.wicket.page.ajax.AjaxTimeline.java

License:Apache License

protected Status getCurrentStatus(long statusId) throws TwitterException {
    Twitter twitterSession = AppSession.get().getTwitterSession();
    Paging paging = new Paging(1, 1);
    paging.setMaxId(statusId);
    List<Status> statusList = twitterSession.getFriendsTimeline(paging);
    return statusList.size() > 0 ? statusList.get(0) : null;
}

From source file:net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment.java

License:Open Source License

@Override
public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
    final MainActivity activity = (MainActivity) getActivity();
    final Account currentAccount = activity.getCurrentAccount();
    Twitter twitter = TwitterApi.getTwitter(currentAccount);
    final StatusListAdapter adapter = getListAdapter(activity);
    Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity));
    if (adapter.getCount() > 0) {
        paging.setMaxId(adapter.getLastID() - 1);
    }/*from w  ww  .  ja v a2s .  c  o  m*/
    new UserTimelineTask(twitter, getUserID(), paging) {
        @Override
        protected void onPostExecute(twitter4j.Status[] statuses) {
            super.onPostExecute(statuses);
            for (twitter4j.Status status : statuses) {
                adapter.addToBottom(new StatusViewModel(status, currentAccount));
            }
            updateListView(refreshView.getRefreshableView(), adapter, false);
            refreshView.onRefreshComplete();
        }
    }.execute();
}

From source file:net.lacolaco.smileessence.view.HomeFragment.java

License:Open Source License

@Override
public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
    final MainActivity activity = (MainActivity) getActivity();
    final Account currentAccount = activity.getCurrentAccount();
    Twitter twitter = TwitterApi.getTwitter(currentAccount);
    final StatusListAdapter adapter = getListAdapter(activity);
    Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity));
    if (adapter.getCount() > 0) {
        paging.setMaxId(adapter.getLastID() - 1);
    }//w  w w .  java 2s  .  c om
    new HomeTimelineTask(twitter, activity, paging) {
        @Override
        protected void onPostExecute(twitter4j.Status[] statuses) {
            super.onPostExecute(statuses);
            for (twitter4j.Status status : statuses) {
                StatusViewModel viewModel = new StatusViewModel(status, currentAccount);
                adapter.addToBottom(viewModel);
                StatusFilter.filter(activity, viewModel);
            }
            updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false);
            refreshView.onRefreshComplete();
        }
    }.execute();
}

From source file:net.lacolaco.smileessence.view.MentionsFragment.java

License:Open Source License

@Override
public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
    final MainActivity activity = (MainActivity) getActivity();
    final Account currentAccount = activity.getCurrentAccount();
    Twitter twitter = TwitterApi.getTwitter(currentAccount);
    final StatusListAdapter adapter = getListAdapter(activity);
    Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity));
    if (adapter.getCount() > 0) {
        paging.setMaxId(adapter.getLastID() - 1);
    }//from w ww. j a v  a  2  s . c o m
    new MentionsTimelineTask(twitter, activity, paging) {
        @Override
        protected void onPostExecute(twitter4j.Status[] statuses) {
            super.onPostExecute(statuses);
            for (twitter4j.Status status : statuses) {
                adapter.addToBottom(new StatusViewModel(status, currentAccount));
            }
            updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false);
            refreshView.onRefreshComplete();
        }
    }.execute();
}

From source file:net.lacolaco.smileessence.view.MessagesFragment.java

License:Open Source License

@Override
public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
    final MainActivity activity = (MainActivity) getActivity();
    final Account currentAccount = activity.getCurrentAccount();
    Twitter twitter = TwitterApi.getTwitter(currentAccount);
    final MessageListAdapter adapter = getListAdapter(activity);
    Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity));
    if (adapter.getCount() > 0) {
        paging.setMaxId(adapter.getLastID() - 1);
    }//  w  ww .jav  a2  s .  c o  m
    new DirectMessagesTask(twitter, activity, paging) {
        @Override
        protected void onPostExecute(DirectMessage[] directMessages) {
            super.onPostExecute(directMessages);
            for (DirectMessage directMessage : directMessages) {
                adapter.addToBottom(new MessageViewModel(directMessage, currentAccount));
            }
            updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false);
            refreshView.onRefreshComplete();
        }
    }.execute();
}

From source file:net.lacolaco.smileessence.view.UserListFragment.java

License:Open Source License

@Override
public void onPullUpToRefresh(final PullToRefreshBase<ListView> refreshView) {
    final MainActivity activity = getMainActivity();
    final Account currentAccount = activity.getCurrentAccount();
    Twitter twitter = TwitterApi.getTwitter(currentAccount);
    final UserListListAdapter adapter = getListAdapter(activity);
    String listFullName = adapter.getListFullName();
    if (TextUtils.isEmpty(listFullName)) {
        new UIHandler() {
            @Override//w  ww.j  a  va2  s. co  m
            public void run() {
                notifyTextEmpty(activity);
                refreshView.onRefreshComplete();
            }
        }.post();
        return;
    }
    Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity));
    if (adapter.getCount() > 0) {
        paging.setMaxId(adapter.getLastID() - 1);
    }
    new UserListStatusesTask(twitter, listFullName, activity, paging) {
        @Override
        protected void onPostExecute(twitter4j.Status[] statuses) {
            super.onPostExecute(statuses);
            for (int i = 0; i < statuses.length; i++) {
                twitter4j.Status status = statuses[i];
                StatusViewModel statusViewModel = new StatusViewModel(status, activity.getCurrentAccount());
                adapter.addToBottom(statusViewModel);
                StatusFilter.filter(activity, statusViewModel);
            }
            updateListViewWithNotice(refreshView.getRefreshableView(), adapter, false);
            refreshView.onRefreshComplete();
        }
    }.execute();
}

From source file:org.apache.nutch.protocol.http.api.HttpBase.java

License:Apache License

private HttpResponse getTwitterResponse(String url)
        throws MalformedURLException, TwitterException, UnsupportedEncodingException, CharacterCodingException {
    url = URLDecoder.decode(url, "UTF-8");
    Map<String, String> map = getQueryParams(url);
    String consumerKey = map.get("consumer_key");
    String consumerSecret = map.get("consumer_secret");
    String accessToken = map.get("oauth_key");
    String accessTokenSecret = map.get("oauth_secret");

    Twitter twitter = getTwitterInstance(consumerKey, consumerSecret, accessToken, accessTokenSecret);
    Paging paging = new Paging();
    paging.setCount(10);/*from  w w w. j a v a  2 s . co  m*/
    twitter4j.internal.http.HttpResponse twitterResponse;
    String result = null;
    if (!(url.indexOf("statuses/show.json") >= 0)) {
        String max_id = map.get("max_id");
        if (null != max_id)
            paging.setMaxId(Long.parseLong(max_id));
        ResponseList<Status> homeTimeline = twitter.getUserTimeline(paging);
        twitterResponse = homeTimeline.getResponse();
        result = twitterResponse.asJSONArray().toString();
    } else {
        String id = map.get("id");
        Long statusId = Long.parseLong(id);
        Status status = twitter.showStatus(statusId);
        twitterResponse = status.getResponse();
        result = twitterResponse.asJSONObject().toString();
    }

    u = new URL(twitterResponse.getRequestURL());
    code = twitterResponse.getStatusCode();
    ByteBuffer buffer = toByteBUffer(result);
    contents = buffer.array();
    contentType = "text/javascript";

    headers = new SpellCheckedMetadata();
    Map<String, List<String>> responseHeaders = twitterResponse.getResponseHeaderFields();
    for (String key : responseHeaders.keySet()) {
        List<String> values = responseHeaders.get(key);
        for (String value : values) {
            if (null == key)
                continue;
            if (null == value)
                continue;
            headers.add(key, value);
        }
    }
    return null;
}

From source file:org.getlantern.firetweet.loader.support.Twitter4JActivitiesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   ww  w .  j  av a2 s  . c  o m*/
public final List<ParcelableActivity> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableActivity> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableActivity> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            if (mComparator != null) {
                Collections.sort(data, mComparator);
            } else {
                Collections.sort(data);
            }
            return new CopyOnWriteArrayList<>(data);
        }
    }
    final List<Activity> activities;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId);
        }
        activities = new ArrayList<>();
        truncated = truncateActivities(getActivities(getTwitter(), paging), activities, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        e.printStackTrace();
        return new CopyOnWriteArrayList<>(data);
    }
    final Pair<Long, Long> minId;
    if (activities.isEmpty()) {
        minId = new Pair<>(-1L, -1L);
    } else {
        final Activity minActivity = Collections.min(activities);
        minId = new Pair<>(minActivity.getMinPosition(), minActivity.getMaxPosition());
    }
    final boolean insertGap = minId.first > 0 && minId.second > 0 && activities.size() > 1 && !data.isEmpty()
            && !truncated;
    //        mHandler.post(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountIds, activities)));
    for (final Activity activity : activities) {
        final long min = activity.getMinPosition(), max = activity.getMaxPosition();
        final boolean deleted = deleteStatus(data, max);
        final boolean isGap = minId.first == min && minId.second == max && insertGap && !deleted;
        data.add(new ParcelableActivity(activity, mAccountIds, isGap));
    }
    //        final ParcelableActivity[] array = data.toArray(new ParcelableActivity[data.size()]);
    //        for (int i = 0, size = array.length; i < size; i++) {
    //            final ParcelableActivity status = array[i];
    //            if (shouldFilterActivity(mDatabase, status) && !status.is_gap && i != size - 1) {
    //                deleteStatus(data, status.max_position);
    //            }
    //        }
    if (mComparator != null) {
        Collections.sort(data, mComparator);
    } else {
        Collections.sort(data);
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<>(data);
}

From source file:org.getlantern.firetweet.loader.support.TwitterAPIStatusesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w ww. j av a2  s . c o  m*/
public final List<ParcelableStatus> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableStatus> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableStatus> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            if (mComparator != null) {
                Collections.sort(data, mComparator);
            } else {
                Collections.sort(data);
            }
            return new CopyOnWriteArrayList<>(data);
        }
    }
    if (!isFromUser())
        return data;
    final List<Status> statuses;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId - 1);
        }
        statuses = new ArrayList<>();
        final Twitter twitter = getTwitter();
        if (twitter == null) {
            throw new TwitterException("Account is null");
        }
        truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        Log.w(LOGTAG, e);
        return new CopyOnWriteArrayList<>(data);
    }
    final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId();
    final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated;
    for (final Status status : statuses) {
        final long id = status.getId();
        final boolean deleted = deleteStatus(data, id);
        data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted));
    }
    final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
    for (int i = 0, size = array.length; i < size; i++) {
        final ParcelableStatus status = array[i];
        if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) {
            deleteStatus(data, status.id);
        }
    }
    if (mComparator != null) {
        Collections.sort(data, mComparator);
    } else {
        Collections.sort(data);
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<>(data);
}