Skip to content

Commit

Permalink
fix: some get methods should not reply on downloadTask
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianhua Ran committed Nov 7, 2019
1 parent 4d4b12f commit ddde3dc
Showing 1 changed file with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ public boolean isUsing() {

@Override
public boolean isRunning() {
insureAssembleDownloadTask();
return OkDownload.with().downloadDispatcher().isRunning(downloadTask);
if (downloadTask == null) {
return false;
} else {
return OkDownload.with().downloadDispatcher().isRunning(downloadTask);
}
}

@Override
Expand All @@ -263,6 +266,9 @@ public void insureAssembleDownloadTask() {
}
downloadTask = builder.build();
compatListener = CompatListenerAdapter.create(listener);
if (progressAssist == null) {
progressAssist = new ProgressAssist(callbackProgressCount);
}
statusAssist.setDownloadTask(downloadTask);
downloadTask.addTag(KEY_TASK_ADAPTER, this);
}
Expand Down Expand Up @@ -294,8 +300,7 @@ public int getDownloadId() {

@Override
public String getUrl() {
insureAssembleDownloadTask();
return downloadTask.getUrl();
return builder.url;
}

@Override
Expand All @@ -305,8 +310,7 @@ public int getCallbackProgressTimes() {

@Override
public int getCallbackProgressMinInterval() {
insureAssembleDownloadTask();
return downloadTask.getMinIntervalMillisCallbackProcess();
return builder.minIntervalMillisCallbackProgress;
}

@Override
Expand All @@ -321,19 +325,16 @@ public boolean isPathAsDirectory() {

@Override
public String getFilename() {
insureAssembleDownloadTask();
return downloadTask.getFilename();
if (builder.pathAsDirectory) {
return null;
}
return new File(builder.path).getName();
}

@Override
public String getTargetFilePath() {
insureAssembleDownloadTask();
File file = downloadTask.getFile();
if (file != null) {
return file.getPath();
} else {
return null;
}
return FileDownloadUtils
.getTargetFilePath(builder.path, builder.pathAsDirectory, getFilename());
}

@Override
Expand All @@ -347,7 +348,9 @@ public int getSoFarBytes() {
}

public long getSoFarBytesInLong() {
insureAssembleDownloadTask();
if (downloadTask == null) {
return 0L;
}
BreakpointInfo info = downloadTask.getInfo();
if (info != null) {
return info.getTotalOffset();
Expand Down Expand Up @@ -375,7 +378,7 @@ public int getTotalBytes() {
}

public long getTotalBytesInLong() {
insureAssembleDownloadTask();
if (downloadTask == null) return 0L;
BreakpointInfo info = downloadTask.getInfo();
if (info != null) {
return info.getTotalLength();
Expand All @@ -390,7 +393,7 @@ public int getSmallFileTotalBytes() {

@Override
public long getLargeFileTotalBytes() {
insureAssembleDownloadTask();
if (downloadTask == null) return 0L;
BreakpointInfo info = downloadTask.getInfo();
if (info != null) {
return info.getTotalLength();
Expand Down Expand Up @@ -470,8 +473,7 @@ public int getRetryingTimes() {

@Override
public boolean isSyncCallback() {
insureAssembleDownloadTask();
return !downloadTask.isAutoCallbackToUIThread();
return !builder.autoCallbackToUIThread;
}

@Override
Expand All @@ -481,8 +483,7 @@ public boolean isLargeFile() {

@Override
public boolean isWifiRequired() {
insureAssembleDownloadTask();
return downloadTask.isWifiRequired();
return builder.isWifiRequired;
}

// implement BaseDownload.IRunningTask
Expand Down

0 comments on commit ddde3dc

Please sign in to comment.