Exemplo 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;
    }
Exemplo n.º 2
0
  @Override
  protected void onResume() {
    super.onResume();

    if (!AppContext.isLogedin()) finish();

    setFabType();

    BaiduAnalyzeUtils.onPageStart("首页");
  }
Exemplo 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);
    }
  }
Exemplo 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;
    }
Exemplo n.º 5
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (unreadCountNotifier == null) unreadCountNotifier = new UnreadCountNotifier(this);

    if (!AppContext.isLogedin()) {
      stopSelf();
      return super.onStartCommand(intent, flags, startId);
    }

    String action = intent != null ? intent.getAction() : "";

    if (ACTION_GET.equals(action)) {
      resetTheTime();

      new UnreadTask().execute();
    } else if (ACTION_UPDATE.equals(action)) {
      Logger.v(TAG, "刷新时间");

      resetTheTime();
    }

    return super.onStartCommand(intent, flags, startId);
  }
Exemplo n.º 6
0
  public static UnreadCount getUnreadCount() {
    if (!AppContext.isLogedin()) return null;

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