@Override
    protected boolean handleResult(
        com.m.ui.fragment.ARefreshFragment.RefreshMode mode, List<StatusComment> datas) {
      // 如果是重置或者刷新数据,加载数据大于分页大小,则清空之前的数据
      if (mode == RefreshMode.refresh)
        // 目前微博加载分页大小是默认大小
        if (datas.size() >= AppSettings.getCommentCount()) {
          setAdapterItems(new ArrayList<StatusComment>());
        }

      return super.handleResult(mode, datas);
    }
    @Override
    protected StatusContents workInBackground(
        RefreshMode mode, String previousPage, String nextPage, Void... p) throws TaskException {
      Params params = new Params();

      if (mode == RefreshMode.refresh && !TextUtils.isEmpty(previousPage))
        params.addParameter("since_id", previousPage);

      if (mode == RefreshMode.update && !TextUtils.isEmpty(nextPage))
        params.addParameter("max_id", nextPage);

      //			params.addParameter("feature", feature);

      // 不管user_id字段传值什么,都返回登录用户的微博
      if (AppContext.getUser().getIdstr().equals(mUser.getIdstr())) {
        params.addParameter("user_id", mUser.getIdstr());
      } else {
        params.addParameter("screen_name", mUser.getScreen_name());
      }

      params.addParameter("count", String.valueOf(AppSettings.getTimelineCount()));

      StatusContents statusContents =
          SinaSDK.getInstance(AppContext.getToken(), getTaskCacheMode(this))
              .statusesUserTimeLine(params);

      if (mNewUser == null
          && (mUser != null && !mUser.getIdstr().equals(AppContext.getUser().getIdstr()))) {
        mNewUser =
            SinaSDK.getInstance(AppContext.getToken()).userShow(null, mUser.getScreen_name());
        mUser = mNewUser;
        if (mNewUser.getStatus() != null) mUser.getStatus().setUser(mNewUser);
        if (mUser.getStatus() != null
            && statusContents != null
            && (statusContents.getStatuses() == null || statusContents.getStatuses().size() == 0)) {
          List<StatusContent> statusList = new ArrayList<StatusContent>();
          statusList.add(mNewUser.getStatus());
          statusContents.setStatuses(statusList);
        }
      }

      if (statusContents != null
          && statusContents.getStatuses() != null
          && statusContents.getStatuses().size() > 0) {
        for (StatusContent status : statusContents.getStatuses()) status.setUser(mUser);
      }

      return statusContents;
    }
    @Override
    protected StatusComments workInBackground(
        RefreshMode mode, String previousPage, String nextPage, Void... params)
        throws TaskException {
      String sinceId = null;
      String maxId = null;
      String filterByAuthor = null;
      if (mode == RefreshMode.refresh && !TextUtils.isEmpty(previousPage)) sinceId = previousPage;
      if (mode == RefreshMode.update && !TextUtils.isEmpty(nextPage)) maxId = nextPage;
      if ("103".equals(mGroupBean.getGroup())) filterByAuthor = "0";
      else filterByAuthor = "1";

      return SinaSDK.getInstance(AppContext.getToken(), getTaskCacheMode(this))
          .commentsMentions(
              sinceId, maxId, filterByAuthor, String.valueOf(AppSettings.getCommentCount()));
    }
Ejemplo n.º 4
0
    @Override
    protected StatusContents workInBackground(
        RefreshMode mode, String previousPage, String nextPage, Void... params)
        throws TaskException {
      Favorities favorities =
          SinaSDK.getInstance(AppContext.getToken(), getTaskCacheMode(this))
              .favorites(nextPage, String.valueOf(AppSettings.getTimelineCount()));

      StatusContents statusContents = new StatusContents(new ArrayList<StatusContent>());
      for (Favority favority : favorities.getFavorites()) {
        statusContents.getStatuses().add(favority.getStatus());
      }
      statusContents.setCache(favorities.isCache());
      statusContents.setExpired(favorities.expired());

      // 如果是重置数据,就判断新加载的数据是否是全部加载完了
      int total = mode == RefreshMode.reset ? 0 : getAdapter().getCount();
      total += favorities.getFavorites().size();
      if (total >= favorities.getTotal_number()) statusContents.setNoMore(true);

      return statusContents;
    }