List of usage examples for twitter4j Paging Paging
public Paging()
From source file:org.kie.twitter.TwitterClient.java
License:Apache License
public List<Entry> getEntriesByUser(final String screenName) { try {/*from w ww.j a v a 2 s .c o m*/ return twitter().timelines().getUserTimeline(screenName, new Paging().count(TIMELINE_MAX_VALUE)) .stream().map(Entry::new).collect(Collectors.toList()); } catch (TwitterException e) { e.printStackTrace(); } return new ArrayList<>(); }
From source file:org.luwrain.app.twitter.TwitterApp.java
License:Open Source License
private boolean onShowLikes() { final List<Status> likes; try {/* w w w .j a v a 2 s .c o m*/ likes = (List) base.call(() -> base.getTwitter().getFavorites(new Paging())); } catch (java.util.concurrent.ExecutionException e) { luwrain.crash(e); return true; } final ListArea.Params params = new ListArea.Params(); params.context = new DefaultControlEnvironment(luwrain); params.model = new ListUtils.FixedModel(TweetWrapper.create(likes)) { @Override public void refresh() { final List<Status> l; try { l = (List) base.call(() -> base.getTwitter().getFavorites(new Paging())); } catch (java.util.concurrent.ExecutionException e) { luwrain.crash(e); return; } final List<TweetWrapper> wrappers = new LinkedList<TweetWrapper>(); for (Status s : l) wrappers.add(new TweetWrapper(s)); clear(); addAll(wrappers); } }; params.appearance = new ListUtils.DefaultAppearance(params.context); params.name = "";//FIXME: final ListArea area = new ListArea(params) { @Override public boolean onInputEvent(KeyboardEvent event) { NullCheck.notNull(event, "event"); if (event.isSpecial() && !event.isModified()) switch (event.getSpecial()) { case ESCAPE: layout.closeAdditionalArea(); return true; case TAB: case BACKSPACE: luwrain.setActiveArea(statusArea); return true; } return super.onInputEvent(event); } @Override public boolean onSystemEvent(EnvironmentEvent event) { NullCheck.notNull(event, "event"); if (event.getType() != EnvironmentEvent.Type.REGULAR) return super.onSystemEvent(event); switch (event.getCode()) { case ACTION: if (ActionEvent.isAction(event, "cancel-like")) return actions.onDeleteLike(this); return false; case CLOSE: closeApp(); return true; default: return super.onSystemEvent(event); } } @Override public Action[] getAreaActions() { return ActionLists.getLikesActions(selected()); } }; layout.openAdditionalArea(area, AreaLayoutHelper.Position.BOTTOM); luwrain.setActiveArea(area); return true; }
From source file:org.mariotaku.twidere.loader.support.Twitter4JStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w ww . 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 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 va2s. co 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.Twitter4JActivitiesLoader.java
License:Open Source License
@Override public final List<ParcelableActivity> loadInBackground() { final File serializationFile = getSerializationFile(); if (mIsFirstLoad && mTabPosition >= 0 && serializationFile != null) { final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached != null) { Collections.sort(cached); return new CopyOnWriteArrayList<ParcelableActivity>(cached); }//from w ww . j a v a 2s . c o m } final SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); final List<Activity> activities; try { final Paging paging = new Paging(); paging.setCount(Math.min(100, loadItemLimit)); activities = getActivities(getTwitter(), paging); } catch (final TwitterException e) { e.printStackTrace(); final List<ParcelableActivity> cached = getCachedData(serializationFile); if (cached == null) return Collections.emptyList(); return new CopyOnWriteArrayList<ParcelableActivity>(cached); } if (activities == null) return new CopyOnWriteArrayList<ParcelableActivity>(mData); final List<ParcelableActivity> result = new ArrayList<ParcelableActivity>(); for (final Activity activity : activities) { result.add(new ParcelableActivity(activity, mAccountId, mHiResProfileImage)); } Collections.sort(result); saveCachedData(serializationFile, result); return new CopyOnWriteArrayList<ParcelableActivity>(result); }
From source file:org.mariotaku.twidere.loader.Twitter4JStatusesLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j ava 2 s .co 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/*www . ja v a 2 s. 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.mariotaku.twidere.loader.UserRetweetedStatusLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; if (mStatusId > 0) { final Paging paging = new Paging(); paging.setCount(mLoadItemLimit); if (mPage > 0) { paging.setPage(mPage);/* w w w. j ava 2 s. com*/ } final ResponseList<User> users = twitter.getRetweetedBy(mStatusId, paging); if (users == null) return null; final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); final int users_list_size = mUsersList.size(); final int size = users.size(); for (int i = 0; i < size; i++) { final User user = users.get(i); result.add(new ParcelableUser(user, getAccountId(), users_list_size + i)); } return result; } return null; }
From source file:org.rhq.plugins.twitter.FeedComponent.java
License:Open Source License
/** * Gather measurement data/*from w w w. j av a2 s.co 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); } } }
From source file:org.rhq.plugins.twitter.TwitterComponent.java
License:Open Source License
/** * Gather measurement data//from ww w . j a va 2 s . com * @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 { Twitter twitter = createTwitterInstance(); for (MeasurementScheduleRequest req : metrics) { if (req.getName().equals("tweetCount")) { // Twitter twitter = new Twitter(username,password,serverUrl); Paging paging = new Paging(); if (lastId == NOT_YET_SET) { paging.setSinceId(1); paging.setCount(1); } else { paging.setSinceId(lastId); paging.setCount(100); } List<Status> statuses; statuses = twitter.getHomeTimeline(paging); if (lastId > 0) { MeasurementDataNumeric res; res = new MeasurementDataNumeric(req, (double) statuses.size()); eventPoller.addStatuses(statuses); report.addData(res); } if (statuses.size() > 0) lastId = statuses.get(0).getId(); // This is always newest first } else if (req.getName().equals("followerCount")) { int count = twitter.getFollowersIDs(-1).getIDs().length; MeasurementDataNumeric res; res = new MeasurementDataNumeric(req, (double) count); report.addData(res); } } }