Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
0
    @Override
    protected void onSuccess(TokenInfo tokenInfo) {
      super.onSuccess(tokenInfo);

      if (tokenInfo != null
          && account.getUser().getIdstr().equalsIgnoreCase(AppContext.getUser().getIdstr())) {
        long validSecond =
            Long.parseLong(tokenInfo.getCreate_at()) + Long.parseLong(tokenInfo.getExpire_in());
        if (System.currentTimeMillis() > validSecond * 1000) {
          new AlertDialogWrapper.Builder(MainActivity.this)
              .setTitle(R.string.remind)
              .setMessage(R.string.account_expired)
              .setNegativeButton(R.string.no, null)
              .setPositiveButton(
                  R.string.yes,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      LoginFragment.launch(
                          MainActivity.this, account.getAccount(), account.getPassword(), 2000);
                    }
                  })
              .show();
        }
      }
    }
Ejemplo n.º 3
0
  /**
   * 触发一次离线,如果没有设置过离线分组,优先设置后再离线
   *
   * @param context
   */
  public static void toggleOffline(final Activity context) {
    if (!AppContext.isLogedin()) return;

    List<Group> groups =
        SinaDB.getOfflineSqlite()
            .select(new Extra(AppContext.getUser().getIdstr(), null), Group.class);
    if (groups.size() == 0) {
      Logger.d(TAG, "离线分组未设置过");

      new AlertDialogWrapper.Builder(context)
          .setMessage(R.string.offline_none_groups_remind)
          .setNegativeButton(R.string.cancel, null)
          .setPositiveButton(
              R.string.yes,
              new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                  showOfflineGroupsModifyDialog(
                      context,
                      new ArrayList<Group>(),
                      new OnOfflineGroupSetCallback() {

                        @Override
                        public void onChanged(List<Group> newGroups) {
                          // 设置离线分组
                          Logger.d(TAG, "设置离线分组%d个", newGroups.size());

                          if (newGroups.size() > 0) {
                            SinaDB.getOfflineSqlite().insert(getLoggedExtra(null), newGroups);

                            toggleOffline(context);
                          }
                        }
                      },
                      R.string.offline_groups_dialog);
                }
              })
          .show();
    } else {
      OfflineService.startOffline((ArrayList) groups);
    }
  }
Ejemplo n.º 4
0
    @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;
    }
Ejemplo n.º 5
0
 public static Extra getLoggedExtra(String key) {
   return new Extra(AppContext.getUser().getIdstr(), key);
 }
Ejemplo n.º 6
0
 public static boolean isLoggedUser(WeiBoUser user) {
   return user.getIdstr().equalsIgnoreCase(AppContext.getUser().getIdstr());
 }
Ejemplo n.º 7
0
  public static UnreadCount getUnreadCount() {
    if (!AppContext.isLogedin()) return null;

    return SinaDB.getSqlite().selectById(null, UnreadCount.class, AppContext.getUser().getIdstr());
  }