Пример #1
0
 @Override
 protected List<TwitterWrapper.StatusListResponse> doInBackground(final Object... params) {
   final List<TwitterWrapper.StatusListResponse> result = new ArrayList<>();
   if (accountIds == null) return result;
   int idx = 0;
   final SharedPreferencesWrapper preferences = twitterWrapper.getPreferences();
   final Context context = twitterWrapper.getContext();
   final ErrorInfoStore errorInfoStore = twitterWrapper.getErrorInfoStore();
   final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
   for (final long accountId : accountIds) {
     final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountId, true);
     if (twitter == null) continue;
     try {
       final Paging paging = new Paging();
       paging.count(loadItemLimit);
       final long maxId, sinceId;
       if (maxIds != null && maxIds[idx] > 0) {
         maxId = maxIds[idx];
         paging.maxId(maxId);
       } else {
         maxId = -1;
       }
       if (sinceIds != null && sinceIds[idx] > 0) {
         sinceId = sinceIds[idx];
         paging.sinceId(sinceId - 1);
         if (maxIds == null || sinceIds[idx] <= 0) {
           paging.setLatestResults(true);
         }
       } else {
         sinceId = -1;
       }
       final List<org.mariotaku.twidere.api.twitter.model.Status> statuses =
           getStatuses(twitter, paging);
       TwitterContentUtils.getStatusesWithQuoteData(twitter, statuses);
       storeStatus(accountId, statuses, sinceId, maxId, true, loadItemLimit);
       publishProgress(new TwitterWrapper.StatusListResponse(accountId, statuses));
       errorInfoStore.remove(getErrorInfoKey(), accountId);
     } catch (final TwitterException e) {
       if (BuildConfig.DEBUG) {
         Log.w(LOGTAG, e);
       }
       if (e.isCausedByNetworkIssue()) {
         errorInfoStore.put(getErrorInfoKey(), accountId, ErrorInfoStore.CODE_NETWORK_ERROR);
       }
       result.add(new TwitterWrapper.StatusListResponse(accountId, e));
     }
     idx++;
   }
   return result;
 }
 private static void parseEntities(final HtmlBuilder builder, final EntitySupport entities) {
   // Format media.
   final MediaEntity[] mediaEntities = entities.getMediaEntities();
   if (mediaEntities != null) {
     for (final MediaEntity mediaEntity : mediaEntities) {
       final int start = mediaEntity.getStart(), end = mediaEntity.getEnd();
       final String mediaUrl = TwitterContentUtils.getMediaUrl(mediaEntity);
       if (mediaUrl != null && start >= 0 && end >= 0) {
         builder.addLink(mediaUrl, mediaEntity.getDisplayUrl(), start, end);
       }
     }
   }
   final UrlEntity[] urlEntities = entities.getUrlEntities();
   if (urlEntities != null) {
     for (final UrlEntity urlEntity : urlEntities) {
       final int start = urlEntity.getStart(), end = urlEntity.getEnd();
       final String expandedUrl = urlEntity.getExpandedUrl();
       if (expandedUrl != null && start >= 0 && end >= 0) {
         builder.addLink(expandedUrl, urlEntity.getDisplayUrl(), start, end);
       }
     }
   }
 }
 public static String formatStatusText(final Status status) {
   if (status == null) return null;
   final HtmlBuilder builder = new HtmlBuilder(status.getText(), false, true, true);
   TwitterContentUtils.parseEntities(builder, status);
   return builder.build();
 }
 public static String formatDirectMessageText(final DirectMessage message) {
   if (message == null) return null;
   final HtmlBuilder builder = new HtmlBuilder(message.getText(), false, true, true);
   TwitterContentUtils.parseEntities(builder, message);
   return builder.build();
 }
Пример #5
0
  public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) {
    this.is_gap = is_gap;
    this.account_id = account_id;
    id = orig.getId();
    timestamp = getTime(orig.getCreatedAt());

    final Status retweeted = orig.getRetweetedStatus();
    final User retweet_user = retweeted != null ? orig.getUser() : null;
    is_retweet = orig.isRetweet();
    retweet_id = retweeted != null ? retweeted.getId() : -1;
    retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1;
    retweeted_by_user_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_user_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_user_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    retweeted_by_user_profile_image = TwitterContentUtils.getProfileImageUrl(retweet_user);

    final Status quoted = orig.getQuotedStatus();
    final User quote_user = quoted != null ? orig.getUser() : null;
    is_quote = orig.isQuote();
    quote_id = quoted != null ? quoted.getId() : -1;
    quote_text_html = TwitterContentUtils.formatStatusText(orig);
    quote_text_plain = TwitterContentUtils.unescapeTwitterStatusText(orig.getText());
    quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html);
    quote_timestamp = orig.getCreatedAt().getTime();
    quote_source = orig.getSource();
    quote_retweet_count = orig.getRetweetCount();
    quote_favorite_count = orig.getFavoriteCount();
    quote_reply_count = orig.getReplyCount();

    quoted_by_user_id = quote_user != null ? quote_user.getId() : -1;
    quoted_by_user_name = quote_user != null ? quote_user.getName() : null;
    quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null;
    quoted_by_user_profile_image = TwitterContentUtils.getProfileImageUrl(quote_user);
    quoted_by_user_is_protected = quote_user != null && quote_user.isProtected();
    quoted_by_user_is_verified = quote_user != null && quote_user.isVerified();

    final Status status;
    if (quoted != null) {
      status = quoted;
    } else if (retweeted != null) {
      status = retweeted;
    } else {
      status = orig;
    }
    final User user = status.getUser();
    user_id = user.getId();
    user_name = user.getName();
    user_screen_name = user.getScreenName();
    user_profile_image_url = TwitterContentUtils.getProfileImageUrl(user);
    user_is_protected = user.isProtected();
    user_is_verified = user.isVerified();
    user_is_following = user.isFollowing();
    text_html = TwitterContentUtils.formatStatusText(status);
    media = ParcelableMedia.fromStatus(status);
    quote_media = quoted != null ? ParcelableMedia.fromStatus(orig) : null;
    text_plain = TwitterContentUtils.unescapeTwitterStatusText(status.getText());
    retweet_count = status.getRetweetCount();
    favorite_count = status.getFavoriteCount();
    reply_count = status.getReplyCount();
    in_reply_to_name = TwitterContentUtils.getInReplyToName(retweeted != null ? retweeted : orig);
    in_reply_to_screen_name = (retweeted != null ? retweeted : orig).getInReplyToScreenName();
    in_reply_to_status_id = (retweeted != null ? retweeted : orig).getInReplyToStatusId();
    in_reply_to_user_id = (retweeted != null ? retweeted : orig).getInReplyToUserId();
    source = status.getSource();
    location = ParcelableLocation.fromGeoLocation(status.getGeoLocation());
    is_favorite = status.isFavorited();
    text_unescaped = HtmlEscapeHelper.toPlainText(text_html);
    my_retweet_id = retweeted_by_user_id == account_id ? id : status.getCurrentUserRetweet();
    is_possibly_sensitive = status.isPossiblySensitive();
    mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities());
    card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id);
    place_full_name = getPlaceFullName(status.getPlace());
    card_name = card != null ? card.name : null;
  }