速度单位转换

pull/330/head
AriaLyy 8 years ago
parent aac060b9bb
commit c402dde329
  1. 2
      .idea/modules.xml
  2. 13
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  3. 15
      Aria/src/main/java/com/arialyy/aria/core/Configuration.java
  4. 27
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  5. 72
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  6. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  7. 11
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  8. 104
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  10. 2
      app/src/main/assets/aria_config.xml
  11. 6
      app/src/main/java/com/arialyy/simple/download/DownloadDialog.java
  12. 2
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  13. 2
      app/src/main/java/com/arialyy/simple/download/fragment_download/DownloadFragment.java
  14. 3
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  15. 4
      gradle.properties

@ -2,8 +2,8 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" /> <module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />

@ -80,10 +80,23 @@ public class ConfigHelper extends DefaultHandler {
String caPath = attributes.getValue("path"); String caPath = attributes.getValue("path");
loadCA(caName, caPath); loadCA(caName, caPath);
break; break;
case "convertSpeed":
loadConvertSpeed(value);
break;
} }
} }
} }
private void loadConvertSpeed(String value) {
boolean open = Boolean.parseBoolean(value);
if (isDownloadConfig) {
mDownloadConfig.isConvertSpeed = open;
}
if (isUploadConfig) {
mUploadConfig.isConvertSpeed = open;
}
}
private void loadReTryInterval(String value) { private void loadReTryInterval(String value) {
int time = 2 * 1000; int time = 2 * 1000;
if (!TextUtils.isEmpty(value)) { if (!TextUtils.isEmpty(value)) {

@ -63,6 +63,11 @@ class Configuration {
*/ */
int connectTimeOut = 5000; int connectTimeOut = 5000;
/**
* 是否需要转换速度单位转换完成后为1b/s1k/s1m/s1g/s1t/s如果不需要将返回byte长度
*/
boolean isConvertSpeed = false;
public boolean isOpenBreadCast() { public boolean isOpenBreadCast() {
return isOpenBreadCast; return isOpenBreadCast;
} }
@ -105,6 +110,16 @@ class Configuration {
return this; return this;
} }
public boolean isConvertSpeed() {
return isConvertSpeed;
}
public BaseConfig setConvertSpeed(boolean convertSpeed) {
isConvertSpeed = convertSpeed;
saveKey("isConvertSpeed", isConvertSpeed + "");
return this;
}
public int getConnectTimeOut() { public int getConnectTimeOut() {
return connectTimeOut; return connectTimeOut;
} }

@ -31,6 +31,7 @@ import com.arialyy.aria.orm.DbEntity;
*/ */
public class DownloadEntity extends DbEntity implements Parcelable, IEntity { public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
@Ignore private long speed = 0; //下载速度 @Ignore private long speed = 0; //下载速度
@Ignore private String convertSpeed = "0b/s";
@Ignore private int failNum = 0; @Ignore private int failNum = 0;
private String downloadUrl = ""; //下载路径 private String downloadUrl = ""; //下载路径
private String downloadPath = ""; //保存路径 private String downloadPath = ""; //保存路径
@ -43,19 +44,10 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
private long completeTime; //完成时间 private long completeTime; //完成时间
private boolean isRedirect = false; private boolean isRedirect = false;
private String redirectUrl = ""; //重定向链接 private String redirectUrl = ""; //重定向链接
private int threadNum; //下载线程数
public DownloadEntity() { public DownloadEntity() {
} }
public int getThreadNum() {
return threadNum;
}
public void setThreadNum(int threadNum) {
this.threadNum = threadNum;
}
public String getStr() { public String getStr() {
return str; return str;
} }
@ -131,6 +123,14 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
isDownloadComplete = downloadComplete; isDownloadComplete = downloadComplete;
} }
public String getConvertSpeed() {
return convertSpeed;
}
public void setConvertSpeed(String convertSpeed) {
this.convertSpeed = convertSpeed;
}
public long getSpeed() { public long getSpeed() {
return speed; return speed;
} }
@ -171,6 +171,9 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
return "DownloadEntity{" return "DownloadEntity{"
+ "speed=" + "speed="
+ speed + speed
+ ", convertSpeed='"
+ convertSpeed
+ '\''
+ ", failNum=" + ", failNum="
+ failNum + failNum
+ ", downloadUrl='" + ", downloadUrl='"
@ -200,8 +203,6 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
+ ", redirectUrl='" + ", redirectUrl='"
+ redirectUrl + redirectUrl
+ '\'' + '\''
+ ", threadNum="
+ threadNum
+ '}'; + '}';
} }
@ -211,6 +212,7 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
@Override public void writeToParcel(Parcel dest, int flags) { @Override public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.speed); dest.writeLong(this.speed);
dest.writeString(this.convertSpeed);
dest.writeInt(this.failNum); dest.writeInt(this.failNum);
dest.writeString(this.downloadUrl); dest.writeString(this.downloadUrl);
dest.writeString(this.downloadPath); dest.writeString(this.downloadPath);
@ -223,11 +225,11 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
dest.writeLong(this.completeTime); dest.writeLong(this.completeTime);
dest.writeByte(this.isRedirect ? (byte) 1 : (byte) 0); dest.writeByte(this.isRedirect ? (byte) 1 : (byte) 0);
dest.writeString(this.redirectUrl); dest.writeString(this.redirectUrl);
dest.writeInt(this.threadNum);
} }
protected DownloadEntity(Parcel in) { protected DownloadEntity(Parcel in) {
this.speed = in.readLong(); this.speed = in.readLong();
this.convertSpeed = in.readString();
this.failNum = in.readInt(); this.failNum = in.readInt();
this.downloadUrl = in.readString(); this.downloadUrl = in.readString();
this.downloadPath = in.readString(); this.downloadPath = in.readString();
@ -240,7 +242,6 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
this.completeTime = in.readLong(); this.completeTime = in.readLong();
this.isRedirect = in.readByte() != 0; this.isRedirect = in.readByte() != 0;
this.redirectUrl = in.readString(); this.redirectUrl = in.readString();
this.threadNum = in.readInt();
} }
@Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() { @Ignore public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() {

@ -40,32 +40,53 @@ public class DownloadTask implements ITask {
*/ */
private String mTargetName; private String mTargetName;
private DownloadEntity mEntity; private DownloadEntity mEntity;
private DownloadTaskEntity mTaskEntity;
private IDownloadListener mListener; private IDownloadListener mListener;
private Handler mOutHandler; private Handler mOutHandler;
private IDownloadUtil mUtil; private IDownloadUtil mUtil;
private Context mContext; private Context mContext;
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
mTaskEntity = taskEntity;
mEntity = taskEntity.downloadEntity; mEntity = taskEntity.downloadEntity;
mOutHandler = outHandler; mOutHandler = outHandler;
mContext = AriaManager.APP; mContext = AriaManager.APP;
init();
}
private void init() {
mListener = new DListener(mContext, this, mOutHandler); mListener = new DListener(mContext, this, mOutHandler);
mUtil = new DownloadUtil(mContext, mTaskEntity, mListener); mUtil = new DownloadUtil(mContext, taskEntity, mListener);
} }
/** /**
* 获取下载速度 * @return 返回原始byte速度需要你在配置文件中配置
* <pre>
* <download>
* ...
* <convertSpeed value="false"/>
* </download>
*
* 或在代码中设置
* Aria.get(this).getDownloadConfig().setConvertSpeed(false);
* </pre>
* 才能生效
*/ */
@Override public long getSpeed() { @Override public long getSpeed() {
return mEntity.getSpeed(); return mEntity.getSpeed();
} }
/**
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1k/s1m/s1g/s1t/s
* <pre>
* <download>
* ...
* <convertSpeed value="true"/>
* </download>
*
* 或在代码中设置
* Aria.get(this).getDownloadConfig().setConvertSpeed(true);
* </pre>
* 才能生效
*/
@Override public String getConvertSpeed() {
return mEntity.getConvertSpeed();
}
/** /**
* 获取文件大小 * 获取文件大小
*/ */
@ -182,7 +203,6 @@ public class DownloadTask implements ITask {
public static class Builder { public static class Builder {
DownloadTaskEntity taskEntity; DownloadTaskEntity taskEntity;
Handler outHandler; Handler outHandler;
int threadNum = 3;
String targetName; String targetName;
public Builder(String targetName, DownloadTaskEntity taskEntity) { public Builder(String targetName, DownloadTaskEntity taskEntity) {
@ -201,14 +221,6 @@ public class DownloadTask implements ITask {
return this; return this;
} }
/**
* 设置线程数
*/
public Builder setThreadNum(int threadNum) {
this.threadNum = threadNum;
return this;
}
public DownloadTask build() { public DownloadTask build() {
DownloadTask task = new DownloadTask(taskEntity, outHandler); DownloadTask task = new DownloadTask(taskEntity, outHandler);
task.setTargetName(targetName); task.setTargetName(targetName);
@ -225,7 +237,6 @@ public class DownloadTask implements ITask {
WeakReference<DownloadTask> wTask; WeakReference<DownloadTask> wTask;
Context context; Context context;
Intent sendIntent; Intent sendIntent;
long INTERVAL = 1024 * 10; //10k大小的间隔
long lastLen = 0; //上一次发送长度 long lastLen = 0; //上一次发送长度
long lastTime = 0; long lastTime = 0;
long INTERVAL_TIME = 1000; //1m更新周期 long INTERVAL_TIME = 1000; //1m更新周期
@ -233,6 +244,7 @@ public class DownloadTask implements ITask {
DownloadEntity downloadEntity; DownloadEntity downloadEntity;
DownloadTask task; DownloadTask task;
boolean isOpenBroadCast = false; boolean isOpenBroadCast = false;
boolean isConvertSpeed = false;
DListener(Context context, DownloadTask task, Handler outHandler) { DListener(Context context, DownloadTask task, Handler outHandler) {
this.context = context; this.context = context;
@ -242,7 +254,9 @@ public class DownloadTask implements ITask {
this.downloadEntity = this.task.getDownloadEntity(); this.downloadEntity = this.task.getDownloadEntity();
sendIntent = CommonUtil.createIntent(context.getPackageName(), Aria.ACTION_RUNNING); sendIntent = CommonUtil.createIntent(context.getPackageName(), Aria.ACTION_RUNNING);
sendIntent.putExtra(Aria.ENTITY, downloadEntity); sendIntent.putExtra(Aria.ENTITY, downloadEntity);
isOpenBroadCast = AriaManager.getInstance(context).getDownloadConfig().isOpenBreadCast(); final AriaManager manager = AriaManager.getInstance(context);
isOpenBroadCast = manager.getDownloadConfig().isOpenBreadCast();
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
} }
@Override public void supportBreakpoint(boolean support) { @Override public void supportBreakpoint(boolean support) {
@ -289,11 +303,10 @@ public class DownloadTask implements ITask {
sendIntent.putExtra(Aria.CURRENT_SPEED, speed); sendIntent.putExtra(Aria.CURRENT_SPEED, speed);
lastTime = System.currentTimeMillis(); lastTime = System.currentTimeMillis();
if (isFirst) { if (isFirst) {
downloadEntity.setSpeed(0); speed = 0;
isFirst = false; isFirst = false;
} else {
downloadEntity.setSpeed(speed);
} }
handleSpeed(speed);
downloadEntity.setCurrentProgress(currentLocation); downloadEntity.setCurrentProgress(currentLocation);
lastLen = currentLocation; lastLen = currentLocation;
sendInState2Target(DownloadSchedulers.RUNNING); sendInState2Target(DownloadSchedulers.RUNNING);
@ -304,7 +317,7 @@ public class DownloadTask implements ITask {
@Override public void onStop(long stopLocation) { @Override public void onStop(long stopLocation) {
super.onStop(stopLocation); super.onStop(stopLocation);
downloadEntity.setState(DownloadEntity.STATE_STOP); downloadEntity.setState(DownloadEntity.STATE_STOP);
downloadEntity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.STOP); sendInState2Target(DownloadSchedulers.STOP);
sendIntent(Aria.ACTION_STOP, stopLocation); sendIntent(Aria.ACTION_STOP, stopLocation);
} }
@ -312,6 +325,7 @@ public class DownloadTask implements ITask {
@Override public void onCancel() { @Override public void onCancel() {
super.onCancel(); super.onCancel();
downloadEntity.setState(DownloadEntity.STATE_CANCEL); downloadEntity.setState(DownloadEntity.STATE_CANCEL);
handleSpeed(0);
sendInState2Target(DownloadSchedulers.CANCEL); sendInState2Target(DownloadSchedulers.CANCEL);
sendIntent(Aria.ACTION_CANCEL, -1); sendIntent(Aria.ACTION_CANCEL, -1);
downloadEntity.deleteData(); downloadEntity.deleteData();
@ -321,7 +335,7 @@ public class DownloadTask implements ITask {
super.onComplete(); super.onComplete();
downloadEntity.setState(DownloadEntity.STATE_COMPLETE); downloadEntity.setState(DownloadEntity.STATE_COMPLETE);
downloadEntity.setDownloadComplete(true); downloadEntity.setDownloadComplete(true);
downloadEntity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.COMPLETE); sendInState2Target(DownloadSchedulers.COMPLETE);
sendIntent(Aria.ACTION_COMPLETE, downloadEntity.getFileSize()); sendIntent(Aria.ACTION_COMPLETE, downloadEntity.getFileSize());
} }
@ -330,11 +344,19 @@ public class DownloadTask implements ITask {
super.onFail(); super.onFail();
downloadEntity.setFailNum(downloadEntity.getFailNum() + 1); downloadEntity.setFailNum(downloadEntity.getFailNum() + 1);
downloadEntity.setState(DownloadEntity.STATE_FAIL); downloadEntity.setState(DownloadEntity.STATE_FAIL);
downloadEntity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.FAIL); sendInState2Target(DownloadSchedulers.FAIL);
sendIntent(Aria.ACTION_FAIL, -1); sendIntent(Aria.ACTION_FAIL, -1);
} }
private void handleSpeed(long speed) {
if (isConvertSpeed) {
downloadEntity.setConvertSpeed(CommonUtil.formatFileSize(speed) + "/s");
} else {
downloadEntity.setSpeed(speed);
}
}
/** /**
* 将任务状态发送给下载器 * 将任务状态发送给下载器
* *

@ -44,8 +44,16 @@ public interface ITask {
public void cancel(); public void cancel();
/**
* 原始byte速度
*/
public long getSpeed(); public long getSpeed();
/**
* 转换单位后的速度
*/
public String getConvertSpeed();
public long getFileSize(); public long getFileSize();
public long getCurrentProgress(); public long getCurrentProgress();

@ -34,8 +34,17 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable {
private long currentProgress = 0; private long currentProgress = 0;
private boolean isComplete = false; private boolean isComplete = false;
@Ignore private long speed = 0; //下载速度 @Ignore private long speed = 0; //下载速度
@Ignore private String convertSpeed = "0/s";
@Ignore private int failNum = 0; @Ignore private int failNum = 0;
public String getConvertSpeed() {
return convertSpeed;
}
public void setConvertSpeed(String convertSpeed) {
this.convertSpeed = convertSpeed;
}
public boolean isComplete() { public boolean isComplete() {
return isComplete; return isComplete;
} }
@ -115,6 +124,7 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable {
dest.writeLong(this.currentProgress); dest.writeLong(this.currentProgress);
dest.writeByte(this.isComplete ? (byte) 1 : (byte) 0); dest.writeByte(this.isComplete ? (byte) 1 : (byte) 0);
dest.writeLong(this.speed); dest.writeLong(this.speed);
dest.writeString(this.convertSpeed);
dest.writeInt(this.failNum); dest.writeInt(this.failNum);
} }
@ -126,6 +136,7 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable {
this.currentProgress = in.readLong(); this.currentProgress = in.readLong();
this.isComplete = in.readByte() != 0; this.isComplete = in.readByte() != 0;
this.speed = in.readLong(); this.speed = in.readLong();
this.convertSpeed = in.readString();
this.failNum = in.readInt(); this.failNum = in.readInt();
} }

@ -36,19 +36,17 @@ import java.lang.ref.WeakReference;
public class UploadTask implements ITask { public class UploadTask implements ITask {
private static final String TAG = "UploadTask"; private static final String TAG = "UploadTask";
private Handler mOutHandler; private Handler mOutHandler;
private UploadTaskEntity mTaskEntity;
private UploadEntity mUploadEntity; private UploadEntity mUploadEntity;
private String mTargetName; private String mTargetName;
private UploadUtil mUtil; private UploadUtil mUtil;
private UListener mListener; private UListener mListener;
UploadTask(UploadTaskEntity taskEntity, Handler outHandler) { private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) {
mTaskEntity = taskEntity;
mOutHandler = outHandler; mOutHandler = outHandler;
mUploadEntity = mTaskEntity.uploadEntity; mUploadEntity = taskEntity.uploadEntity;
mListener = new UListener(mOutHandler, this); mListener = new UListener(mOutHandler, this);
mUtil = new UploadUtil(mTaskEntity, mListener); mUtil = new UploadUtil(taskEntity, mListener);
} }
@Override public void setTargetName(String targetName) { @Override public void setTargetName(String targetName) {
@ -110,10 +108,41 @@ public class UploadTask implements ITask {
return mTargetName; return mTargetName;
} }
/**
* @return 返回原始byte速度需要你在配置文件中配置
* <pre>
* <upload>
* ...
* <convertSpeed value="false"/>
* </upload>
*
* 或在代码中设置
* Aria.get(this).getUploadConfig().setConvertSpeed(false);
* </pre>
* 才能生效
*/
@Override public long getSpeed() { @Override public long getSpeed() {
return mUploadEntity.getSpeed(); return mUploadEntity.getSpeed();
} }
/**
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1k/s1m/s1g/s1t/s
* <pre>
* <upload>
* ...
* <convertSpeed value="true"/>
* </upload>
*
* 或在代码中设置
* Aria.get(this).getUploadConfig().setConvertSpeed(true);
* </pre>
*
* 才能生效
*/
@Override public String getConvertSpeed() {
return mUploadEntity.getConvertSpeed();
}
@Override public long getFileSize() { @Override public long getFileSize() {
return mUploadEntity.getFileSize(); return mUploadEntity.getFileSize();
} }
@ -129,43 +158,46 @@ public class UploadTask implements ITask {
long lastTime = 0; long lastTime = 0;
long INTERVAL_TIME = 1000; //1m更新周期 long INTERVAL_TIME = 1000; //1m更新周期
boolean isFirst = true; boolean isFirst = true;
UploadEntity entity; UploadEntity uploadEntity;
Intent sendIntent; Intent sendIntent;
boolean isOpenBroadCast = false; boolean isOpenBroadCast = false;
boolean isConvertSpeed = false;
Context context; Context context;
UListener(Handler outHandle, UploadTask task) { UListener(Handler outHandle, UploadTask task) {
this.outHandler = new WeakReference<>(outHandle); this.outHandler = new WeakReference<>(outHandle);
this.task = new WeakReference<>(task); this.task = new WeakReference<>(task);
entity = this.task.get().getUploadEntity(); uploadEntity = this.task.get().getUploadEntity();
sendIntent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_RUNNING); sendIntent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_RUNNING);
sendIntent.putExtra(Aria.ENTITY, entity); sendIntent.putExtra(Aria.ENTITY, uploadEntity);
context = AriaManager.APP; context = AriaManager.APP;
isOpenBroadCast = AriaManager.getInstance(context).getUploadConfig().isOpenBreadCast(); final AriaManager manager = AriaManager.getInstance(context);
isOpenBroadCast = manager.getUploadConfig().isOpenBreadCast();
isConvertSpeed = manager.getUploadConfig().isConvertSpeed();
} }
@Override public void onPre() { @Override public void onPre() {
entity.setState(IEntity.STATE_PRE); uploadEntity.setState(IEntity.STATE_PRE);
sendIntent(Aria.ACTION_PRE, -1); sendIntent(Aria.ACTION_PRE, -1);
sendInState2Target(ISchedulers.PRE); sendInState2Target(ISchedulers.PRE);
} }
@Override public void onStart(long fileSize) { @Override public void onStart(long fileSize) {
entity.setFileSize(fileSize); uploadEntity.setFileSize(fileSize);
entity.setState(IEntity.STATE_RUNNING); uploadEntity.setState(IEntity.STATE_RUNNING);
sendIntent(Aria.ACTION_PRE, -1); sendIntent(Aria.ACTION_PRE, -1);
sendInState2Target(ISchedulers.START); sendInState2Target(ISchedulers.START);
} }
@Override public void onResume(long resumeLocation) { @Override public void onResume(long resumeLocation) {
entity.setState(DownloadEntity.STATE_RUNNING); uploadEntity.setState(DownloadEntity.STATE_RUNNING);
sendInState2Target(DownloadSchedulers.RESUME); sendInState2Target(DownloadSchedulers.RESUME);
sendIntent(Aria.ACTION_RESUME, resumeLocation); sendIntent(Aria.ACTION_RESUME, resumeLocation);
} }
@Override public void onStop(long stopLocation) { @Override public void onStop(long stopLocation) {
entity.setState(DownloadEntity.STATE_STOP); uploadEntity.setState(DownloadEntity.STATE_STOP);
entity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.STOP); sendInState2Target(DownloadSchedulers.STOP);
sendIntent(Aria.ACTION_STOP, stopLocation); sendIntent(Aria.ACTION_STOP, stopLocation);
} }
@ -177,12 +209,11 @@ public class UploadTask implements ITask {
sendIntent.putExtra(Aria.CURRENT_SPEED, speed); sendIntent.putExtra(Aria.CURRENT_SPEED, speed);
lastTime = System.currentTimeMillis(); lastTime = System.currentTimeMillis();
if (isFirst) { if (isFirst) {
entity.setSpeed(0); speed = 0;
isFirst = false; isFirst = false;
} else {
entity.setSpeed(speed);
} }
entity.setCurrentProgress(currentLocation); handleSpeed(speed);
uploadEntity.setCurrentProgress(currentLocation);
lastLen = currentLocation; lastLen = currentLocation;
sendInState2Target(DownloadSchedulers.RUNNING); sendInState2Target(DownloadSchedulers.RUNNING);
AriaManager.APP.sendBroadcast(sendIntent); AriaManager.APP.sendBroadcast(sendIntent);
@ -190,28 +221,37 @@ public class UploadTask implements ITask {
} }
@Override public void onCancel() { @Override public void onCancel() {
entity.setState(DownloadEntity.STATE_CANCEL); uploadEntity.setState(DownloadEntity.STATE_CANCEL);
handleSpeed(0);
sendInState2Target(DownloadSchedulers.CANCEL); sendInState2Target(DownloadSchedulers.CANCEL);
sendIntent(Aria.ACTION_CANCEL, -1); sendIntent(Aria.ACTION_CANCEL, -1);
entity.deleteData(); uploadEntity.deleteData();
} }
@Override public void onComplete() { @Override public void onComplete() {
entity.setState(DownloadEntity.STATE_COMPLETE); uploadEntity.setState(DownloadEntity.STATE_COMPLETE);
entity.setComplete(true); uploadEntity.setComplete(true);
entity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.COMPLETE); sendInState2Target(DownloadSchedulers.COMPLETE);
sendIntent(Aria.ACTION_COMPLETE, entity.getFileSize()); sendIntent(Aria.ACTION_COMPLETE, uploadEntity.getFileSize());
} }
@Override public void onFail() { @Override public void onFail() {
entity.setFailNum(entity.getFailNum() + 1); uploadEntity.setFailNum(uploadEntity.getFailNum() + 1);
entity.setState(DownloadEntity.STATE_FAIL); uploadEntity.setState(DownloadEntity.STATE_FAIL);
entity.setSpeed(0); handleSpeed(0);
sendInState2Target(DownloadSchedulers.FAIL); sendInState2Target(DownloadSchedulers.FAIL);
sendIntent(Aria.ACTION_FAIL, -1); sendIntent(Aria.ACTION_FAIL, -1);
} }
private void handleSpeed(long speed) {
if (isConvertSpeed) {
uploadEntity.setConvertSpeed(CommonUtil.formatFileSize(speed) + "/s");
} else {
uploadEntity.setSpeed(speed);
}
}
/** /**
* 将任务状态发送给下载器 * 将任务状态发送给下载器
* *
@ -224,12 +264,12 @@ public class UploadTask implements ITask {
} }
private void sendIntent(String action, long location) { private void sendIntent(String action, long location) {
entity.setComplete(action.equals(Aria.ACTION_COMPLETE)); uploadEntity.setComplete(action.equals(Aria.ACTION_COMPLETE));
entity.setCurrentProgress(location); uploadEntity.setCurrentProgress(location);
entity.update(); uploadEntity.update();
if (!isOpenBroadCast) return; if (!isOpenBroadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action); Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
intent.putExtra(Aria.ENTITY, entity); intent.putExtra(Aria.ENTITY, uploadEntity);
if (location != -1) { if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location); intent.putExtra(Aria.CURRENT_LOCATION, location);
} }

@ -28,7 +28,7 @@ import java.util.Map;
public class DBConfig { public class DBConfig {
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 3; static int VERSION = 2;
static { static {
if (TextUtils.isEmpty(DB_NAME)) { if (TextUtils.isEmpty(DB_NAME)) {

@ -32,7 +32,7 @@
<ca name="" path=""/> <ca name="" path=""/>
<!--是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度--> <!--是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度-->
<cnvertSpeed value="false"/> <convertSpeed value="true"/>
</download> </download>

@ -110,14 +110,14 @@ public class DownloadDialog extends AbsDialog {
@Override public void onTaskStop(DownloadTask task) { @Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task); super.onTaskStop(task);
setBtState(true); setBtState(true);
mSpeed.setText("0.0kb/s"); mSpeed.setText(task.getConvertSpeed());
} }
@Override public void onTaskCancel(DownloadTask task) { @Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task); super.onTaskCancel(task);
setBtState(true); setBtState(true);
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText("0.0kb/s"); mSpeed.setText(task.getConvertSpeed());
} }
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
@ -129,7 +129,7 @@ public class DownloadDialog extends AbsDialog {
} else { } else {
mPb.setProgress((int) ((current * 100) / len)); mPb.setProgress((int) ((current * 100) / len));
} }
mSpeed.setText(CommonUtil.formatFileSize(task.getSpeed()) + "/s"); mSpeed.setText(task.getConvertSpeed());
} }
} }
} }

@ -91,7 +91,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} else { } else {
mPb.setProgress((int) ((current * 100) / len)); mPb.setProgress((int) ((current * 100) / len));
} }
mSpeed.setText(CommonUtil.formatFileSize(task.getSpeed()) + "/s"); mSpeed.setText(task.getConvertSpeed());
break; break;
case DOWNLOAD_PRE: case DOWNLOAD_PRE:
mSize.setText(CommonUtil.formatFileSize((Long) msg.obj)); mSize.setText(CommonUtil.formatFileSize((Long) msg.obj));

@ -134,7 +134,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
} else { } else {
mPb.setProgress((int) ((current * 100) / len)); mPb.setProgress((int) ((current * 100) / len));
} }
mSpeed.setText(CommonUtil.formatFileSize(task.getSpeed()) + "/s"); mSpeed.setText(task.getConvertSpeed());
} }
} }
} }

@ -103,7 +103,6 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
long size = item.getFileSize(); long size = item.getFileSize();
int current = 0; int current = 0;
long progress = item.getCurrentProgress(); long progress = item.getCurrentProgress();
long speed = item.getSpeed();
current = size == 0 ? 0 : (int) (progress * 100 / size); current = size == 0 ? 0 : (int) (progress * 100 / size);
holder.progress.setProgress(current); holder.progress.setProgress(current);
BtClickListener listener = new BtClickListener(item); BtClickListener listener = new BtClickListener(item);
@ -136,7 +135,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
} }
holder.bt.setText(str); holder.bt.setText(str);
holder.bt.setTextColor(getColor(color)); holder.bt.setTextColor(getColor(color));
holder.speed.setText(CommonUtil.formatFileSize(speed) + "/s"); holder.speed.setText(item.getConvertSpeed());
holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size)); holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size));
holder.cancel.setOnClickListener(new View.OnClickListener() { holder.cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { @Override public void onClick(View v) {

@ -13,7 +13,3 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
#Wed Dec 07 20:19:22 CST 2016 #Wed Dec 07 20:19:22 CST 2016
systemProp.http.proxyPassword=7RbgsDfOoBn
systemProp.http.proxyHost=hilton.h.xduotai.com
systemProp.http.proxyUser=duotai
systemProp.http.proxyPort=10969

Loading…
Cancel
Save