AriaLyy 7 years ago
parent 7055093f7a
commit d22d7a3e6b
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 1
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  3. 35
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsDownloadTarget.java
  4. 1
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  5. 11
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java

@ -154,8 +154,8 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
@Override public void cancel() {
closeTimer();
mConstance.isCancel = true;
mConstance.isRunning = false;
mConstance.isCancel = true;
if (mFixedThreadPool != null) {
mFixedThreadPool.shutdown();
}

@ -134,6 +134,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) {
mEntity.setState(state);
mEntity.deleteData();
} else if (state == IEntity.STATE_COMPLETE) {
mEntity.setState(state);

@ -33,18 +33,27 @@ public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends
* key默认值为Content-MD5
* 获取md5信息{@link DownloadEntity#getMd5Code()}
*/
public void setHeaderMd5Key(String md5Key) {
if (TextUtils.isEmpty(md5Key)) return;
public TARGET setHeaderMd5Key(String md5Key) {
if (TextUtils.isEmpty(md5Key)) return (TARGET) this;
mTaskEntity.md5Key = md5Key;
if (TextUtils.isEmpty(mTaskEntity.md5Key) || !mTaskEntity.md5Key.equals(md5Key)) {
mTaskEntity.update();
}
return (TARGET) this;
}
/**
* 如果你的文件长度是放在header中那么你需要配置key来让Aria知道正确的文件长度
* key默认值为Content-Length
*/
public void setHeaderContentLengthKey(String contentLength) {
if (TextUtils.isEmpty(contentLength)) return;
public TARGET setHeaderContentLengthKey(String contentLength) {
if (TextUtils.isEmpty(contentLength)) return (TARGET) this;
mTaskEntity.contentLength = contentLength;
if (TextUtils.isEmpty(mTaskEntity.contentLength) || !mTaskEntity.contentLength.equals(
contentLength)) {
mTaskEntity.update();
}
return (TARGET) this;
}
/**
@ -52,9 +61,14 @@ public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends
* key默认值为Content-Disposition
* 获取文件描述信息{@link DownloadEntity#getDisposition()}
*/
public void setHeaderDispositionKey(String dispositionKey) {
if (TextUtils.isEmpty(dispositionKey)) return;
public TARGET setHeaderDispositionKey(String dispositionKey) {
if (TextUtils.isEmpty(dispositionKey)) return (TARGET) this;
mTaskEntity.dispositionKey = dispositionKey;
if (TextUtils.isEmpty(mTaskEntity.dispositionKey) || !mTaskEntity.dispositionKey.equals(
dispositionKey)) {
mTaskEntity.save();
}
return (TARGET) this;
}
/**
@ -62,9 +76,14 @@ public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends
* key默认值为attachment;filename
* 获取文件名信息{@link DownloadEntity#getServerFileName()}
*/
public void setHeaderDispositionFileKey(String dispositionFileKey) {
if (TextUtils.isEmpty(dispositionFileKey)) return;
public TARGET setHeaderDispositionFileKey(String dispositionFileKey) {
if (TextUtils.isEmpty(dispositionFileKey)) return (TARGET) this;
mTaskEntity.dispositionFileKey = dispositionFileKey;
if (TextUtils.isEmpty(mTaskEntity.dispositionFileKey) || !mTaskEntity.dispositionFileKey.equals(
dispositionFileKey)) {
mTaskEntity.save();
}
return (TARGET) this;
}
/**

@ -42,6 +42,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private static final String DOWNLOAD_URL =
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";

@ -93,7 +93,8 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
public synchronized void updateState(AbsEntity entity) {
if (entity.getState() == DownloadEntity.STATE_CANCEL) {
if (entity.getState() == IEntity.STATE_CANCEL) {
mData.remove(entity);
mPositions.clear();
int i = 0;
for (AbsEntity entity_1 : mData) {
@ -217,10 +218,10 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
private void handleSubChild(GroupHolder holder, final AbsEntity entity) {
if (holder.childList.getSubData().size() > 0){
holder.childList.updateChildProgress(((DownloadGroupEntity)entity).getSubTask());
}else {
holder.childList.addData(((DownloadGroupEntity)entity).getSubTask());
if (holder.childList.getSubData().size() > 0) {
holder.childList.updateChildProgress(((DownloadGroupEntity) entity).getSubTask());
} else {
holder.childList.addData(((DownloadGroupEntity) entity).getSubTask());
}
}

Loading…
Cancel
Save