Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fc11d9e

Browse files
committedDec 24, 2015
fix: 处理新的串行执行机制的pause
1 parent c82d2cf commit fc11d9e

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
 

‎library/src/main/java/com/liulishuo/filedownloader/BaseDownloadTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ FileDownloadDriver getDriver() {
531531
// ------------------
532532
// 开始进入队列
533533
void begin() {
534+
FileDownloadLog.v(this, "filedownloader:lifecycle:start %s by %d ", toString(), getStatus());
534535
_addEventListener();
535536
}
536537

@@ -540,7 +541,7 @@ void ing() {
540541

541542
// 结束
542543
void over() {
543-
FileDownloadLog.v(this, "%s over by %d ", toString(), getStatus());
544+
FileDownloadLog.v(this, "filedownloader:lifecycle:over %s by %d ", toString(), getStatus());
544545

545546
if (finishListener != null) {
546547
finishListener.over();

‎library/src/main/java/com/liulishuo/filedownloader/FileDownloader.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ public boolean handleMessage(final Message msg) {
214214
return true;
215215
}
216216

217+
final BaseDownloadTask task = this.list.get(msg.arg1);
218+
if (!FileDownloadList.getImpl().contains(task)) {
219+
// pause?
220+
FileDownloadLog.d(SerialHandlerCallback.class, "direct go next by not contains %s %d", task, msg.arg1);
221+
goNext(msg.arg1 + 1);
222+
return true;
223+
}
224+
217225
list.get(msg.arg1)
218226
.setFinishListener(new BaseDownloadTask.FinishListener() {
219227
private int index;
@@ -225,20 +233,29 @@ public BaseDownloadTask.FinishListener setIndex(int index) {
225233

226234
@Override
227235
public void over() {
228-
Message nextMsg = SerialHandlerCallback.this.handler.obtainMessage();
229-
nextMsg.what = WHAT_SERIAL_NEXT;
230-
nextMsg.arg1 = this.index;
231-
FileDownloadLog.d(SerialHandlerCallback.class, "start next %s %s",
232-
SerialHandlerCallback.this.list == null ? null : SerialHandlerCallback.this.list.get(0) == null ? null :
233-
SerialHandlerCallback.this.list.get(0).getListener(), nextMsg.arg1);
234-
SerialHandlerCallback.this.handler.sendMessage(nextMsg);
236+
goNext(this.index);
235237
}
236238
}.setIndex(msg.arg1 + 1))
237239
.start();
238240

239241
}
240242
return true;
241243
}
244+
245+
private void goNext(final int nextIndex) {
246+
if (this.handler == null || this.list == null) {
247+
FileDownloadLog.w(this, "need go next %d, but params is not ready %s %s", nextIndex, this.handler, this.list);
248+
return;
249+
}
250+
251+
Message nextMsg = this.handler.obtainMessage();
252+
nextMsg.what = WHAT_SERIAL_NEXT;
253+
nextMsg.arg1 = nextIndex;
254+
FileDownloadLog.d(SerialHandlerCallback.class, "start next %s %s",
255+
this.list == null ? null : this.list.get(0) == null ? null :
256+
this.list.get(0).getListener(), nextMsg.arg1);
257+
this.handler.sendMessage(nextMsg);
258+
}
242259
}
243260

244261
}

0 commit comments

Comments
 (0)
Failed to load comments.