Skip to content

Commit

Permalink
fix #332
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonlzy committed Jun 29, 2017
1 parent 050801b commit e9a8096
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 37 deletions.
16 changes: 3 additions & 13 deletions demo/src/main/java/com/lzy/demo/okdownload/DesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,15 +144,9 @@ public void start() {
if (task == null) {

//这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样
Map<String, String> map = new HashMap<>();
map.put("a", "1");
map.put("b", "2");
map.put("c", "3");
JSONObject jsonObject = new JSONObject(map);
PostRequest<File> request = OkGo.<File>post(apk.url)//
GetRequest<File> request = OkGo.<File>get(apk.url)//
.headers("aaa", "111")//
.params("bbb", "222")//
.upJson(jsonObject);
.params("bbb", "222");

task = OkDownload.request(apk.url, request)//
.priority(apk.priority)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,15 +120,9 @@ public void startAll(View view) {
for (ApkModel apk : apks) {

//这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样
Map<String, String> map = new HashMap<>();
map.put("a", "1");
map.put("b", "2");
map.put("c", "3");
JSONObject jsonObject = new JSONObject(map);
PostRequest<File> request = OkGo.<File>post(apk.url)//
GetRequest<File> request = OkGo.<File>get(apk.url)//
.headers("aaa", "111")//
.params("bbb", "222")//
.upJson(jsonObject);
.params("bbb", "222");

//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
OkDownload.request(apk.url, request)//
Expand Down Expand Up @@ -202,15 +192,9 @@ public void bind(ApkModel apk) {
public void download() {

//这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样
Map<String, String> map = new HashMap<>();
map.put("a", "1");
map.put("b", "2");
map.put("c", "3");
JSONObject jsonObject = new JSONObject(map);
PostRequest<File> request = OkGo.<File>post(apk.url)//
GetRequest<File> request = OkGo.<File>get(apk.url)//
.headers("aaa", "111")//
.params("bbb", "222")//
.upJson(jsonObject);
.params("bbb", "222");

//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
OkDownload.request(apk.url, request)//
Expand Down
4 changes: 2 additions & 2 deletions okgo/src/main/java/com/lzy/okgo/convert/FileConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class FileConvert implements Converter<File> {

public static final String DM_TARGET_FOLDER = File.separator + "download" + File.separator; //下载目标文件夹

private String folder; //目标文件存储的文件夹路径
private String folder; //目标文件存储的文件夹路径
private String fileName; //目标文件存储的文件名
private Callback<File> callback; //下载回调
private Callback<File> callback; //下载回调

public FileConvert() {
this(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e9a8096

Please sign in to comment.