diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java index e6d4ba6c..82796d94 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java @@ -140,8 +140,7 @@ public abstract class AbsThreadTask subTaskFileName) { + + return setSubFileName(subTaskFileName); + } + /** * 设置子任务文件名,该方法必须在{@link #setDownloadDirPath(String)}之后调用,否则不生效 */ - public TARGET setSubTaskFileName(List subTaskFileName) { + public TARGET setSubFileName(List subTaskFileName) { if (subTaskFileName == null || subTaskFileName.isEmpty()) return (TARGET) this; mSubTaskFileName.addAll(subTaskFileName); if (mUrls.size() != subTaskFileName.size()) { @@ -187,8 +197,8 @@ abstract class BaseGroupTarget createMultiTestList() { - String[] names = getContext().getResources().getStringArray(R.array.file_nams); - String[] downloadUrl = getContext().getResources().getStringArray(R.array.download_url); + String[] names = getStringArray(R.array.file_nams); + String[] downloadUrl = getStringArray(R.array.download_url); List list = new ArrayList<>(); int i = 0; for (String name : names) { FileListEntity entity = new FileListEntity(); entity.name = name; - entity.downloadUrl = downloadUrl[i]; + entity.key = downloadUrl[i]; entity.downloadPath = Environment.getExternalStorageDirectory() + "/Download/" + name; list.add(entity); i++; @@ -69,6 +71,33 @@ public class DownloadModule extends BaseModule { return list; } + private String[] getStringArray(int array) { + return getContext().getResources().getStringArray(array); + } + + /** + * 创建任务组 + */ + public List createGroupTestList() { + List list = new ArrayList<>(); + list.add(createGroupEntity(R.array.group_urls, R.array.group_names, "任务组_0")); + list.add(createGroupEntity(R.array.group_urls_1, R.array.group_names_1, "任务组_1")); + list.add(createGroupEntity(R.array.group_urls_2, R.array.group_names_2, "任务组_2")); + list.add(createGroupEntity(R.array.group_urls_3, R.array.group_names_3, "任务组_3")); + return list; + } + + private FileListEntity createGroupEntity(int urls, int names, String alias) { + FileListEntity entity = new FileListEntity(); + entity.urls = getStringArray(urls); + entity.names = getStringArray(names); + entity.isGroup = true; + entity.name = alias; + entity.key = CommonUtil.getMd5Code(Arrays.asList(entity.urls)); + entity.downloadPath = Environment.getExternalStorageDirectory() + "/Download/" + alias; + return entity; + } + /** * 创建下载实体,Aria也可以通过下载实体启动下载 */ @@ -80,5 +109,4 @@ public class DownloadModule extends BaseModule { entity.setDownloadPath(path); return entity; } - } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index c96d01cc..ac29dfa7 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -30,10 +30,13 @@ import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.util.CommonUtil; +import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivitySingleBinding; +import java.io.File; public class SingleTaskActivity extends BaseActivity { @@ -157,6 +160,7 @@ public class SingleTaskActivity extends BaseActivity { mCancel.setEnabled(false); setBtState(true); getBinding().setSpeed(""); + L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); } @Download.onNoSupportBreakPoint(DOWNLOAD_URL) diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java index e423f79a..d0b4df38 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java @@ -26,6 +26,7 @@ import com.arialyy.aria.core.Aria; import com.arialyy.simple.R; import com.arialyy.simple.base.adapter.AbsHolder; import com.arialyy.simple.base.adapter.AbsRVAdapter; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @@ -43,8 +44,8 @@ final class FileListAdapter extends AbsRVAdapter data) { super(context, data); for (int i = 0, len = data.size(); i < len; i++) { - mBtStates.put(data.get(i).downloadUrl, true); - mPositions.put(data.get(i).downloadUrl, i); + mBtStates.put(data.get(i).key, true); + mPositions.put(data.get(i).key, i); } } @@ -59,17 +60,27 @@ final class FileListAdapter extends AbsRVAdapter { super.init(savedInstanceState); Aria.download(this).register(); setTitle("多任务下载"); + mData.addAll(getModule(DownloadModule.class).createGroupTestList()); mData.addAll(getModule(DownloadModule.class).createMultiTestList()); mAdapter = new FileListAdapter(this, mData); mList.setLayoutManager(new LinearLayoutManager(this)); @@ -93,7 +94,32 @@ public class MultiTaskActivity extends BaseActivity { mAdapter.updateBtState(task.getKey(), true); } - @Download.onTaskComplete void taskComplete(DownloadTask task) { + //############################### 任务组 ############################## + @DownloadGroup.onTaskComplete void groupTaskComplete(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), true); + } + + @DownloadGroup.onTaskStart void groupTaskStart(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), false); + } + + @DownloadGroup.onTaskResume void groupTaskResume(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), false); + } + + @DownloadGroup.onTaskStop void groupTaskStop(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), true); + } + + @DownloadGroup.onTaskCancel void groupTaskCancel(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), true); + } + + @DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) { + mAdapter.updateBtState(task.getKey(), true); + } + + @DownloadGroup.onTaskComplete void taskComplete(DownloadGroupTask task) { mAdapter.updateBtState(task.getKey(), true); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d127bee..02bc4a8c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,10 +50,23 @@ - http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk + + + + http://droidweb.smartgame-down.com/201708171123/C183E9C2010C7CABACFB398250A3DB75/new/game1/1/107001/qq_1502875308555.apk?f=web_1 + http://droidweb.smartgame-down.com/201708171124/6E5AF91791661236D0A2F60125D3B45F/new/game1/93/113093/00D42A6AA63A039485F510C2E4D69BAA_1498831237.apk?f=web_1 + + + + http://droidweb.smartgame-down.com/201708171125/005BCF0FFBB75510958D14074286B25F/new/game1/2/106202/qqkj_1502868291416.apk?f=web_1 + http://droidweb.smartgame-down.com/201708171126/05FAAA4FD294BC63AA8F792636961D19/new/game1/72/110472/com.taobao.taobao-6.9.0-157-0629_1498744826.apk?f=web_1 + + + http://droidweb.smartgame-down.com/201708171127/F55445FD8B7BBA8D72CA4B7D7BD91F90/new/game1/84/33184/txtim_1502854269836.apk?f=web_1 + http://droidweb.smartgame-down.com/201708171128/5C4D0289F0B83690BF252420F473FB9F/new/game1/46/108046/com.shuqi.controller-10.5.2.50-137-0703_1499083244.apk?f=web_1 @@ -62,4 +75,19 @@ + + QQ.apk + 百度贴吧.apk + + + + QQ空间.apk + 淘宝.apk + + + + TIM.apk + 书旗小说.apk + +