parent
2ef9550d86
commit
1e5f01cbd8
@ -0,0 +1,60 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.core.download.wrapper; |
||||||
|
|
||||||
|
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||||
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; |
||||||
|
import com.arialyy.aria.core.download.DownloadTaskEntity; |
||||||
|
import com.arialyy.aria.orm.AbsWrapper; |
||||||
|
import com.arialyy.aria.orm.DbEntity; |
||||||
|
import com.arialyy.aria.orm.annotation.Many; |
||||||
|
import com.arialyy.aria.orm.annotation.One; |
||||||
|
import com.arialyy.aria.orm.annotation.Wrapper; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by laoyuyu on 2018/3/30. |
||||||
|
* 任务组实体和任务组任务实体的关系 |
||||||
|
*/ |
||||||
|
@Wrapper |
||||||
|
public class DGroupTaskEntityWrapper extends AbsWrapper { |
||||||
|
|
||||||
|
@One |
||||||
|
public DownloadGroupEntity entity; |
||||||
|
|
||||||
|
@Many(parentColumn = "groupName", entityColumn = "key") |
||||||
|
private List<DownloadGroupTaskEntity> taskEntitys; |
||||||
|
|
||||||
|
public DownloadGroupTaskEntity taskEntity; |
||||||
|
|
||||||
|
@Override protected void handleConvert() { |
||||||
|
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); |
||||||
|
if (taskEntity != null) { |
||||||
|
taskEntity.setEntity(entity); |
||||||
|
List<DownloadTaskWrapper> subWrappers = |
||||||
|
DbEntity.findRelationData(DownloadTaskWrapper.class, "DownloadTaskEntity.groupName=?", |
||||||
|
taskEntity.getKey()); |
||||||
|
if (subWrappers != null && !subWrappers.isEmpty()) { |
||||||
|
List<DownloadTaskEntity> temp = new ArrayList<>(); |
||||||
|
for (DownloadTaskWrapper dw : subWrappers) { |
||||||
|
temp.add(dw.taskEntity); |
||||||
|
} |
||||||
|
taskEntity.setSubTaskEntities(temp); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,162 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.core.manager; |
||||||
|
|
||||||
|
import com.arialyy.aria.core.download.DownloadEntity; |
||||||
|
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||||
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; |
||||||
|
import com.arialyy.aria.core.download.DownloadTaskEntity; |
||||||
|
import com.arialyy.aria.core.download.wrapper.DGroupEntityWrapper; |
||||||
|
import com.arialyy.aria.core.download.wrapper.DGroupTaskEntityWrapper; |
||||||
|
import com.arialyy.aria.orm.DbEntity; |
||||||
|
import com.arialyy.aria.util.CommonUtil; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Aria.Lao on 2017/11/1. |
||||||
|
* 任务实体工厂 |
||||||
|
*/ |
||||||
|
class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskEntity> { |
||||||
|
private static final String TAG = "DTEFactory"; |
||||||
|
private static volatile DGTEFactory INSTANCE = null; |
||||||
|
|
||||||
|
private DGTEFactory() { |
||||||
|
} |
||||||
|
|
||||||
|
public static DGTEFactory getInstance() { |
||||||
|
if (INSTANCE == null) { |
||||||
|
synchronized (DGTEFactory.class) { |
||||||
|
INSTANCE = new DGTEFactory(); |
||||||
|
} |
||||||
|
} |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
@Override public DownloadGroupTaskEntity getGTE(String groupName, List<String> urls) { |
||||||
|
DownloadGroupEntity entity = createDGroupEntity(groupName, urls); |
||||||
|
List<DGroupTaskEntityWrapper> wrapper = |
||||||
|
DbEntity.findRelationData(DGroupTaskEntityWrapper.class, "DownloadGroupTaskEntity.key=?", |
||||||
|
entity.getGroupName()); |
||||||
|
DownloadGroupTaskEntity gte; |
||||||
|
|
||||||
|
if (wrapper != null && !wrapper.isEmpty()) { |
||||||
|
gte = wrapper.get(0).taskEntity; |
||||||
|
if (gte == null) { |
||||||
|
// 创建新的任务组任务实体
|
||||||
|
gte = new DownloadGroupTaskEntity(); |
||||||
|
//创建子任务的任务实体
|
||||||
|
gte.setSubTaskEntities(createDGSubTaskEntity(entity)); |
||||||
|
} else if (gte.getSubTaskEntities() == null || gte.getSubTaskEntities().isEmpty()) { |
||||||
|
gte.setSubTaskEntities(createDGSubTaskEntity(entity)); |
||||||
|
} |
||||||
|
} else { |
||||||
|
gte = new DownloadGroupTaskEntity(); |
||||||
|
gte.setSubTaskEntities(createDGSubTaskEntity(entity)); |
||||||
|
} |
||||||
|
gte.setKey(entity.getGroupName()); |
||||||
|
gte.setEntity(entity); |
||||||
|
|
||||||
|
return gte; |
||||||
|
} |
||||||
|
|
||||||
|
@Override public DownloadGroupTaskEntity getFTE(String ftpUrl) { |
||||||
|
List<DGroupTaskEntityWrapper> wrapper = |
||||||
|
DbEntity.findRelationData(DGroupTaskEntityWrapper.class, "DownloadGroupTaskEntity.key=?", |
||||||
|
ftpUrl); |
||||||
|
DownloadGroupTaskEntity fte; |
||||||
|
|
||||||
|
if (wrapper != null && !wrapper.isEmpty()) { |
||||||
|
fte = wrapper.get(0).taskEntity; |
||||||
|
if (fte == null) { |
||||||
|
fte = new DownloadGroupTaskEntity(); |
||||||
|
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||||
|
dge.setGroupName(ftpUrl); |
||||||
|
fte.setEntity(dge); |
||||||
|
} else if (fte.getEntity() == null) { |
||||||
|
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||||
|
dge.setGroupName(ftpUrl); |
||||||
|
fte.setEntity(dge); |
||||||
|
} |
||||||
|
} else { |
||||||
|
fte = new DownloadGroupTaskEntity(); |
||||||
|
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||||
|
dge.setGroupName(ftpUrl); |
||||||
|
fte.setEntity(dge); |
||||||
|
} |
||||||
|
fte.setKey(ftpUrl); |
||||||
|
fte.urlEntity = CommonUtil.getFtpUrlInfo(ftpUrl); |
||||||
|
return fte; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建任务组子任务的任务实体 |
||||||
|
*/ |
||||||
|
private List<DownloadTaskEntity> createDGSubTaskEntity(DownloadGroupEntity dge) { |
||||||
|
List<DownloadTaskEntity> list = new ArrayList<>(); |
||||||
|
for (DownloadEntity entity : dge.getSubEntities()) { |
||||||
|
DownloadTaskEntity taskEntity = new DownloadTaskEntity(); |
||||||
|
taskEntity.entity = entity; |
||||||
|
taskEntity.key = entity.getDownloadPath(); |
||||||
|
taskEntity.groupName = dge.getKey(); |
||||||
|
taskEntity.isGroupTask = true; |
||||||
|
taskEntity.url = entity.getUrl(); |
||||||
|
list.add(taskEntity); |
||||||
|
} |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体 |
||||||
|
*/ |
||||||
|
private DownloadGroupEntity createDGroupEntity(String groupName, List<String> urls) { |
||||||
|
List<DGroupEntityWrapper> wrapper = |
||||||
|
DbEntity.findRelationData(DGroupEntityWrapper.class, "DownloadGroupEntity.groupName=?", |
||||||
|
groupName); |
||||||
|
|
||||||
|
DownloadGroupEntity groupEntity; |
||||||
|
if (wrapper != null && !wrapper.isEmpty()) { |
||||||
|
groupEntity = wrapper.get(0).groupEntity; |
||||||
|
if (groupEntity == null) { |
||||||
|
groupEntity = new DownloadGroupEntity(); |
||||||
|
groupEntity.setSubEntities(createSubTask(groupName, urls)); |
||||||
|
} |
||||||
|
} else { |
||||||
|
groupEntity = new DownloadGroupEntity(); |
||||||
|
groupEntity.setSubEntities(createSubTask(groupName, urls)); |
||||||
|
} |
||||||
|
groupEntity.setGroupName(groupName); |
||||||
|
groupEntity.setUrls(urls); |
||||||
|
return groupEntity; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建子任务 |
||||||
|
*/ |
||||||
|
private List<DownloadEntity> createSubTask(String groupName, List<String> urls) { |
||||||
|
List<DownloadEntity> list = new ArrayList<>(); |
||||||
|
for (int i = 0, len = urls.size(); i < len; i++) { |
||||||
|
DownloadEntity entity = new DownloadEntity(); |
||||||
|
entity.setUrl(urls.get(i)); |
||||||
|
entity.setDownloadPath(groupName + "_" + i); |
||||||
|
entity.setFileName(groupName + "_" + i); |
||||||
|
entity.setGroupName(groupName); |
||||||
|
entity.setGroupChild(true); |
||||||
|
list.add(entity); |
||||||
|
} |
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
@ -1,128 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
package com.arialyy.aria.core.manager; |
|
||||||
|
|
||||||
import android.text.TextUtils; |
|
||||||
import com.arialyy.aria.core.download.DownloadGroupEntity; |
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; |
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskWrapper; |
|
||||||
import com.arialyy.aria.core.download.DownloadGroupWrapper; |
|
||||||
import com.arialyy.aria.orm.DbEntity; |
|
||||||
import com.arialyy.aria.util.CommonUtil; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by Aria.Lao on 2017/11/1. |
|
||||||
* 任务实体工厂 |
|
||||||
*/ |
|
||||||
class DGTEntityFactory implements ITEntityFactory<DownloadGroupEntity, DownloadGroupTaskEntity>, |
|
||||||
IGTEntityFactory<DownloadGroupEntity, DownloadGroupTaskEntity> { |
|
||||||
private static final String TAG = "DTEntityFactory"; |
|
||||||
private static volatile DGTEntityFactory INSTANCE = null; |
|
||||||
|
|
||||||
private DGTEntityFactory() { |
|
||||||
} |
|
||||||
|
|
||||||
public static DGTEntityFactory getInstance() { |
|
||||||
if (INSTANCE == null) { |
|
||||||
synchronized (DGTEntityFactory.class) { |
|
||||||
INSTANCE = new DGTEntityFactory(); |
|
||||||
} |
|
||||||
} |
|
||||||
return INSTANCE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 通过下载实体创建任务实体 |
|
||||||
*/ |
|
||||||
private DownloadGroupTaskEntity create(DownloadGroupEntity entity) { |
|
||||||
List<DownloadGroupTaskWrapper> wrapper = |
|
||||||
DbEntity.findRelationData(DownloadGroupTaskWrapper.class, "DownloadGroupTaskWrapper.key=?", |
|
||||||
entity.getGroupName()); |
|
||||||
DownloadGroupTaskEntity dgTaskEntity; |
|
||||||
|
|
||||||
if (wrapper != null && !wrapper.isEmpty()) { |
|
||||||
dgTaskEntity = wrapper.get(0).taskEntity; |
|
||||||
if (dgTaskEntity == null) { |
|
||||||
dgTaskEntity = new DownloadGroupTaskEntity(); |
|
||||||
dgTaskEntity.setEntity(entity); |
|
||||||
} else if (dgTaskEntity.getEntity() == null || TextUtils.isEmpty( |
|
||||||
dgTaskEntity.getEntity().getKey())) { |
|
||||||
dgTaskEntity.setEntity(entity); |
|
||||||
} |
|
||||||
} else { |
|
||||||
dgTaskEntity = new DownloadGroupTaskEntity(); |
|
||||||
dgTaskEntity.setEntity(entity); |
|
||||||
} |
|
||||||
|
|
||||||
return dgTaskEntity; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 对于任务组,不能使用这个,该方法只用于FTP文件夹下载 |
|
||||||
* |
|
||||||
* @deprecated 任务组使用:{@link #create(String, List)} |
|
||||||
*/ |
|
||||||
@Override @Deprecated public DownloadGroupTaskEntity create(String key) { |
|
||||||
List<DownloadGroupTaskWrapper> wrapper = |
|
||||||
DbEntity.findRelationData(DownloadGroupTaskWrapper.class, "DownloadGroupTaskWrapper.key=?", |
|
||||||
key); |
|
||||||
DownloadGroupTaskEntity dgTaskEntity; |
|
||||||
if (wrapper != null && !wrapper.isEmpty()) { |
|
||||||
dgTaskEntity = wrapper.get(0).taskEntity; |
|
||||||
if (dgTaskEntity == null) { |
|
||||||
dgTaskEntity = new DownloadGroupTaskEntity(); |
|
||||||
dgTaskEntity.setEntity(getDownloadGroupEntity(key, null)); |
|
||||||
} else if (dgTaskEntity.getEntity() == null || TextUtils.isEmpty( |
|
||||||
dgTaskEntity.getEntity().getKey())) { |
|
||||||
dgTaskEntity.setEntity(getDownloadGroupEntity(key, null)); |
|
||||||
} |
|
||||||
dgTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(key); |
|
||||||
return dgTaskEntity; |
|
||||||
} else { |
|
||||||
dgTaskEntity = new DownloadGroupTaskEntity(); |
|
||||||
dgTaskEntity.setEntity(getDownloadGroupEntity(key, null)); |
|
||||||
dgTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(key); |
|
||||||
return dgTaskEntity; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override public DownloadGroupTaskEntity create(String groupName, List<String> urls) { |
|
||||||
return create(getDownloadGroupEntity(groupName, urls)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体 |
|
||||||
*/ |
|
||||||
private DownloadGroupEntity getDownloadGroupEntity(String groupName, List<String> urls) { |
|
||||||
|
|
||||||
List<DownloadGroupWrapper> wrapper = |
|
||||||
DbEntity.findRelationData(DownloadGroupWrapper.class, "DownloadGroupEntity.groupName=?", |
|
||||||
groupName); |
|
||||||
DownloadGroupEntity groupEntity; |
|
||||||
if (wrapper != null && !wrapper.isEmpty()) { |
|
||||||
groupEntity = wrapper.get(0).groupEntity; |
|
||||||
if (groupEntity == null) { |
|
||||||
groupEntity = new DownloadGroupEntity(); |
|
||||||
} |
|
||||||
} else { |
|
||||||
groupEntity = new DownloadGroupEntity(); |
|
||||||
} |
|
||||||
groupEntity.setGroupName(groupName); |
|
||||||
groupEntity.setUrls(urls); |
|
||||||
return groupEntity; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,92 @@ |
|||||||
|
package com.arialyy.simple.test; |
||||||
|
|
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Environment; |
||||||
|
import android.util.Log; |
||||||
|
import android.view.View; |
||||||
|
import com.arialyy.annotations.Download; |
||||||
|
import com.arialyy.aria.core.Aria; |
||||||
|
import com.arialyy.aria.core.common.RequestEnum; |
||||||
|
import com.arialyy.aria.core.download.DownloadTask; |
||||||
|
import com.arialyy.aria.util.CommonUtil; |
||||||
|
import com.arialyy.frame.util.show.L; |
||||||
|
import com.arialyy.simple.R; |
||||||
|
import com.arialyy.simple.base.BaseActivity; |
||||||
|
import com.arialyy.simple.databinding.ActivityTestBinding; |
||||||
|
import java.io.File; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Administrator on 2018/4/12. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class TestActivity extends BaseActivity<ActivityTestBinding> { |
||||||
|
String TAG = "TestActivity"; |
||||||
|
String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||||
|
|
||||||
|
@Override protected int setLayoutId() { |
||||||
|
return R.layout.activity_test; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected void init(Bundle savedInstanceState) { |
||||||
|
super.init(savedInstanceState); |
||||||
|
mBar.setVisibility(View.GONE); |
||||||
|
Aria.download(this).register(); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onWait void onWait(DownloadTask task) { |
||||||
|
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onPre protected void onPre(DownloadTask task) { |
||||||
|
Log.d(TAG, "onPre"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskStart void taskStart(DownloadTask task) { |
||||||
|
Log.d(TAG, "onStart"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskRunning protected void running(DownloadTask task) { |
||||||
|
Log.d(TAG, "running"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskResume void taskResume(DownloadTask task) { |
||||||
|
Log.d(TAG, "resume"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskStop void taskStop(DownloadTask task) { |
||||||
|
Log.d(TAG, "stop"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskCancel void taskCancel(DownloadTask task) { |
||||||
|
Log.d(TAG, "cancel"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskFail void taskFail(DownloadTask task) { |
||||||
|
Log.d(TAG, "fail"); |
||||||
|
} |
||||||
|
|
||||||
|
@Download.onTaskComplete void taskComplete(DownloadTask task) { |
||||||
|
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); |
||||||
|
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); |
||||||
|
} |
||||||
|
|
||||||
|
public void onClick(View view) { |
||||||
|
switch (view.getId()) { |
||||||
|
case R.id.start: |
||||||
|
Aria.download(this) |
||||||
|
.load(URL) |
||||||
|
.addHeader("Accept-Encoding", "gzip, deflate") |
||||||
|
.setRequestMode(RequestEnum.GET) |
||||||
|
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") |
||||||
|
.resetState() |
||||||
|
.start(); |
||||||
|
break; |
||||||
|
case R.id.stop: |
||||||
|
Aria.download(this).load(URL).stop(); |
||||||
|
break; |
||||||
|
case R.id.cancel: |
||||||
|
Aria.download(this).load(URL).cancel(); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
package com.arialyy.simple.test; |
||||||
|
|
||||||
|
import android.os.Bundle; |
||||||
|
import android.os.Environment; |
||||||
|
import android.view.View; |
||||||
|
import com.arialyy.annotations.DownloadGroup; |
||||||
|
import com.arialyy.aria.core.Aria; |
||||||
|
import com.arialyy.aria.core.download.DownloadGroupTask; |
||||||
|
import com.arialyy.frame.util.show.L; |
||||||
|
import com.arialyy.simple.R; |
||||||
|
import com.arialyy.simple.base.BaseActivity; |
||||||
|
import com.arialyy.simple.databinding.ActivityTestBinding; |
||||||
|
import com.arialyy.simple.download.group.GroupModule; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Administrator on 2018/4/12. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class TestGroupActivity extends BaseActivity<ActivityTestBinding> { |
||||||
|
List<String> mUrls; |
||||||
|
|
||||||
|
@Override protected int setLayoutId() { |
||||||
|
return R.layout.activity_test; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected void init(Bundle savedInstanceState) { |
||||||
|
super.init(savedInstanceState); |
||||||
|
mBar.setVisibility(View.GONE); |
||||||
|
Aria.download(this).register(); |
||||||
|
mUrls = getModule(GroupModule.class).getUrls(); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onWait void taskWait(DownloadGroupTask task) { |
||||||
|
L.d(TAG, task.getTaskName() + "wait"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group pre"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task pre"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task start"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task running"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task resume"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskStop() void taskStop(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task stop"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskCancel() void taskCancel(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task cancel"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskFail() void taskFail(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task fail"); |
||||||
|
} |
||||||
|
|
||||||
|
@DownloadGroup.onTaskComplete() void taskComplete(DownloadGroupTask task) { |
||||||
|
L.d(TAG, "group task complete"); |
||||||
|
} |
||||||
|
|
||||||
|
public void onClick(View view) { |
||||||
|
switch (view.getId()) { |
||||||
|
case R.id.start: |
||||||
|
Aria.download(this) |
||||||
|
.loadGroup(mUrls) |
||||||
|
.setDirPath(Environment.getExternalStorageDirectory().getPath() + "/download/test/") |
||||||
|
.resetState() |
||||||
|
.start(); |
||||||
|
break; |
||||||
|
case R.id.stop: |
||||||
|
Aria.download(this).loadGroup(mUrls).stop(); |
||||||
|
break; |
||||||
|
case R.id.cancel: |
||||||
|
Aria.download(this).loadGroup(mUrls).cancel(); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
<LinearLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:orientation="vertical" |
||||||
|
> |
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar |
||||||
|
android:id="@+id/toolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
/> |
||||||
|
|
||||||
|
<Button |
||||||
|
android:id="@+id/start" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:onClick="onClick" |
||||||
|
android:text="start" |
||||||
|
/> |
||||||
|
|
||||||
|
<Button |
||||||
|
android:id="@+id/stop" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:onClick="onClick" |
||||||
|
android:text="stop" |
||||||
|
/> |
||||||
|
|
||||||
|
<Button |
||||||
|
android:id="@+id/cancel" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:onClick="onClick" |
||||||
|
android:text="del" |
||||||
|
/> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
|
</layout> |
Loading…
Reference in new issue