Search in sources :

Example 1 with DownloadTask

use of com.lzy.okserver.download.DownloadTask in project okhttp-OkGo by jeasonlzy.

the class DownloadAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    DownloadTask task = values.get(position);
    String tag = createTag(task);
    // 
    task.register(new ListDownloadListener(tag, holder)).register(new LogDownloadListener());
    holder.setTag(tag);
    holder.setTask(task);
    holder.bind();
    holder.refresh(task.progress);
}
Also used : DownloadTask(com.lzy.okserver.download.DownloadTask)

Example 2 with DownloadTask

use of com.lzy.okserver.download.DownloadTask in project okhttp-OkGo by jeasonlzy.

the class OkDownload method startAll.

/**
 * 开始所有任务
 */
public void startAll() {
    for (Map.Entry<String, DownloadTask> entry : taskMap.entrySet()) {
        DownloadTask task = entry.getValue();
        if (task == null) {
            OkLogger.w("can't find task with tag = " + entry.getKey());
            continue;
        }
        task.start();
    }
}
Also used : DownloadTask(com.lzy.okserver.download.DownloadTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with DownloadTask

use of com.lzy.okserver.download.DownloadTask in project okhttp-OkGo by jeasonlzy.

the class OkDownload method restore.

/**
 * 从数据库中恢复任务
 */
public static DownloadTask restore(Progress progress) {
    Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
    DownloadTask task = taskMap.get(progress.tag);
    if (task == null) {
        task = new DownloadTask(progress);
        taskMap.put(progress.tag, task);
    }
    return task;
}
Also used : DownloadTask(com.lzy.okserver.download.DownloadTask)

Example 4 with DownloadTask

use of com.lzy.okserver.download.DownloadTask in project okhttp-OkGo by jeasonlzy.

the class OkDownload method request.

public static DownloadTask request(String tag, Request<File, ? extends Request> request) {
    Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
    DownloadTask task = taskMap.get(tag);
    if (task == null) {
        task = new DownloadTask(tag, request);
        taskMap.put(tag, task);
    }
    return task;
}
Also used : DownloadTask(com.lzy.okserver.download.DownloadTask)

Example 5 with DownloadTask

use of com.lzy.okserver.download.DownloadTask in project okhttp-OkGo by jeasonlzy.

the class OkDownload method restore.

/**
 * 从数据库中恢复任务
 */
public static List<DownloadTask> restore(List<Progress> progressList) {
    Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
    List<DownloadTask> tasks = new ArrayList<>();
    for (Progress progress : progressList) {
        DownloadTask task = taskMap.get(progress.tag);
        if (task == null) {
            task = new DownloadTask(progress);
            taskMap.put(progress.tag, task);
        }
        tasks.add(task);
    }
    return tasks;
}
Also used : Progress(com.lzy.okgo.model.Progress) ArrayList(java.util.ArrayList) DownloadTask(com.lzy.okserver.download.DownloadTask)

Aggregations

DownloadTask (com.lzy.okserver.download.DownloadTask)5 Progress (com.lzy.okgo.model.Progress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1