修复组合任务单线程下载过程中应用被杀,文件变大的问题

pull/330/head
laoyuyu 6 years ago
parent 671ae11e2b
commit 3c05d8cafc
  1. 240
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 106
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 16
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  4. 5
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  7. 9
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  10. 2
      app/src/main/AndroidManifest.xml
  11. 59
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  12. 3
      app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java
  13. 4
      app/src/main/res/values/strings.xml
  14. 2
      build.gradle

@ -109,6 +109,28 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
startFlow();
}
/**
* 重置任务状态
*/
private void resetState() {
closeTimer();
mCompleteThreadNum = 0;
mTotalThreadNum = 0;
mStartThreadNum = 0;
if (mFixedThreadPool != null) {
mFixedThreadPool.shutdown();
}
if (mTask != null && !mTask.isEmpty()) {
for (int i = 0; i < mTask.size(); i++) {
AbsThreadTask task = mTask.get(i);
if (task != null && !task.isRunning()) {
task.breakTask();
}
}
mTask.clear();
}
}
/**
* 开始流程
*/
@ -116,8 +138,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (isBreak()) {
return;
}
resetState();
mConstance.resetState();
checkRecord();
mConstance.isRunning = true;
mConstance.TASK_RECORD = mRecord;
if (mListener instanceof IDownloadListener) {
((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
@ -281,67 +305,109 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
initRecord(true);
} else if (mRecord.isBlock) {
final int threadNum = mRecord.threadRecords.size();
final long blockLen = mEntity.getFileSize() / threadNum;
int i = 0;
for (ThreadRecord tr : mRecord.threadRecords) {
File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId));
if (!temp.exists()) {
ALog.w(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false;
tr.startLocation = -1;
mStartThreadNum++;
} else {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
long realLocation = i * blockLen + temp.length();
ALog.w(TAG, String.format(
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s",
tr.startLocation, tr.endLocation, blockLen, temp.length(), i));
if (tr.endLocation == realLocation) {
ALog.d(TAG, String.format("分块【%s】已完成,更新记录", temp.getPath()));
tr.startLocation = realLocation;
tr.isComplete = true;
mCompleteThreadNum++;
} else {
tr.isComplete = false;
if (realLocation < tr.startLocation) {
ALog.w(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
tr.startLocation = realLocation;
} else if (realLocation > tr.endLocation) {
ALog.w(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
temp.delete();
tr.startLocation = i * blockLen;
}
mStartThreadNum++;
}
}
}
i++;
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
handleBlockRecord();
} else {
File file = new File(mRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));
mRecord.deleteData();
initRecord(true);
return;
}
for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
mStartThreadNum++;
handleNormalRecord();
}
}
}
}
/**
* 处理普通任务的记录
*/
private void handleNormalRecord() {
File file = new File(mRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));
mRecord.deleteData();
initRecord(true);
return;
}
if (mRecord.isOpenDynamicFile) {
ThreadRecord tr = mRecord.threadRecords.get(0);
if (tr == null) {
mTaskEntity.setNewTask(true);
mTotalThreadNum = 1;
return;
}
if (file.length() > mEntity.getFileSize()) {
ALog.i(TAG, String.format("文件【%s】错误,任务重新开始", file.getPath()));
file.delete();
tr.startLocation = 0;
tr.isComplete = false;
tr.endLocation = mEntity.getFileSize();
mStartThreadNum++;
} else if (file.length() == mEntity.getFileSize()) {
tr.isComplete = true;
mCompleteThreadNum++;
} else {
if (file.length() != tr.startLocation) {
ALog.i(TAG, String.format("修正【%s】的进度记录为:%s", file.getPath(), file.length()));
tr.startLocation = file.length();
tr.isComplete = false;
mStartThreadNum++;
}
}
} else {
for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
mStartThreadNum++;
}
}
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
}
/**
* 处理分块任务的记录
*/
private void handleBlockRecord() {
final int threadNum = mRecord.threadRecords.size();
final long blockLen = mEntity.getFileSize() / threadNum;
int i = 0;
for (ThreadRecord tr : mRecord.threadRecords) {
File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId));
if (!temp.exists()) {
ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false;
tr.startLocation = -1;
mStartThreadNum++;
} else {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
long realLocation = i * blockLen + temp.length();
ALog.i(TAG, String.format(
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s",
tr.startLocation, tr.endLocation, blockLen, temp.length(), i));
if (tr.endLocation == realLocation) {
ALog.d(TAG, String.format("分块【%s】已完成,更新记录", temp.getPath()));
tr.startLocation = realLocation;
tr.isComplete = true;
mCompleteThreadNum++;
} else {
tr.isComplete = false;
if (realLocation < tr.startLocation) {
ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
tr.startLocation = realLocation;
} else if (realLocation > tr.endLocation) {
ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
temp.delete();
tr.startLocation = i * blockLen;
}
mStartThreadNum++;
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
}
}
i++;
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
}
/**
@ -463,7 +529,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private AbsThreadTask createSingThreadTask(int i, long startL, long endL, long fileLength,
ThreadRecord record) {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
config.FILE_SIZE = fileLength;
config.TOTAL_FILE_SIZE = fileLength;
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE =
mRecord.isBlock ? new File(String.format(SUB_PATH, mTempFile.getPath(), i)) : mTempFile;
@ -566,34 +632,36 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 重试线程任务只有线程创建成功才能重试
* 重试任务
*/
public void retryThreadTask() {
if (isBreak()) {
return;
}
if (mTask == null || mTask.size() == 0) {
ALog.w(TAG, "没有线程任务");
return;
}
Set<Integer> keys = mTask.keySet();
for (Integer key : keys) {
AbsThreadTask task = mTask.get(key);
if (task != null && !task.isThreadComplete()) {
task.getConfig().START_LOCATION = task.getConfig().THREAD_RECORD.startLocation;
mConstance.resetState();
startTimer();
ALog.d(TAG, String.format("任务【%s】开始重试,线程__%s__【开始位置:%s,结束位置:%s】", mEntity.getFileName(),
key, task.getConfig().START_LOCATION, task.getConfig().END_LOCATION));
if (!mFixedThreadPool.isShutdown()) {
mFixedThreadPool.execute(task);
} else {
ALog.w(TAG, "线程池已关闭");
mListener.onFail(true);
}
}
}
public void retryTask() {
ALog.w(TAG, String.format("任务【%s】开始重试", mEntity.getFileName()));
startFlow();
//if (isBreak()) {
// return;
//}
//if (mTask == null || mTask.size() == 0) {
// ALog.w(TAG, "没有线程任务");
// return;
//}
//Set<Integer> keys = mTask.keySet();
//for (Integer key : keys) {
// AbsThreadTask task = mTask.get(key);
// if (task != null && !task.isThreadComplete()) {
//
// task.getConfig().START_LOCATION = task.getConfig().THREAD_RECORD.startLocation;
// mConstance.resetState();
// startTimer();
// ALog.d(TAG, String.format("任务【%s】开始重试,线程__%s__【开始位置:%s,结束位置:%s】", mEntity.getFileName(),
// key, task.getConfig().START_LOCATION, task.getConfig().END_LOCATION));
// if (!mFixedThreadPool.isShutdown()) {
// mFixedThreadPool.execute(task);
// } else {
// ALog.w(TAG, "线程池已关闭");
// mListener.onFail(true);
// }
// }
//}
}
/**
@ -608,17 +676,17 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/
private void handleNoSupportBP() {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
config.FILE_SIZE = mEntity.getFileSize();
config.TOTAL_FILE_SIZE = mEntity.getFileSize();
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE = mTempFile;
config.THREAD_ID = 0;
config.START_LOCATION = 0;
config.END_LOCATION = config.FILE_SIZE;
config.END_LOCATION = config.TOTAL_FILE_SIZE;
config.SUPPORT_BP = mTaskEntity.isSupportBP();
config.TASK_ENTITY = mTaskEntity;
ThreadRecord record = new ThreadRecord();
record.startLocation = 0;
record.endLocation = config.FILE_SIZE;
record.endLocation = config.TOTAL_FILE_SIZE;
record.key = mTempFile.getPath();
config.THREAD_RECORD = record;
AbsThreadTask task = selectThreadTask(config);

@ -104,6 +104,52 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return mConfig.THREAD_RECORD.isComplete;
}
/**
* 获取任务记录
*/
public TaskRecord getTaskRecord() {
return STATE.TASK_RECORD;
}
/**
* 获取线程记录
*/
public ThreadRecord getThreadRecord() {
return mConfig.THREAD_RECORD;
}
/**
* 中断任务
*/
public void breakTask() {
synchronized (AriaManager.LOCK) {
taskBreak = true;
if (mConfig.SUPPORT_BP) {
final long currentTemp = mChildCurrentLocation;
STATE.STOP_NUM++;
ALog.d(TAG, String.format("任务【%s】thread__%s__中断【停止位置:%s】", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID, currentTemp));
writeConfig(false, currentTemp);
if (STATE.isStop()) {
ALog.i(TAG, String.format("任务【%s】已中断", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false;
}
} else {
ALog.i(TAG, String.format("任务【%s】已中断", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false;
}
}
}
/**
* 是否在运行
*
* @return {@code true}正在运行
*/
public boolean isRunning() {
return STATE.isRunning;
}
/**
* 获取线程配置信息
*/
@ -250,7 +296,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
synchronized (AriaManager.LOCK) {
if (ex != null) {
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
//ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
} else {
ALog.e(TAG, msg);
}
@ -280,7 +326,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mConfig.THREAD_ID));
}
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
|| isNotNetRetry) && isBreak()) {
|| isNotNetRetry) && !isBreak()) {
mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() {
@Override public void run() {
@ -291,8 +337,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mFailTimes++;
ALog.w(TAG, String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID));
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
: mConfig.THREAD_RECORD.startLocation;
handleRetryRecord();
AbsThreadTask.this.run();
}
}, RETRY_INTERVAL);
@ -301,6 +346,44 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
}
}
/**
* 处理线程重试的记录只有多线程任务才会执行
*/
private void handleRetryRecord() {
if (getTaskRecord().isBlock) {
ThreadRecord tr = getThreadRecord();
long block = mEntity.getFileSize() / getTaskRecord().threadRecords.size();
File file = mConfig.TEMP_FILE;
if (file.length() > tr.endLocation) {
ALog.i(TAG, String.format("分块【%s】错误,将重新下载该分块", file.getPath()));
boolean b = file.delete();
ALog.w(TAG, "删除:" + b);
tr.startLocation = block * tr.threadId;
tr.isComplete = false;
mConfig.START_LOCATION = tr.startLocation;
} else if (file.length() == tr.endLocation) {
STATE.COMPLETE_THREAD_NUM++;
tr.isComplete = true;
} else {
tr.startLocation = file.length();
mConfig.START_LOCATION = file.length();
tr.isComplete = false;
long size = 0;
for (int i = 0, len = getTaskRecord().threadRecords.size(); i < len; i++) {
File temp = new File(String.format(AbsFileer.SUB_PATH, getTaskRecord().filePath, i));
if (temp.exists()) {
size += file.length();
}
}
STATE.CURRENT_LOCATION = size;
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s", file.getPath(), tr.startLocation));
}
} else {
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
: mConfig.THREAD_RECORD.startLocation;
}
}
/**
* 处理失败状态
*
@ -328,12 +411,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
*/
protected void writeConfig(boolean isComplete, final long record) {
synchronized (AriaManager.LOCK) {
if (mConfig.THREAD_RECORD != null) {
mConfig.THREAD_RECORD.isComplete = isComplete;
if (0 < record && record < mConfig.END_LOCATION) {
mConfig.THREAD_RECORD.startLocation = record;
ThreadRecord tr = getThreadRecord();
if (tr != null) {
tr.isComplete = isComplete;
if (getTaskRecord().isBlock || getTaskRecord().isOpenDynamicFile) {
tr.startLocation = mConfig.TEMP_FILE.length();
} else {
if (0 < record && record < mConfig.END_LOCATION) {
tr.startLocation = record;
}
}
mConfig.THREAD_RECORD.update();
tr.update();
}
}
}

@ -109,14 +109,26 @@ public class ProxyHelper {
try {
if (Class.forName(className.concat("$$DownloadGroupListenerProxy")) != null) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP);
} else if (Class.forName(className.concat("$$DownloadListenerProxy")) != null) {
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
try {
if (Class.forName(className.concat("$$DownloadListenerProxy")) != null) {
result.add(PROXY_TYPE_DOWNLOAD);
} else if (Class.forName(className.concat("$$UploadListenerProxy")) != null) {
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
try {
if (Class.forName(className.concat("$$UploadListenerProxy")) != null) {
result.add(PROXY_TYPE_UPLOAD);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
if (!result.isEmpty()) {
mProxyCache.put(clazz.getName(), result);
}

@ -40,10 +40,13 @@ public class StateConstance {
public void resetState() {
isCancel = false;
isStop = false;
isRunning = true;
isRunning = false;
CANCEL_NUM = 0;
STOP_NUM = 0;
FAIL_NUM = 0;
COMPLETE_THREAD_NUM = 0;
START_THREAD_NUM = 0;
CURRENT_LOCATION = 0;
}
/**

@ -9,8 +9,8 @@ import java.io.File;
public class SubThreadConfig<TASK_ENTITY extends AbsTaskEntity> {
//线程Id
public int THREAD_ID;
//下载文件大小
public long FILE_SIZE;
//文件总长度
public long TOTAL_FILE_SIZE;
//子线程启动下载位置
public long START_LOCATION;
//子线程结束下载位置

@ -170,7 +170,7 @@ public class DownloadReceiver extends AbsReceiver {
}
}
} else {
ALog.i(TAG, "没有Aria的注解方法");
ALog.w(TAG, "没有Aria的注解方法");
}
}

@ -275,6 +275,7 @@ public abstract class AbsGroupUtil implements IUtil {
*/
protected void onPre() {
mListener.onPre();
isRunning = true;
mGroupSize = mGTEntity.getSubTaskEntities().size();
mTotalLen = mGTEntity.getEntity().getFileSize();
isNeedLoadFileSize = mTotalLen <= 10;
@ -492,20 +493,22 @@ public abstract class AbsGroupUtil implements IUtil {
subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0);
reTry(needRetry);
//reTry(needRetry);
reTry(false);
}
/**
* 重试下载只有全部都下载失败才会执行任务组的整体重试否则只会执行单个子任务的重试
*/
private void reTry(boolean needRetry) {
Downloader dt = mDownloaderMap.get(subEntity.getUrl());
synchronized (AbsGroupUtil.LOCK) {
Downloader dt = mDownloaderMap.get(subEntity.getUrl());
if (!isCancel && !isStop && dt != null
&& !dt.isBreak()
&& needRetry
&& subEntity.getFailNum() < 3
&& (NetUtils.isConnected(AriaManager.APP) || isNotNetRetry)) {
ALog.d(TAG, "downloader retry");
reStartTask(dt);
} else {
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
@ -531,7 +534,7 @@ public abstract class AbsGroupUtil implements IUtil {
timer.schedule(new TimerTask() {
@Override public void run() {
if (dt != null) {
dt.retryThreadTask();
dt.retryTask();
}
}
}, 5000);

@ -163,6 +163,10 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
*/
private void checkStartFlow() {
synchronized (DownloadGroupUtil.class) {
if (isStop) {
closeTimer();
return;
}
if (mInitFailNum == mExeNum) {
closeTimer();
mListener.onFail(true);

@ -60,7 +60,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
}
@Override public void run() {
if (mConfig.THREAD_RECORD.isComplete) {
if (getThreadRecord().isComplete) {
handleComplete();
return;
}

@ -14,10 +14,10 @@
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"-->
<!--android:name="com.arialyy.simple.test.AnyRunActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<activity
android:name=".download.group.DownloadGroupActivity"
android:label="@string/app_name">

@ -46,7 +46,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
super.init(savedInstanceState);
Aria.download(this).register();
setTitle("任务组");
mUrls = getModule(GroupModule.class).getUrls2();
mUrls = getModule(GroupModule.class).getUrls1();
DownloadGroupTaskEntity entity = Aria.download(this).getGroupTask(mUrls);
if (entity != null && entity.getEntity() != null) {
DownloadGroupEntity groupEntity = entity.getEntity();
@ -83,9 +83,11 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this)
.loadGroup(mUrls)
.setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_5")
//Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_5")
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_1")
.setGroupAlias("任务组测试")
.setSubFileName(getModule(GroupModule.class).getSubName2())
//.setSubFileName(getModule(GroupModule.class).getSubName2())
.setSubFileName(getModule(GroupModule.class).getSubName())
//.setFileSize(32895492)
.start();
break;
@ -134,12 +136,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
}
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
//Log.d(TAG, "group running, p = "
// + task.getPercent()
// + ", speed = "
// + task.getConvertSpeed()
// + "current_p = "
// + task.getCurrentProgress());
Log.d(TAG, "group running, p = "
+ task.getPercent()
+ ", speed = "
+ task.getConvertSpeed()
+ "current_p = "
+ task.getCurrentProgress());
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
//Log.d(TAG, "sub_len = " + task.getEntity().getSubEntities().size());
@ -175,26 +177,25 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
//ALog.d(TAG, "sub_percent = " + subEntity.getPercent());
Log.e(TAG, "gHash = "
+ groupTask.getEntity().getSubEntities().get(0).hashCode()
+ "; subHash = "
+ groupTask.getTaskEntity().getSubTaskEntities().get(0).getEntity().hashCode() +
"; subHash = " + subEntity.hashCode());
int percent = subEntity.getPercent();
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
String convertSpeed = subEntity.getConvertSpeed();
//当前下载完成的进度,长度bytes
long completedSize = subEntity.getCurrentProgress();
Log.d(TAG, "subTask名字:"
+ subEntity.getFileName()
+ ", "
+ " speed:"
+ convertSpeed
+ ",percent: "
+ percent
+ "%, completedSize:"
+ completedSize);
//Log.e(TAG, "gHash = "
// + groupTask.getEntity().getSubEntities().get(0).hashCode()
// + "; subHash = "
// + groupTask.getTaskEntity().getSubTaskEntities().get(0).getEntity().hashCode() +
// "; subHash = " + subEntity.hashCode());
//int percent = subEntity.getPercent();
////如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
//String convertSpeed = subEntity.getConvertSpeed();
////当前下载完成的进度,长度bytes
//long completedSize = subEntity.getCurrentProgress();
//Log.d(TAG, "subTask名字:"
// + subEntity.getFileName()
// + ", "
// + " speed:"
// + convertSpeed
// + ",percent: "
// + percent
// + "%, completedSize:"
// + completedSize);
}
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,

@ -35,7 +35,7 @@ import java.util.WeakHashMap;
* Created by Aria.Lao on 2017/7/17.
*/
public class SubStateLinearLayout extends LinearLayout implements View.OnClickListener {
private final String TAG = "SubStateLinearLayout";
interface OnShowCallback {
void onShow(boolean visibility);
}
@ -106,7 +106,6 @@ public class SubStateLinearLayout extends LinearLayout implements View.OnClickLi
if (position != -1) {
TextView child = ((TextView) getChildAt(position));
int p = getPercent(entity);
Log.d("TAG", "p = " + p);
child.setText(entity.getFileName() + ": " + p + "%" + " | " + entity.getConvertSpeed());
child.invalidate();
}

@ -60,7 +60,7 @@
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>
<!--<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>-->
</string-array>
<string-array name="group_urls_1">
@ -87,7 +87,7 @@
<string-array name="group_names">
<!--<item>王者荣耀.apk</item>-->
<item>战斗吧剑灵.apk</item>
<item>天魔幻想.apk</item>
<!--<item>天魔幻想.apk</item>-->
</string-array>
<string-array name="group_names_1">

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.4.6_dev2'
publishVersion = '3.4.6_dev3'
// publishVersion = '1.0.3' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save