Пример #1
0
  private void setStatuses(TwitterStatuses statuses) {

    if (statuses != null && statuses.getStatusCount() > 0) {
      mConversationStatuses = new TwitterStatuses();

      for (int i = 0; i < statuses.getStatusCount(); i++) {
        TwitterStatus status = statuses.getStatus(i);
        if (status.mId != mTwitterStatus.mId) {
          mConversationStatuses.add(new TwitterStatus(status));
        }
      }

      if (mConversationStatuses.getStatusCount() == 0) {
        mConversationStatuses = null;
      }
    }
  }
Пример #2
0
  private void updateViewVisibility(boolean loadHasFinished) {

    if (loadHasFinished == false
        && (mConversationStatuses == null || mConversationStatuses.getStatusCount() == 0)) {
      mLoadingView.setVisibility(View.VISIBLE);
    } else {
      mLoadingView.setVisibility(View.GONE);

      mConversationView.removeAllViews();

      if (mConversationStatuses == null || mConversationStatuses.getStatusCount() == 0) {
        View view = getLoadMoreView();
        mConversationView.addView(view);
      } else {
        for (int i = 0; i < mConversationStatuses.getStatusCount(); ++i) {
          View view = getTweetFeedView(i, mConversationStatuses.getStatus(i));
          mConversationView.addView(view);
        }
      }
    }
  }
Пример #3
0
  public void configure(TwitterStatus twitterStatus, LayoutInflater inflater, Callbacks callbacks) {

    mTwitterStatus = twitterStatus;
    mInflater = inflater;
    mCallbacks = callbacks;

    mLoadingView = (RelativeLayout) findViewById(R.id.conversation_feed_loading);
    mConversationView = (LinearLayout) findViewById(R.id.conversation_feed_loaded);

    TwitterContentHandleBase base =
        new TwitterContentHandleBase(
            TwitterConstant.ContentType.STATUSES,
            TwitterConstant.StatusesType.PREVIOUS_CONVERSATION);
    mContentHandle =
        new TwitterContentHandle(
            base, twitterStatus.mUserScreenName, Long.valueOf(mTwitterStatus.mId).toString());

    TwitterStatuses cachedStatuses = TwitterManager.get().getContentFeed(mContentHandle);
    if (cachedStatuses != null && cachedStatuses.getStatusCount() > 0) {
      setStatuses(cachedStatuses);
      updateViewVisibility(true);
    } else {
      TwitterManager.get()
          .triggerFetchStatuses(
              mContentHandle,
              null,
              new TwitterFetchStatusesFinishedCallback() {

                @Override
                public void finished(TwitterFetchResult result, TwitterStatuses feed) {
                  if (result.isSuccessful()) {
                    setStatuses(feed);
                  }
                  updateViewVisibility(true);
                }
              },
              1);
    }
  }
    @Override
    protected ModifyStatusesTaskOutput doInBackground(ModifyStatusesTaskInput... inputArray) {

      TwitterStatuses contentFeed = new TwitterStatuses();
      ModifyStatusesTaskInput input = inputArray[0];
      Twitter twitter = getTwitterInstance();
      String errorDescription = null;

      AppdotnetApi appdotnetApi = getAppdotnetApi();
      if (appdotnetApi != null) {
        switch (input.mStatusesType) {
          case DELETE:
            {
              if (input.mStatuses != null) {
                for (int i = 0; i < input.mStatuses.getStatusCount(); i++) {
                  TwitterStatus twitterStatus = input.mStatuses.getStatus(i);
                  AdnPost post = appdotnetApi.deleteTweet(twitterStatus.mId);
                  if (post == null) {
                    errorDescription = "Unable to delete status";
                  }
                }
              }
              break;
            }

          case SET_FAVORITE:
            {
              boolean favorite = input.mValue == 1;

              if (input.mStatuses != null) {
                for (int i = 0; i < input.mStatuses.getStatusCount(); i++) {
                  TwitterStatus twitterStatus = input.mStatuses.getStatus(i);
                  if (twitterStatus.mIsFavorited != favorite) {
                    AdnPost post = appdotnetApi.setAdnFavorite(twitterStatus.mId, favorite);

                    if (post != null) {
                      twitterStatus = new TwitterStatus(post);
                      twitterStatus.setFavorite(favorite);
                      contentFeed.add(twitterStatus);
                    }
                  }
                }
              }
              break;
            }
        }
      } else if (twitter != null) {

        try {
          switch (input.mStatusesType) {
            case DELETE:
              {
                if (input.mStatuses != null) {
                  for (int i = 0; i < input.mStatuses.getStatusCount(); i++) {
                    TwitterStatus twitterStatus = input.mStatuses.getStatus(i);
                    twitter.destroyStatus(twitterStatus.mId);
                  }
                }
                break;
              }

            case SET_FAVORITE:
              {
                boolean favorite = input.mValue == 1;

                if (input.mStatuses != null) {
                  for (int i = 0; i < input.mStatuses.getStatusCount(); i++) {
                    TwitterStatus twitterStatus = input.mStatuses.getStatus(i);
                    if (twitterStatus.mIsFavorited != favorite) {
                      try {
                        twitter4j.Status status;
                        if (favorite) {
                          status = twitter.createFavorite(twitterStatus.mId);
                        } else {
                          status = twitter.destroyFavorite(twitterStatus.mId);
                        }

                        // Yuck: See the comment for
                        // TwitterStatus.setFavorite() for
                        // reasons for this
                        twitterStatus = new TwitterStatus(status);
                        twitterStatus.setFavorite(favorite);

                        contentFeed.add(twitterStatus);
                      } catch (TwitterException e) {
                        // we might get errors setting the favorite
                        // state to the same
                        // value again.
                        // Just ignore those ones...
                      }
                    }
                  }
                }

                break;
              }
          }
        } catch (TwitterException e) {
          e.printStackTrace();
          errorDescription = e.getErrorMessage();
          Log.e("api-call", errorDescription, e);
          if (e.getRateLimitStatus() != null && e.getRateLimitStatus().getRemaining() <= 0) {
            errorDescription +=
                "\nTry again in " + e.getRateLimitStatus().getSecondsUntilReset() + " " + "seconds";
          }
        }
      }

      return new ModifyStatusesTaskOutput(
          new TwitterFetchResult(errorDescription == null, errorDescription),
          input.mCallbackHandle,
          contentFeed,
          null);
    }