From e9a8096978349df7b2f8b091d0aea686a364ccf3 Mon Sep 17 00:00:00 2001 From: liaoziyao Date: Thu, 29 Jun 2017 12:24:59 +0800 Subject: [PATCH] fix #332 --- .../com/lzy/demo/okdownload/DesActivity.java | 16 +++--------- .../demo/okdownload/DownloadListActivity.java | 26 ++++--------------- .../com/lzy/okgo/convert/FileConvert.java | 4 +-- .../lzy/okserver/download/DownloadTask.java | 5 +++- 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/demo/src/main/java/com/lzy/demo/okdownload/DesActivity.java b/demo/src/main/java/com/lzy/demo/okdownload/DesActivity.java index b8ce517d..40e7f6d8 100644 --- a/demo/src/main/java/com/lzy/demo/okdownload/DesActivity.java +++ b/demo/src/main/java/com/lzy/demo/okdownload/DesActivity.java @@ -29,17 +29,13 @@ import com.lzy.demo.utils.ApkUtils; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.Progress; -import com.lzy.okgo.request.PostRequest; +import com.lzy.okgo.request.GetRequest; import com.lzy.okserver.OkDownload; import com.lzy.okserver.download.DownloadListener; import com.lzy.okserver.download.DownloadTask; -import org.json.JSONObject; - import java.io.File; import java.text.NumberFormat; -import java.util.HashMap; -import java.util.Map; import butterknife.Bind; import butterknife.OnClick; @@ -148,15 +144,9 @@ public void start() { if (task == null) { //这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样 - Map map = new HashMap<>(); - map.put("a", "1"); - map.put("b", "2"); - map.put("c", "3"); - JSONObject jsonObject = new JSONObject(map); - PostRequest request = OkGo.post(apk.url)// + GetRequest request = OkGo.get(apk.url)// .headers("aaa", "111")// - .params("bbb", "222")// - .upJson(jsonObject); + .params("bbb", "222"); task = OkDownload.request(apk.url, request)// .priority(apk.priority)// diff --git a/demo/src/main/java/com/lzy/demo/okdownload/DownloadListActivity.java b/demo/src/main/java/com/lzy/demo/okdownload/DownloadListActivity.java index df8f1702..6b335d9e 100644 --- a/demo/src/main/java/com/lzy/demo/okdownload/DownloadListActivity.java +++ b/demo/src/main/java/com/lzy/demo/okdownload/DownloadListActivity.java @@ -41,16 +41,12 @@ import com.lzy.okgo.OkGo; import com.lzy.okgo.db.DownloadManager; import com.lzy.okgo.model.Progress; -import com.lzy.okgo.request.PostRequest; +import com.lzy.okgo.request.GetRequest; import com.lzy.okserver.OkDownload; -import org.json.JSONObject; - import java.io.File; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import butterknife.Bind; import butterknife.ButterKnife; @@ -124,15 +120,9 @@ public void startAll(View view) { for (ApkModel apk : apks) { //这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样 - Map map = new HashMap<>(); - map.put("a", "1"); - map.put("b", "2"); - map.put("c", "3"); - JSONObject jsonObject = new JSONObject(map); - PostRequest request = OkGo.post(apk.url)// + GetRequest request = OkGo.get(apk.url)// .headers("aaa", "111")// - .params("bbb", "222")// - .upJson(jsonObject); + .params("bbb", "222"); //这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag OkDownload.request(apk.url, request)// @@ -202,15 +192,9 @@ public void bind(ApkModel apk) { public void download() { //这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样 - Map map = new HashMap<>(); - map.put("a", "1"); - map.put("b", "2"); - map.put("c", "3"); - JSONObject jsonObject = new JSONObject(map); - PostRequest request = OkGo.post(apk.url)// + GetRequest request = OkGo.get(apk.url)// .headers("aaa", "111")// - .params("bbb", "222")// - .upJson(jsonObject); + .params("bbb", "222"); //这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag OkDownload.request(apk.url, request)// diff --git a/okgo/src/main/java/com/lzy/okgo/convert/FileConvert.java b/okgo/src/main/java/com/lzy/okgo/convert/FileConvert.java index be134a25..6ad5dfbb 100644 --- a/okgo/src/main/java/com/lzy/okgo/convert/FileConvert.java +++ b/okgo/src/main/java/com/lzy/okgo/convert/FileConvert.java @@ -43,9 +43,9 @@ public class FileConvert implements Converter { public static final String DM_TARGET_FOLDER = File.separator + "download" + File.separator; //下载目标文件夹 - private String folder; //目标文件存储的文件夹路径 + private String folder; //目标文件存储的文件夹路径 private String fileName; //目标文件存储的文件名 - private Callback callback; //下载回调 + private Callback callback; //下载回调 public FileConvert() { this(null); diff --git a/okserver/src/main/java/com/lzy/okserver/download/DownloadTask.java b/okserver/src/main/java/com/lzy/okserver/download/DownloadTask.java index a4ade8ff..0d3d341c 100644 --- a/okserver/src/main/java/com/lzy/okserver/download/DownloadTask.java +++ b/okserver/src/main/java/com/lzy/okserver/download/DownloadTask.java @@ -271,7 +271,10 @@ public void run() { postOnError(progress, OkGoException.BREAKPOINT_EXPIRED()); return; } - if (startPosition == progress.totalSize && startPosition >= 0) { + if (startPosition == 0 && file.exists()) { + IOUtils.delFileOrFolder(file); + } + if (startPosition == progress.totalSize && startPosition > 0) { if (file.exists() && startPosition == file.length()) { postOnFinish(progress, file); return;