添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value=1000/>`或在代码中调用`AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔. https://github.com/AriaLyy/Aria/issues/190

pull/330/head
AriaLyy 7 years ago
parent f6d7a7c820
commit 755e333d8b
  1. 19
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  2. 31
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  4. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  5. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  6. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  7. 5
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java
  8. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java
  9. 3
      DEV_LOG.md
  10. 6
      app/src/main/assets/aria_config.xml
  11. 1
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 25
      aria/src/main/java/com/arialyy/aria/core/Configuration.java

@ -86,7 +86,26 @@ class ConfigHelper extends DefaultHandler {
case "queueMod":
loadQueueMod(value);
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;
}
}

@ -63,6 +63,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/
private static final long SUB_LEN = 1024 * 1024;
private Timer mTimer;
private long mUpdateInterval = 1000;
protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
mListener = listener;
@ -97,7 +98,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 开始下载流程
* 开始流程
*/
private void startFlow() {
mConstance.resetState();
@ -145,7 +146,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mListener.onProgress(mConstance.CURRENT_LOCATION);
}
}
}, 0, 1000);
}, 0, mUpdateInterval);
}
protected void closeTimer() {
@ -225,11 +226,25 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
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文件不存在
* 2下载记录文件不存在
* 3下载记录文件缺失或不匹配
* 2记录文件不存在
* 3记录文件缺失或不匹配
* 4数据库记录不存在
* 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) {
mConstance.CURRENT_LOCATION += endL - startL;
@ -346,7 +361,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mConstance.CURRENT_LOCATION += r - startL;
startL = r;
}
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复");
recordL[rl] = i;
rl++;
} else {
@ -365,7 +380,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 启动单线程下载任务
* 启动单线程处理任务
*/
private void startSingleTask(int[] recordL) {
if (mConstance.CURRENT_LOCATION > 0) {
@ -390,7 +405,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
protected abstract void handleNewTask();
/**
* 处理不支持断点的下载
* 处理不支持断点的任务
*/
private void handleNoSupportBP() {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();

@ -41,6 +41,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
private boolean isConvertSpeed = false;
boolean isWait = false;
private long mLastSaveTime;
private long mUpdateInterval;
BaseDListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler);
@ -51,6 +52,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress();
mLastSaveTime = System.currentTimeMillis();
mUpdateInterval = manager.getDownloadConfig().getUpdateInterval();
}
@Override public void onPre() {
@ -123,6 +125,9 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
}
private void handleSpeed(long speed) {
if (mUpdateInterval != 1000) {
speed = speed * 1000 / mUpdateInterval;
}
if (isConvertSpeed) {
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
}

@ -99,6 +99,7 @@ public abstract class AbsGroupUtil implements IUtil {
int mInitFailNum = 0;
//任务组大小
int mGroupSize = 0;
long mUpdateInterval = 1000;
AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) {
mListener = listener;
@ -131,6 +132,8 @@ public abstract class AbsGroupUtil implements IUtil {
}
}
updateFileSize();
mUpdateInterval =
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval();
}
/**
@ -371,7 +374,7 @@ public abstract class AbsGroupUtil implements IUtil {
mListener.onProgress(mCurrentLocation);
}
}
}, 0, 1000);
}, 0, mUpdateInterval);
}
/**

@ -15,6 +15,7 @@
*/
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.AbsThreadTask;
import com.arialyy.aria.core.common.SubThreadConfig;
@ -39,6 +40,8 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
super(listener, taskEntity);
setUpdateInterval(
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval());
}
@Override protected void checkTask() {

@ -36,10 +36,6 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
* HTTP任务组下载
*/
public static final int DG_HTTP = 0x12;
/**
* HTTP单文件上传
*/
public static final int U_HTTP = 0xA1;
/**
* FTP单文件下载
@ -49,6 +45,11 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
* FTP文件夹下载为避免登录过多子任务由单线程进行处理
*/
public static final int D_FTP_DIR = 0x14;
/**
* HTTP单文件上传
*/
public static final int U_HTTP = 0xA1;
/**
* FTP单文件上传
*/

@ -41,6 +41,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
private boolean isConvertSpeed = false;
boolean isWait = false;
private long mLastSaveTime;
private long mUpdateInterval;
BaseUListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler);
@ -51,6 +52,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress();
mLastSaveTime = System.currentTimeMillis();
mUpdateInterval = manager.getUploadConfig().getUpdateInterval();
}
@Override public void onPre() {
@ -111,6 +113,9 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
}
private void handleSpeed(long speed) {
if (mUpdateInterval != 1000) {
speed = speed * 1000 / mUpdateInterval;
}
if (isConvertSpeed) {
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
}

@ -15,6 +15,7 @@
*/
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.AbsThreadTask;
import com.arialyy.aria.core.common.SubThreadConfig;
@ -35,6 +36,8 @@ class Uploader extends AbsFileer<UploadEntity, UploadTaskEntity> {
Uploader(IUploadListener listener, UploadTaskEntity taskEntity) {
super(listener, taskEntity);
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
- 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181
- 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182

@ -34,6 +34,9 @@
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
<queueMod value="wait"/>
<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>
</download>
<upload>
@ -54,6 +57,9 @@
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
<queueMod value="wait"/>
<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>
</upload>
</aria>

@ -157,6 +157,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
mStart.setText("开始");
setBtState(true);
getBinding().setSpeed("");
Log.d(TAG, "cancel");
}
@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.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.lang.reflect.Field;
@ -39,6 +40,11 @@ class Configuration {
* 通用配置
*/
public static class BaseConfig {
/**
* 进度刷新间隔默认1秒
*/
long updateInterval = 1000;
/**
* 旧任务数
*/
@ -73,6 +79,25 @@ class Configuration {
*/
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() {
return queueMod;
}

Loading…
Cancel
Save