Search in sources :

Example 1 with OfflinePictureBean

use of org.aisen.weibo.sina.support.bean.OfflinePictureBean in project AisenWeiBo by wangdan.

the class OfflineService method preparePicture.

private synchronized void preparePicture() {
    // 等微博离线完了再离线图片
    if (unOfflineGroups.size() > 0)
        return;
    // 正在运行
    if (BaseActivity.getRunningActivity() instanceof MainActivity) {
        TimelineMainFragment.sendBroadcast();
    } else {
        setOfflineFinished(loggedIn, true);
    }
    // 清理缓存数据
    mPictureMap.clear();
    // 微博更新完了
    mNotifier.notifyStatusSuccess(mGroups.size(), offlineStatusCount, offlineStatusLengh);
    // 只有WIFI情况才离线图片
    if (isCanceled()) {
        return;
    }
    // 没有图片
    if (mPictures.size() == 0) {
        stopSelf();
    } else {
        // 开始下载队列里的图片
        if (OFFLINE_EXECUTOR == null) {
            OFFLINE_EXECUTOR = Executors.newFixedThreadPool(AppSettings.offlinePicTaskSize(), sThreadFactory);
        }
        // 新建线程队列,开始下载图片
        List<LoadPictureTask> taskList = new ArrayList<>();
        int taskSize = AppSettings.offlinePicTaskSize() > mPictures.size() ? mPictures.size() : AppSettings.offlinePicTaskSize();
        for (int i = 0; i < taskSize; i++) {
            OfflinePictureBean bean = pollPicture();
            if (bean != null)
                taskList.add(new LoadPictureTask(bean));
            else {
                break;
            }
        }
        for (LoadPictureTask task : taskList) {
            task.executeOnExecutor(OFFLINE_EXECUTOR);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MainActivity(org.aisen.weibo.sina.ui.activity.base.MainActivity) OfflinePictureBean(org.aisen.weibo.sina.support.bean.OfflinePictureBean)

Aggregations

ArrayList (java.util.ArrayList)1 OfflinePictureBean (org.aisen.weibo.sina.support.bean.OfflinePictureBean)1 MainActivity (org.aisen.weibo.sina.ui.activity.base.MainActivity)1