@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; }
@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(); }