Beispiel #1
0
    @Override
    public TokenInfo workInBackground(AccountBean... params) throws TaskException {
      Logger.w("run CheckAccountValidTask");

      TokenInfo token = null;
      TokenInfo adToken = null;

      try {
        AccountBean account = params[0];
        // Aisen授权
        try {
          token =
              SinaSDK.getInstance(account.getAccessToken())
                  .getTokenInfo(account.getAccessToken().getToken());
        } catch (TaskException e) {
          e.printStackTrace();
          if ("21327".equals(e.getCode()) || "21317".equals(e.getCode())) {
            token = new TokenInfo();
            token.setExpire_in(0);
          }
        }
        if (token != null) account.getAccessToken().setExpires_in(token.getExpire_in());
        // Weico授权
        try {
          if (account.getAdvancedToken() != null)
            adToken =
                SinaSDK.getInstance(account.getAdvancedToken())
                    .getTokenInfo(account.getAdvancedToken().getToken());
          else {
            adToken = new TokenInfo();
            adToken.setExpire_in(0);
          }
        } catch (TaskException e) {
          e.printStackTrace();
          if ("21327".equals(e.getCode()) || "21317".equals(e.getCode())) {
            adToken = new TokenInfo();
            adToken.setExpire_in(0);
          }
        }
        if (account.getAdvancedToken() != null && adToken != null)
          account.getAdvancedToken().setExpires_in(adToken.getExpire_in());
      } catch (Throwable e) {
      }

      if (token != null) {
        token.setUid(params[0].getUid());
      }
      return token;
    }
Beispiel #2
0
    @Override
    public UnreadCount workInBackground(Void... params) throws TaskException {
      if (!AppContext.isLogedin()) return null;

      UnreadCount result =
          SinaSDK.getInstance(AppContext.getToken()).remindUnread(AppContext.getUser().getIdstr());
      //			result.setMention_status(500);
      //			result.setMention_cmt(100);
      //			result.setCmt(20);
      //			result.setFollower(10);

      AppContext.setUnreadCount(new UnreadCount());
      ;
      if (AppSettings.isNotifyComment()) AppContext.getUnreadCount().setCmt(result.getCmt());
      if (AppSettings.isNotifyCommentMention())
        AppContext.getUnreadCount().setMention_cmt(result.getMention_cmt());
      if (AppSettings.isNotifyStatusMention())
        AppContext.getUnreadCount().setMention_status(result.getMention_status());
      if (AppSettings.isNotifyFollower())
        AppContext.getUnreadCount().setFollower(result.getFollower());
      if (AppSettings.isNotifyDm()) AppContext.getUnreadCount().setDm(result.getDm());

      // 更新DB
      result.setId(AppContext.getUser().getIdstr());
      SinaDB.getSqlite().insert(null, AppContext.getUnreadCount());
      return result;
    }
    @Override
    public WeiBoUser workInBackground(String... params) throws TaskException {
      // 1、请求授权
      AccessToken accessToken = SinaSDK.getInstance(null).getAccessToken(params[0]);
      AccountBean account = new AccountBean();
      account.setToken(accessToken);

      // 2、加载用户信息
      publishProgress(R.string.account_load_userinfo);
      WeiBoUser user = SinaSDK.getInstance(accessToken).userShow(accessToken.getUid(), null);

      // 3、加载分组信息
      publishProgress(R.string.account_load_groups);
      Groups groups = SinaSDK.getInstance(accessToken).friendshipGroups();

      // 4、更新新账户到DB
      account.setUser(user);
      account.setGroups(groups);
      account.setAccount(mAccount);
      account.setPassword(mPassword);
      account.setUserId(user.getIdstr());
      // 2014-09-18 移除了所有账户信息,包括LoggedIn,所以需要调用AccountFragment.login()
      AccountDB.remove(account.getUserId());
      AccountDB.newAccount(account);

      if (AppContext.isLogedin()
          &&
          // 2014-09-18 仅更新登录用户数据
          AppContext.getUser().getIdstr().equals(user.getIdstr())) {
        AccountFragment.login(account, false);
      }

      if (getActivity() != null) {
        Intent data = new Intent();
        data.putExtra("token", accessToken);
        getActivity().setResult(Activity.RESULT_OK, data);
      }

      return user;
    }