添加进度更新间隔api,在aria_config.xml
配置<updateInterval value=1000/>
或在代码中调用AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)
便可以改变进度刷新间隔. https://github.com/AriaLyy/Aria/issues/190
This commit is contained in:
@@ -86,10 +86,29 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
case "queueMod":
|
case "queueMod":
|
||||||
loadQueueMod(value);
|
loadQueueMod(value);
|
||||||
break;
|
break;
|
||||||
|
case "updateInterval":
|
||||||
|
loadUpdateInterval(value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadUpdateInterval(String value) {
|
||||||
|
long temp = 1000;
|
||||||
|
if (!TextUtils.isEmpty(value)) {
|
||||||
|
temp = Long.parseLong(value);
|
||||||
|
if (temp <= 0) {
|
||||||
|
temp = 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isDownloadConfig) {
|
||||||
|
mDownloadConfig.updateInterval = temp;
|
||||||
|
}
|
||||||
|
if (isUploadConfig) {
|
||||||
|
mUploadConfig.updateInterval = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadQueueMod(String value) {
|
private void loadQueueMod(String value) {
|
||||||
String mod = "now";
|
String mod = "now";
|
||||||
if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
|
if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
|
||||||
|
@@ -63,6 +63,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
*/
|
*/
|
||||||
private static final long SUB_LEN = 1024 * 1024;
|
private static final long SUB_LEN = 1024 * 1024;
|
||||||
private Timer mTimer;
|
private Timer mTimer;
|
||||||
|
private long mUpdateInterval = 1000;
|
||||||
|
|
||||||
protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
|
protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
@@ -97,7 +98,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始下载流程
|
* 开始流程
|
||||||
*/
|
*/
|
||||||
private void startFlow() {
|
private void startFlow() {
|
||||||
mConstance.resetState();
|
mConstance.resetState();
|
||||||
@@ -145,7 +146,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
mListener.onProgress(mConstance.CURRENT_LOCATION);
|
mListener.onProgress(mConstance.CURRENT_LOCATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 1000);
|
}, 0, mUpdateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void closeTimer() {
|
protected void closeTimer() {
|
||||||
@@ -225,11 +226,25 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
return mListener;
|
return mListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置定时器更新间隔
|
||||||
|
*
|
||||||
|
* @param interval 单位毫秒,不能小于0
|
||||||
|
*/
|
||||||
|
protected long setUpdateInterval(long interval) {
|
||||||
|
if (interval < 0) {
|
||||||
|
ALog.w(TAG, "更新间隔不能小于0,默认为1000毫秒");
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
mUpdateInterval = interval;
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查任务是否是新任务,新任务条件:
|
* 检查任务是否是新任务,新任务条件:
|
||||||
* 1、文件不存在
|
* 1、文件不存在
|
||||||
* 2、下载记录文件不存在
|
* 2、记录文件不存在
|
||||||
* 3、下载记录文件缺失或不匹配
|
* 3、记录文件缺失或不匹配
|
||||||
* 4、数据库记录不存在
|
* 4、数据库记录不存在
|
||||||
* 5、不支持断点,则是新任务
|
* 5、不支持断点,则是新任务
|
||||||
*/
|
*/
|
||||||
@@ -274,7 +289,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
/**
|
/**
|
||||||
* 恢复记录地址
|
* 恢复记录地址
|
||||||
*
|
*
|
||||||
* @return true 表示下载完成
|
* @return true 表示完成
|
||||||
*/
|
*/
|
||||||
private boolean resumeRecordLocation(int i, long startL, long endL) {
|
private boolean resumeRecordLocation(int i, long startL, long endL) {
|
||||||
mConstance.CURRENT_LOCATION += endL - startL;
|
mConstance.CURRENT_LOCATION += endL - startL;
|
||||||
@@ -346,7 +361,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
mConstance.CURRENT_LOCATION += r - startL;
|
mConstance.CURRENT_LOCATION += r - startL;
|
||||||
startL = r;
|
startL = r;
|
||||||
}
|
}
|
||||||
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
|
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复");
|
||||||
recordL[rl] = i;
|
recordL[rl] = i;
|
||||||
rl++;
|
rl++;
|
||||||
} else {
|
} else {
|
||||||
@@ -365,7 +380,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动单线程下载任务
|
* 启动单线程处理任务
|
||||||
*/
|
*/
|
||||||
private void startSingleTask(int[] recordL) {
|
private void startSingleTask(int[] recordL) {
|
||||||
if (mConstance.CURRENT_LOCATION > 0) {
|
if (mConstance.CURRENT_LOCATION > 0) {
|
||||||
@@ -390,7 +405,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
protected abstract void handleNewTask();
|
protected abstract void handleNewTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理不支持断点的下载
|
* 处理不支持断点的任务
|
||||||
*/
|
*/
|
||||||
private void handleNoSupportBP() {
|
private void handleNoSupportBP() {
|
||||||
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
|
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
|
||||||
|
@@ -41,6 +41,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
private boolean isConvertSpeed = false;
|
private boolean isConvertSpeed = false;
|
||||||
boolean isWait = false;
|
boolean isWait = false;
|
||||||
private long mLastSaveTime;
|
private long mLastSaveTime;
|
||||||
|
private long mUpdateInterval;
|
||||||
|
|
||||||
BaseDListener(TASK task, Handler outHandler) {
|
BaseDListener(TASK task, Handler outHandler) {
|
||||||
this.outHandler = new WeakReference<>(outHandler);
|
this.outHandler = new WeakReference<>(outHandler);
|
||||||
@@ -51,6 +52,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||||
mLastLen = mEntity.getCurrentProgress();
|
mLastLen = mEntity.getCurrentProgress();
|
||||||
mLastSaveTime = System.currentTimeMillis();
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
|
mUpdateInterval = manager.getDownloadConfig().getUpdateInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onPre() {
|
@Override public void onPre() {
|
||||||
@@ -123,6 +125,9 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSpeed(long speed) {
|
private void handleSpeed(long speed) {
|
||||||
|
if (mUpdateInterval != 1000) {
|
||||||
|
speed = speed * 1000 / mUpdateInterval;
|
||||||
|
}
|
||||||
if (isConvertSpeed) {
|
if (isConvertSpeed) {
|
||||||
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
||||||
}
|
}
|
||||||
|
@@ -99,6 +99,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
int mInitFailNum = 0;
|
int mInitFailNum = 0;
|
||||||
//任务组大小
|
//任务组大小
|
||||||
int mGroupSize = 0;
|
int mGroupSize = 0;
|
||||||
|
long mUpdateInterval = 1000;
|
||||||
|
|
||||||
AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) {
|
AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
@@ -131,6 +132,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateFileSize();
|
updateFileSize();
|
||||||
|
mUpdateInterval =
|
||||||
|
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -371,7 +374,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
mListener.onProgress(mCurrentLocation);
|
mListener.onProgress(mCurrentLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 1000);
|
}, 0, mUpdateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.download.downloader;
|
package com.arialyy.aria.core.download.downloader;
|
||||||
|
|
||||||
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.common.AbsFileer;
|
import com.arialyy.aria.core.common.AbsFileer;
|
||||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||||
@@ -39,6 +40,8 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
|
|
||||||
Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
|
Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
|
||||||
super(listener, taskEntity);
|
super(listener, taskEntity);
|
||||||
|
setUpdateInterval(
|
||||||
|
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void checkTask() {
|
@Override protected void checkTask() {
|
||||||
|
@@ -36,10 +36,6 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
|||||||
* HTTP任务组下载
|
* HTTP任务组下载
|
||||||
*/
|
*/
|
||||||
public static final int DG_HTTP = 0x12;
|
public static final int DG_HTTP = 0x12;
|
||||||
/**
|
|
||||||
* HTTP单文件上传
|
|
||||||
*/
|
|
||||||
public static final int U_HTTP = 0xA1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FTP单文件下载
|
* FTP单文件下载
|
||||||
@@ -49,6 +45,11 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
|||||||
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
||||||
*/
|
*/
|
||||||
public static final int D_FTP_DIR = 0x14;
|
public static final int D_FTP_DIR = 0x14;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP单文件上传
|
||||||
|
*/
|
||||||
|
public static final int U_HTTP = 0xA1;
|
||||||
/**
|
/**
|
||||||
* FTP单文件上传
|
* FTP单文件上传
|
||||||
*/
|
*/
|
||||||
|
@@ -41,6 +41,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
private boolean isConvertSpeed = false;
|
private boolean isConvertSpeed = false;
|
||||||
boolean isWait = false;
|
boolean isWait = false;
|
||||||
private long mLastSaveTime;
|
private long mLastSaveTime;
|
||||||
|
private long mUpdateInterval;
|
||||||
|
|
||||||
BaseUListener(TASK task, Handler outHandler) {
|
BaseUListener(TASK task, Handler outHandler) {
|
||||||
this.outHandler = new WeakReference<>(outHandler);
|
this.outHandler = new WeakReference<>(outHandler);
|
||||||
@@ -51,6 +52,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||||
mLastLen = mEntity.getCurrentProgress();
|
mLastLen = mEntity.getCurrentProgress();
|
||||||
mLastSaveTime = System.currentTimeMillis();
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
|
mUpdateInterval = manager.getUploadConfig().getUpdateInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onPre() {
|
@Override public void onPre() {
|
||||||
@@ -111,6 +113,9 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSpeed(long speed) {
|
private void handleSpeed(long speed) {
|
||||||
|
if (mUpdateInterval != 1000) {
|
||||||
|
speed = speed * 1000 / mUpdateInterval;
|
||||||
|
}
|
||||||
if (isConvertSpeed) {
|
if (isConvertSpeed) {
|
||||||
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.upload.uploader;
|
package com.arialyy.aria.core.upload.uploader;
|
||||||
|
|
||||||
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.common.AbsFileer;
|
import com.arialyy.aria.core.common.AbsFileer;
|
||||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||||
@@ -35,6 +36,8 @@ class Uploader extends AbsFileer<UploadEntity, UploadTaskEntity> {
|
|||||||
Uploader(IUploadListener listener, UploadTaskEntity taskEntity) {
|
Uploader(IUploadListener listener, UploadTaskEntity taskEntity) {
|
||||||
super(listener, taskEntity);
|
super(listener, taskEntity);
|
||||||
mTempFile = new File(mEntity.getFilePath());
|
mTempFile = new File(mEntity.getFilePath());
|
||||||
|
setUpdateInterval(
|
||||||
|
AriaManager.getInstance(AriaManager.APP).getUploadConfig().getUpdateInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
## 开发日志
|
## 开发日志
|
||||||
|
+ v_3.3.11
|
||||||
|
- 添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value="1000"/>`或在代码中调用
|
||||||
|
`AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔
|
||||||
+ v_3.3.10
|
+ v_3.3.10
|
||||||
- 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181
|
- 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181
|
||||||
- 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182
|
- 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182
|
||||||
|
@@ -34,6 +34,9 @@
|
|||||||
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
||||||
<queueMod value="wait"/>
|
<queueMod value="wait"/>
|
||||||
|
|
||||||
|
<!--进度更新更新间隔,默认1000毫秒-->
|
||||||
|
<updateInterval value="1000"/>
|
||||||
|
|
||||||
</download>
|
</download>
|
||||||
|
|
||||||
<upload>
|
<upload>
|
||||||
@@ -54,6 +57,9 @@
|
|||||||
|
|
||||||
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
||||||
<queueMod value="wait"/>
|
<queueMod value="wait"/>
|
||||||
|
|
||||||
|
<!--进度更新更新间隔,默认1000毫秒-->
|
||||||
|
<updateInterval value="1000"/>
|
||||||
</upload>
|
</upload>
|
||||||
|
|
||||||
</aria>
|
</aria>
|
@@ -157,6 +157,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
mStart.setText("开始");
|
mStart.setText("开始");
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
getBinding().setSpeed("");
|
getBinding().setSpeed("");
|
||||||
|
Log.d(TAG, "cancel");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||||
|
@@ -19,6 +19,7 @@ import android.text.TextUtils;
|
|||||||
import com.arialyy.aria.core.common.QueueMod;
|
import com.arialyy.aria.core.common.QueueMod;
|
||||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||||
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -39,6 +40,11 @@ class Configuration {
|
|||||||
* 通用配置
|
* 通用配置
|
||||||
*/
|
*/
|
||||||
public static class BaseConfig {
|
public static class BaseConfig {
|
||||||
|
/**
|
||||||
|
* 进度刷新间隔,默认1秒
|
||||||
|
*/
|
||||||
|
long updateInterval = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 旧任务数
|
* 旧任务数
|
||||||
*/
|
*/
|
||||||
@@ -73,6 +79,25 @@ class Configuration {
|
|||||||
*/
|
*/
|
||||||
String queueMod = "wait";
|
String queueMod = "wait";
|
||||||
|
|
||||||
|
public long getUpdateInterval() {
|
||||||
|
return updateInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置进度更新间隔,该设置对正在运行的任务无效,默认为1000毫秒
|
||||||
|
*
|
||||||
|
* @param updateInterval 不能小于0
|
||||||
|
*/
|
||||||
|
public BaseConfig setUpdateInterval(long updateInterval) {
|
||||||
|
if (updateInterval <= 0) {
|
||||||
|
ALog.w("Configuration", "进度更新间隔不能小于0");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
this.updateInterval = updateInterval;
|
||||||
|
saveKey("updateInterval", String.valueOf(updateInterval));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public String getQueueMod() {
|
public String getQueueMod() {
|
||||||
return queueMod;
|
return queueMod;
|
||||||
}
|
}
|
||||||
@@ -272,7 +297,7 @@ class Configuration {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreadNum(int threadNum){
|
public void setThreadNum(int threadNum) {
|
||||||
this.threadNum = threadNum;
|
this.threadNum = threadNum;
|
||||||
saveKey("threadNum", String.valueOf(threadNum));
|
saveKey("threadNum", String.valueOf(threadNum));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user