-
Notifications
You must be signed in to change notification settings - Fork 778
Advanced Use Guideline
Jacksgong edited this page Apr 5, 2018
·
15 revisions
OkDownload.with().setMonitor(monitor);
DownloadDispatcher.setMaxParallelRunningCount(3);
RemitStoreOnSQLite.setRemitToDBDelayMillis(3000);
OkDownload.with().downloadDispatcher().cancelAll();
If you want to inject your components, please invoke following method before you using OkDownload:
OkDownload.Builder builder = new OkDownload.Builder(context)
.downloadStore(downloadStore)
.callbackDispatcher(callbackDispatcher)
.downloadDispatcher(downloadDispatcher)
.connectionFactory(connectionFactory)
.outputStreamFactory(outputStreamFactory)
.downloadStrategy(downloadStrategy)
.processFileStrategy(processFileStrategy)
.monitor(monitor);
OkDownload.setSingletonInstance(builder.build());
DownloadSerialQueue serialQueue = new DownloadSerialQueue(commonListener);
serialQueue.enqueue(task1);
serialQueue.enqueue(task2);
serialQueue.pause();
serialQueue.resume();
int workingTaskId = serialQueue.getWorkingTaskId();
int waitingTaskCount = serialQueue.getWaitingTaskCount();
DownloadTask[] discardTasks = serialQueue.shutdown();
DownloadListener listener1 = new DownloadListener1();
DownloadListener listener2 = new DownloadListener2();
DownloadListener combinedListener = new DownloadListenerBunch.Builder()
.append(listener1)
.append(listener2)
.build();
DownloadTask task = new DownloadTask.build(url, file).build();
task.enqueue(combinedListener);
// all attach or detach is based on the id of Task in fact.
UnifiedListenerManager manager = new UnifiedListenerManager();
DownloadListener listener1 = new DownloadListener1();
DownloadListener listener2 = new DownloadListener2();
DownloadListener listener3 = new DownloadListener3();
DownloadListener listener4 = new DownloadListener4();
DownloadTask task = new DownloadTask.build(url, file).build();
manager.attachListener(task, listener1);
manager.attachListener(task, listener2);
manager.detachListener(task, listener2);
// all listeners added for this task will be removed when task is end.
manager.addAutoRemoveListenersWhenTaskEnd(task.getId());
manager.enqueueTaskWithUnifiedListener(task, listener3);
manager.attachListener(task, listener4);