Skip to content

Commit

Permalink
fix breakpoint download invalid after invoke setId method.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoqian-hu-20230331 committed Jul 30, 2020
1 parent dc5d1f6 commit c6cee52
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import android.app.Application;
import android.os.Environment;

import com.huxq17.download.Pump;
import com.huxq17.download.PumpFactory;
import com.huxq17.download.config.DownloadConfig;
import com.huxq17.download.core.DownloadInfo;
import com.huxq17.download.core.DownloadInterceptor;
import com.huxq17.download.core.service.IDownloadConfigService;
import com.huxq17.download.core.DownloadTaskExecutor;
import com.huxq17.download.core.SimpleDownloadTaskExecutor;
import com.huxq17.download.core.service.IDownloadConfigService;
import com.huxq17.download.utils.FileUtil;
import com.huxq17.download.utils.Util;

import java.io.File;

Expand Down Expand Up @@ -81,7 +80,7 @@ public DownloadInfo intercept(DownloadChain chain) {
public void onCreate() {
super.onCreate();
instance = this;
DownloadConfig.newBuilder()
Pump.newConfigBuilder()
//Optional,set the maximum number of tasks to run at the same time, default 3.
.setMaxRunningTaskNum(2)
//Optional,set the minimum available storage space size for downloading to avoid insufficient storage space during downloading, default is 4kb.
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/huxq17/download/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void onFailed() {
//Set whether to repeatedly download the downloaded file,default false.
.forceReDownload(true)
//Set how many threads are used when downloading,default 3.
.threadNum(1)
.threadNum(3)
.setId("123")
//Pump will connect server by this OKHttp request builder,so you can customize http request.
.setRequestBuilder(new Request.Builder())
.setRetry(3, 200)
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/huxq17/download/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import androidx.annotation.NonNull;

import com.huxq17.download.config.DownloadConfig;
import com.huxq17.download.core.DownloadInfo;
import com.huxq17.download.core.DownloadRequest;
import com.huxq17.download.core.service.IDownloadManager;
Expand All @@ -13,6 +14,9 @@
import java.util.List;

public class Pump {
public static DownloadConfig.Builder newConfigBuilder(){
return DownloadConfig.newBuilder();
}
/**
* Create a new download request,download file will store in cache path.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void setDownloadInfo(DownloadDetailsInfo downloadInfo) {
}

public int getRetryDelay() {
return retryDelay < 0 ? 0 : retryDelay;
return Math.max(retryDelay, 0);
}

public DownloadDetailsInfo getDownloadInfo() {
Expand All @@ -68,7 +68,7 @@ public String getName() {
}

public int getRetryCount() {
return retryCount < 0 ? 0 : retryCount;
return Math.max(retryCount, 0);
}

public String getUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ private void checkDownloadFile(long contentLength, boolean isSupportBreakPointDo
}

private DownloadConnection buildRequest(DownloadRequest downloadRequest) {
String url = downloadRequest.getUrl();
String id = downloadRequest.getId();
DownloadConnection connection = createConnection(downloadRequest);
firstBlockTask = new DownloadBlockTask(downloadRequest, 0, connection);
long completedSize = firstBlockTask.getCompletedSize();
DownloadProvider.CacheBean cacheBean = DBService.getInstance().queryCache(url);
DownloadProvider.CacheBean cacheBean = DBService.getInstance().queryCache(id);
if (cacheBean == null) {
return connection;
}
Expand Down

0 comments on commit c6cee52

Please sign in to comment.