Exemple #1
0
  public boolean merge(LocalAccount account, List<Group> newGroupList) {
    boolean hasChange = false;
    if (account == null || ListUtil.isEmpty(newGroupList)) {
      return hasChange;
    }

    List<Group> oldGroupList = findAll(account);
    if (ListUtil.isEmpty(oldGroupList)) {
      hasChange = true;
      return hasChange;
    }
    for (Group group : newGroupList) {
      if (!oldGroupList.contains(group)) {
        save(account, group);
        hasChange = true;
      }
    }

    for (Group group : oldGroupList) {
      if (!newGroupList.contains(group)) {
        // delete
        delete((LocalGroup) group);
        hasChange = true;
      }
    }

    return hasChange;
  }
Exemple #2
0
  public List<Group> getGroups(LocalAccount account, Paging<Group> paging) {
    List<Group> groupList = null;
    if (account == null || paging == null) {
      return groupList;
    }

    String sql =
        "select "
            + "    * "
            + "from "
            + "    Group_Info "
            + "where "
            + "    State != "
            + LocalGroup.STATE_DELETED
            + " and "
            + "    Account_ID = "
            + account.getAccountId()
            + " "
            + "order by Created_At asc";

    groupList = find(sql, paging.getPageIndex(), paging.getPageSize());
    if (ListUtil.isEmpty(groupList) || groupList.size() < paging.getPageSize() / 2) {
      paging.setLastPage(true);
    }

    return groupList;
  }
  @Override
  protected Integer doInBackground(Void... params) {
    cacheCount = 0;
    if (microBlog == null) {
      return cacheCount;
    }

    List<? extends BaseUser> userList = null;
    Paging<User> paging = new Paging<User>();
    paging.setPageSize(pageSize);

    while (paging.moveToNext() && cycleTime-- > 0) {
      try {
        userList = microBlog.getGroupMembers(group.getSpGroupId(), paging);
      } catch (LibException e) {
        if (Constants.DEBUG) Log.e(TAG, "Task", e);
      }
      if (ListUtil.isNotEmpty(userList)) {
        cacheCount += userList.size();
        this.publishProgress(userList);
      }
    }

    return cacheCount;
  }
  @Override
  protected Boolean doInBackground(net.dev123.mblog.entity.Status... params) {
    boolean isSuccess = false;
    if (microBlog == null || params == null || params.length != 2) {
      return isSuccess;
    }

    net.dev123.mblog.entity.Status max = params[0];
    net.dev123.mblog.entity.Status since = params[1];

    Paging<net.dev123.mblog.entity.Status> paging = new Paging<net.dev123.mblog.entity.Status>();
    paging.setGlobalMax(max);
    paging.setGlobalSince(since);

    if (paging.moveToNext()) {
      try {
        listStatus = microBlog.getMentions(paging);
      } catch (LibException e) {
        if (Constants.DEBUG) Log.e(TAG, "Task", e);
        resultMsg = ResourceBook.getStatusCodeValue(e.getExceptionCode(), adapter.getContext());
        paging.moveToPrevious();
      } finally {
        ListUtil.truncate(listStatus, paging.getMax(), paging.getSince());
      }
    }
    Util.getResponseCounts(listStatus, microBlog);

    isSuccess = listStatus != null && listStatus.size() > 0;
    if (isSuccess && paging.hasNext()) {
      LocalStatus localStatus = StatusUtil.createDividerStatus(listStatus, account);
      listStatus.add(localStatus);
    }
    return isSuccess;
  }
  @Override
  protected List<? extends BaseUser> doInBackground(Void... params) {
    if (adapter == null || microBlog == null) {
      return null;
    }

    List<? extends BaseUser> userList = null;
    boolean isFirstLoad = context.isFirstLoad();
    SocialGraphDao dao = new SocialGraphDao(context);
    try {
      paging = adapter.getPaging();
      if (!isFirstLoad && paging.moveToNext()) {
        if (relation == Relation.Followingship) {
          userList = dao.getFriends(user, paging);
        } else {
          userList = dao.getFollowers(user, paging);
        }
        if (paging.getPageIndex() == 1 && ListUtil.isEmpty(userList)) {
          isFirstLoad = true;
          context.setFirstLoad(isFirstLoad);
        }
      }

      SocialGraphCacheTask cacheTask = null;
      if (isFirstLoad) {
        // 第一次加载时,做一个缓冲task
        if (paging.getPageIndex() == 1 && adapter.getCount() == 0) {
          Paging<User> remotePaging = new Paging<User>();
          adapter.setPaging(remotePaging);
          // 缓冲远程数据;
          cacheTask = new SocialGraphCacheTask(context, account, relation);
        }

        paging = adapter.getPaging();
        if (paging.moveToNext()) {
          if (relation == Relation.Followingship) {
            userList = microBlog.getFriends(paging);
          } else {
            userList = microBlog.getFollowers(paging);
          }
        }
      } else if (paging.getPageIndex() == 1) {
        // 防止新关注,缓冲第一次。
        cacheTask = new SocialGraphCacheTask(context, account, relation);
        cacheTask.setCycleTime(1);
        cacheTask.setPageSize(20);
      }
      if (cacheTask != null) {
        cacheTask.execute();
      }
    } catch (LibException e) {
      if (Constants.DEBUG) Log.e(TAG, "Task", e);
      resultMsg = ResourceBook.getStatusCodeValue(e.getExceptionCode(), context);
      paging.moveToPrevious();
    }

    return userList;
  }
Exemple #6
0
  public void save(LocalAccount account, List<Group> groupList) {
    if (isNull(account) || ListUtil.isEmpty(groupList)) {
      return;
    }

    for (Group group : groupList) {
      save(account, group);
    }
  }
 public void updateButtonState() {
   ArrayList<BaseUser> userList = pickupSelectedUsers();
   Button btnConfirm = (Button) this.findViewById(R.id.btnConfirm);
   if (ListUtil.isNotEmpty(userList)) {
     btnConfirm.setEnabled(true);
   } else {
     btnConfirm.setEnabled(false);
   }
 }
  @Override
  protected void onProgressUpdate(List<? extends BaseUser>... values) {
    super.onProgressUpdate(values);
    if (values == null || values.length != 1) {
      return;
    }

    List<? extends BaseUser> userList = values[0];
    if (ListUtil.isNotEmpty(userList)) {
      dao.batchSave(account, group, userList);
    }
  }
  @Override
  protected void onPostExecute(List<? extends BaseUser> result) {
    if (ListUtil.isNotEmpty(result)) {
      adapter.addCacheToDivider(null, (List<User>) result);
    } else {
      adapter.notifyDataSetChanged();

      if (resultMsg != null) {
        Toast.makeText(adapter.getContext(), resultMsg, Toast.LENGTH_LONG).show();
      }
    }

    if (paging.hasNext()) {
      ((UserQuickSelectorActivity) context).showMoreFooter();
    } else {
      ((UserQuickSelectorActivity) context).showNoMoreFooter();
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    yibo = (YiBoApplication) context.getApplicationContext();
    if (!yibo.isUpdatesEnabled()) {
      return;
    }
    if (ListUtil.isEmpty(accountList)) {
      return;
    }

    for (LocalAccount account : accountList) {
      Cache cache = CacheManager.getInstance().getCache(account);
      AdapterCollectionCache adapterCache = (AdapterCollectionCache) cache;
      if (adapterCache != null) {
        QueryRemindCountTask remindCountTask = new QueryRemindCountTask(adapterCache);
        remindCountTask.execute();
      }
    }
    if (Constants.DEBUG) Log.v(TAG, "auto update receiver");
  }
  @Override
  protected Integer doInBackground(Void... params) {
    if (statusUpdate == null
        || StringUtil.isBlank(statusUpdate.getStatus())
        || ListUtil.isEmpty(listAccount)) {
      return 0;
    }

    if (statusUpdate.getImage() != null && isRetry) {
      rotateImage();
      compressImage();
    }

    String text = statusUpdate.getStatus();
    net.dev123.mblog.entity.Status newStatus = null;
    for (int i = 0; i < listAccount.size(); i++) {
      LocalAccount account = listAccount.get(i);

      if (account == null) {
        continue;
      }

      ProgressHolder holder = new ProgressHolder();
      holder.account = account;
      holder.state = State.Loading;
      newStatus = null;
      this.publishProgress(holder);

      try {
        StatusUpdate toUpdate = new StatusUpdate(text);
        toUpdate.setImage(statusUpdate.getImage());
        toUpdate.setLocation(statusUpdate.getLocation());
        if (account.isSnsAccount()) {
          Sns sns = GlobalVars.getSns(account);
          if (sns != null) {
            boolean result = false;
            if (statusUpdate.getImage() != null) {
              result = sns.uploadPhoto(statusUpdate.getImage(), statusUpdate.getStatus());
            } else {
              result = sns.createStatus(statusUpdate.getStatus());
            }
            if (result) {
              newStatus = new net.dev123.mblog.entity.Status();
            }
          }
        } else {
          MicroBlog microBlog = GlobalVars.getMicroBlog(account);
          if (microBlog != null) {
            newStatus = microBlog.updateStatus(toUpdate);
          }
        }
      } catch (LibException e) {
        if (Constants.DEBUG) Log.e(TAG, "Task", e);
        resultMsg = ResourceBook.getStatusCodeValue(e.getExceptionCode(), context);
      }

      if (newStatus != null) {
        holder.state = State.Success;
      } else {
        holder.state = State.Failed;
        listFailedAccount.add(account);
      }
      this.publishProgress(holder);
    }
    if (listFailedAccount.size() < 1) {
      SystemClock.sleep(1000);
    }

    return listAccount.size() - listFailedAccount.size();
  }