List of usage examples for twitter4j Paging setSinceId
public void setSinceId(long sinceId)
From source file:net.lacolaco.smileessence.view.MessagesFragment.java
License:Open Source License
@Override public void onPullDownToRefresh(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.setSinceId(adapter.getTopID()); }/* www. j a v a 2s . c o m*/ new DirectMessagesTask(twitter, activity, paging) { @Override protected void onPostExecute(DirectMessage[] directMessages) { super.onPostExecute(directMessages); for (int i = directMessages.length - 1; i >= 0; i--) { adapter.addToTop(new MessageViewModel(directMessages[i], currentAccount)); } updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); refreshView.onRefreshComplete(); } }.execute(); }
From source file:net.lacolaco.smileessence.view.UserListFragment.java
License:Open Source License
@Override public void onPullDownToRefresh(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 w w . j a v a 2 s . c o m*/ public void run() { notifyTextEmpty(activity); refreshView.onRefreshComplete(); } }.post(); return; } Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); if (adapter.getCount() > 0) { paging.setSinceId(adapter.getTopID()); } new UserListStatusesTask(twitter, listFullName, activity, paging) { @Override protected void onPostExecute(twitter4j.Status[] statuses) { super.onPostExecute(statuses); for (int i = statuses.length - 1; i >= 0; i--) { twitter4j.Status status = statuses[i]; StatusViewModel statusViewModel = new StatusViewModel(status, activity.getCurrentAccount()); adapter.addToTop(statusViewModel); StatusFilter.filter(activity, statusViewModel); } updateListViewWithNotice(refreshView.getRefreshableView(), adapter, true); refreshView.onRefreshComplete(); } }.execute(); }
From source file:org.getlantern.firetweet.loader.support.Twitter4JActivitiesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from www .j ava 2s .com*/ 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/*w w w . ja v a 2s . com*/ 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); }
From source file:org.mariotaku.twidere.loader.support.Twitter4JStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w. j a va2 s . com*/ 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; mHandler.post(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses))); 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); }
From source file:org.mariotaku.twidere.loader.support.TwitterAPIStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 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 Twitter twitter = getTwitter(); if (twitter == null) return null; 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); final boolean noItemsBefore = data == null || data.isEmpty(); 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<>(); 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[] statusIds = new long[statuses.size()]; long minId = -1; int minIdx = -1; int rowsDeleted = 0; for (int i = 0, j = statuses.size(); i < j; i++) { final twitter4j.Status status = statuses.get(i); final long id = status.getId(); if (minId == -1 || id < minId) { minId = id; minIdx = i; } statusIds[i] = id; if (deleteStatus(data, status.getId())) { rowsDeleted++; } } // Insert a gap. final boolean deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, mMaxId); final boolean noRowsDeleted = rowsDeleted == 0; final boolean insertGap = minId > 0 && (noRowsDeleted || deletedOldGap) && !truncated && !noItemsBefore && statuses.size() > 1; for (int i = 0, j = statuses.size(); i < j; i++) { final Status status = statuses.get(i); data.add(new ParcelableStatus(status, mAccountId, insertGap && isGapEnabled() && minIdx == i)); } 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); }
From source file:org.mariotaku.twidere.loader.Twitter4JStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* ww w .ja v a 2s .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); Collections.sort(data); return new CopyOnWriteArrayList<ParcelableStatus>(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<Status>(); truncated = truncateStatuses(getStatuses(getTwitter(), paging), statuses, mSinceId); } catch (final TwitterException e) { // mHandler.post(new ShowErrorRunnable(e)); e.printStackTrace(); return new CopyOnWriteArrayList<ParcelableStatus>(data); } final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId(); final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated; mHandler.post(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses))); 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, mHiResProfileImage)); } Collections.sort(data); 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); } } saveCachedData(serializationFile, data); return new CopyOnWriteArrayList<ParcelableStatus>(data); }
From source file:org.mariotaku.twidere.loader.Twitter4JStatusLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//w ww .ja va 2s . co m public SynchronizedStateSavedList<ParcelableStatus, Long> loadInBackground() { final SynchronizedStateSavedList<ParcelableStatus, Long> data = getData(); List<Status> statuses = null; final Context context = getContext(); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int load_item_limit = prefs.getInt(PREFERENCE_KEY_LOAD_ITEM_LIMIT, PREFERENCE_DEFAULT_LOAD_ITEM_LIMIT); try { final Paging paging = new Paging(); paging.setCount(load_item_limit); if (mMaxId > 0) { paging.setMaxId(mMaxId); } if (mSinceId > 0) { paging.setSinceId(mSinceId); } statuses = getStatuses(paging); } catch (final TwitterException e) { e.printStackTrace(); } if (statuses != null) { final boolean insert_gap = load_item_limit == statuses.size() && data.size() > 0; final Status min_status = statuses.size() > 0 ? Collections.min(statuses) : null; final long min_status_id = min_status != null ? min_status.getId() : -1; if (context instanceof Activity) { ((Activity) context).runOnUiThread( CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses))); } for (final Status status : statuses) { final long id = status.getId(); deleteStatus(id); data.add(new ParcelableStatus(status, mAccountId, min_status_id > 0 && min_status_id == id && insert_gap, mHiResProfileImage, mLargeInlineImagePreview)); } } try { final List<ParcelableStatus> statuses_to_remove = new ArrayList<ParcelableStatus>(); for (final ParcelableStatus status : data) { if (isFiltered(mDatabase, status) && !status.is_gap) { statuses_to_remove.add(status); } } data.removeAll(statuses_to_remove); Collections.sort(data); } catch (final ConcurrentModificationException e) { Log.w(LOGTAG, e); } return data; }
From source file:org.mule.twitter.TwitterConnector.java
License:Open Source License
protected Paging getPaging(int page, int count, long sinceId) { Paging paging = new Paging(page, count); if (sinceId > 0) { paging.setSinceId(sinceId); }/*from ww w . j a va2s. c o m*/ return paging; }
From source file:org.rhq.plugins.twitter.FeedComponent.java
License:Open Source License
/** * Gather measurement data/*from w w w.j a v a 2 s .c o m*/ * @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set) */ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { for (MeasurementScheduleRequest req : metrics) { if (req.getName().equals("tweetCount")) { Twitter twitter = tFactory.getInstance(); Paging paging = new Paging(); MeasurementDataNumeric res; if (isSearch) { Query q = new Query(keyword); q.setSinceId(lastId); if (lastId == NOT_YET_SET) q.setRpp(1); else q.setRpp(20); QueryResult qr = twitter.search(q); List<Tweet> tweets = qr.getTweets(); res = new MeasurementDataNumeric(req, (double) tweets.size()); eventPoller.addTweets(tweets); if (tweets.size() > 0) lastId = tweets.get(0).getId(); } else { List<Status> statuses; if (lastId == NOT_YET_SET) { paging.setCount(1); } else { paging.setCount(100); } paging.setSinceId(lastId); statuses = twitter.getUserTimeline(keyword, paging); res = new MeasurementDataNumeric(req, (double) statuses.size()); eventPoller.addStatuses(statuses); if (statuses.size() > 0) lastId = statuses.get(0).getId(); } report.addData(res); } } }