Esempio 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;
    }
Esempio n. 2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1000 && RESULT_OK == resultCode) {
      showMessage(R.string.weico_success);

      AccessToken token = (AccessToken) data.getSerializableExtra("token");
      Logger.e(token);

      SinaDB.getSqlite().deleteAll(null, AccessToken.class);
      SinaDB.getSqlite().insert(null, token);
      AppContext.setAdvancedToken(token);
    } else if (requestCode == 2000 && RESULT_OK == resultCode) {
      login();
    }
  }
Esempio 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);
    }
  }
Esempio n. 4
0
  public static UnreadCount getUnreadCount() {
    if (!AppContext.isLogedin()) return null;

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