Esempio n. 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;
  }
Esempio n. 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 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;
  }
Esempio n. 4
0
  public void save(LocalAccount account, List<Group> groupList) {
    if (isNull(account) || ListUtil.isEmpty(groupList)) {
      return;
    }

    for (Group group : groupList) {
      save(account, group);
    }
  }
Esempio n. 5
0
  @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();
  }