[dev_opt_2.15.0] 优化下载逻辑
This commit is contained in:
@@ -26,7 +26,9 @@ public interface DownloadCallBack {
|
||||
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void threadDownLoadFinished(String url,ThreadBean threadBean);
|
||||
void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ public interface IDownload {
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void onFinished(String url,ThreadBean threadBean);
|
||||
void onFinished(String url, ThreadBean threadBean, String localPath);
|
||||
|
||||
/**
|
||||
* 错误信息回调
|
||||
|
||||
@@ -154,10 +154,10 @@ public class DownloadService implements InitThread.InitCallBack, DownloadCallBac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void threadDownLoadFinished(String url, ThreadBean threadBean) {
|
||||
public void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onFinished(url, threadBean);
|
||||
iDownload.onFinished(url, threadBean, localPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class DownloadTask implements DownloadCallBack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void threadDownLoadFinished(String url, ThreadBean threadBean) {
|
||||
public synchronized void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
for (ThreadBean bean : threads) {
|
||||
if (bean.getId() == threadBean.getId()) {
|
||||
//从列表中将已下载完成的线程信息移除
|
||||
@@ -151,7 +151,7 @@ public class DownloadTask implements DownloadCallBack {
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg("下载完成");
|
||||
downloadData.setFilePath(fileBean.getSavePath() + fileBean.getFileName());
|
||||
UiThreadHandler.post(() -> downloadCallBack.threadDownLoadFinished(url,threadBean));
|
||||
UiThreadHandler.post(() -> downloadCallBack.threadDownLoadFinished(url,threadBean, localPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,10 @@ import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.Config;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.DownloadCallBack;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.event.DownloadData;
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
|
||||
import java.io.File;
|
||||
@@ -53,7 +51,7 @@ public class DownloadThread extends Thread {
|
||||
int start = threadBean.getStart() + threadBean.getFinished();
|
||||
connection.setRequestProperty("Range","bytes="+start+"-"+threadBean.getEnd());
|
||||
//设置写入位置
|
||||
File file = new File(fileBean.getFileName().contains(".zip") ? Config.downLoadObuPath : Config.downLoadPath,fileBean.getFileName());
|
||||
File file = new File(fileBean.getSavePath(),fileBean.getFileName());
|
||||
raf = new RandomAccessFile(file,"rwd");
|
||||
raf.seek(start);
|
||||
//开始下载
|
||||
@@ -75,7 +73,7 @@ public class DownloadThread extends Thread {
|
||||
}
|
||||
}
|
||||
//下载完成
|
||||
UiThreadHandler.post(() -> callback.threadDownLoadFinished(this.fileBean.getUrl(),threadBean));
|
||||
UiThreadHandler.post(() -> callback.threadDownLoadFinished(this.fileBean.getUrl(),threadBean, file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user