@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
    public Boolean workInBackground(boolean[]... params) throws TaskException {
      final boolean[] checkedItems = params[0];
      final boolean[] editCheckedItems = params[1];
      mGroupMemberListed = new GroupMemberListed();
      mGroupMemberListed.setLists(new ArrayList<GroupListed>());
      for (int i = 0; i < editCheckedItems.length; i++) {
        Group group = AppContext.getGroups().getLists().get(i);
        GroupListed groupListed = new GroupListed();
        groupListed.setIdstr(group.getIdstr());
        groupListed.setName(group.getName());

        // 这个分组没有选中
        if (editCheckedItems[i]) {
          // 如果这个分组原来也是选中的,则不需要编辑
          if (checkedItems[i]) {
            mGroupMemberListed.getLists().add(groupListed);
          }
          // 如果这个分组原来没有选中,则添加
          else {
            // 添加好友到分组
            SinaSDK.getInstance(AppContext.getToken())
                .friendshipsGroupdMembersAdd(mUser.getIdstr(), group.getIdstr());
            publishProgress(
                String.format(getString(R.string.profile_add_to_group), group.getName()));

            mGroupMemberListed.getLists().add(groupListed);
          }
        } else {
          // 如果原来有这个分组,现在没有勾选,则删除
          if (checkedItems[i]) {
            // 从分组中删除好友
            SinaSDK.getInstance(AppContext.getToken())
                .friendshipsGroupdMembersDestory(mUser.getIdstr(), group.getIdstr());
            publishProgress(
                String.format(getString(R.string.profile_group_remvoe_friend), group.getName()));
          }
          // 原来没有勾选,现在也没有勾选,不做处理
        }
      }

      return true;
    }
    @Override
    public FriendshipShow workInBackground(Void... params) throws TaskException {
      FriendshipShow friendshipShow =
          SinaSDK.getInstance(AppContext.getToken())
              .friendshipsShow(AppContext.getUser().getIdstr(), mUser.getIdstr());

      if (friendshipShow.getSource().getFollowing()) {
        GroupMemberListed[] result =
            SinaSDK.getInstance(AppContext.getToken()).friendshipGroupsListed(mUser.getIdstr());
        if (result != null && result.length > 0) {
          mGroupMemberListed = result[0];
        } else {
          mGroupMemberListed = new GroupMemberListed();
          mGroupMemberListed.setLists(new ArrayList<GroupListed>());
          mGroupMemberListed.setUid(mUser.getId());
        }
      }

      return friendshipShow;
    }
    @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.º 5
0
    @Override
    public TokenInfo workInBackground(Void... params) throws TaskException {
      TokenInfo tokenInfo = null;
      try {
        tokenInfo = SinaSDK.getInstance(account.getToken()).getTokenInfo(account.get_token());
      } catch (TaskException e) {
        e.printStackTrace();
        if ("21327".equals(e.getCode()) || "21317".equals(e.getCode())) {
          tokenInfo = new TokenInfo();
          tokenInfo.setCreate_at("0");
          tokenInfo.setExpire_in("0");
        }
      }

      if (tokenInfo != null) {
        return tokenInfo;
      }

      return null;
    }
Ejemplo n.º 6
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;
    }