Skip to content

Commit 6144ebb

Browse files
committed
update download
1 parent 467d04e commit 6144ebb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

library/src/main/java/com/just/library/DefaultDownLoaderImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DefaultDownLoaderImpl implements DownloadListener, DownLoadResultLi
3131
private boolean enableIndicator;
3232
private volatile static int NoticationID = 1;
3333
private List<DownLoadResultListener> mDownLoadResultListeners;
34-
private LinkedList<String> mList = new LinkedList<>();
34+
static LinkedList<String> mList = null;
3535
private WeakReference<Activity> mActivityWeakReference = null;
3636
private DefaultMsgConfig.DownLoadMsgConfig mDownLoadMsgConfig = null;
3737
private static final String TAG = DefaultDownLoaderImpl.class.getSimpleName();
@@ -144,7 +144,10 @@ private void preDownload(String url, String contentDisposition, long contentLeng
144144

145145
}
146146

147-
if (mList.contains(url)) {
147+
if(mList!=null){
148+
LogUtils.i(TAG,"url:"+url+" list:"+mList);
149+
}
150+
if (mList!=null&&mList.contains(url)) {
148151

149152
AgentWebUtils.toastShowShort(mContext, mDownLoadMsgConfig.getTaskHasBeenExist());
150153
return;
@@ -200,6 +203,9 @@ public void onClick(DialogInterface dialog, int which) {
200203

201204
private void performDownload(String url, long contentLength, File file) {
202205

206+
if (mList == null) {
207+
mList = new LinkedList<>();
208+
}
203209
mList.add(url);
204210
mList.add(file.getAbsolutePath());
205211
//并行下载.
@@ -236,7 +242,7 @@ private File getFile(String contentDisposition, String url) {
236242
}
237243

238244
LogUtils.i(TAG, "file:" + filename);
239-
return AgentWebUtils.createFileByName(mContext,filename,false);
245+
return AgentWebUtils.createFileByName(mContext, filename, false);
240246
} catch (Exception e) {
241247
e.printStackTrace();
242248
}

library/src/main/java/com/just/library/RealDownLoader.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.UnknownFormatConversionException;
2323
import java.util.concurrent.atomic.AtomicBoolean;
2424

25+
import static com.just.library.DefaultDownLoaderImpl.mList;
26+
2527

2628
/**
2729
* Created by cenxiaozhong on 2017/5/13.
@@ -241,6 +243,18 @@ protected void onPostExecute(Integer integer) {
241243
private void doCallback(Integer code) {
242244
DownLoadResultListener mDownLoadResultListener = null;
243245
if ((mDownLoadResultListener = mDownLoadTask.getDownLoadResultListener()) == null) {
246+
LogUtils.e(TAG,"activity has been destroy");
247+
248+
String path="";
249+
if(mList!=null&& mList.contains(path=mDownLoadTask.getFile().getPath())){
250+
synchronized (mList){
251+
int index = mList.indexOf(path);
252+
if (index == -1)
253+
return;
254+
mList.remove(index);
255+
mList.remove(index - 1);
256+
}
257+
}
244258
return;
245259
}
246260
if (code > 200) {

0 commit comments

Comments
 (0)