..
This commit is contained in:
@ -29,31 +29,57 @@ import java.util.List;
|
|||||||
public class DownloadGroupTarget
|
public class DownloadGroupTarget
|
||||||
extends AbsGroupTarget<DownloadGroupTarget, DownloadGroupEntity, DownloadGroupTaskEntity> {
|
extends AbsGroupTarget<DownloadGroupTarget, DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||||
private List<String> mUrls;
|
private List<String> mUrls;
|
||||||
|
private String mGroupName;
|
||||||
|
|
||||||
DownloadGroupTarget(List<String> urls, String targetName) {
|
DownloadGroupTarget(List<String> urls, String targetName) {
|
||||||
this.mTargetName = targetName;
|
this.mTargetName = targetName;
|
||||||
this.mUrls = urls;
|
this.mUrls = urls;
|
||||||
mTaskEntity =
|
mGroupName = CommonUtil.getMd5Code(urls);
|
||||||
DbEntity.findData(DownloadGroupTaskEntity.class, "key=?", CommonUtil.getMd5Code(urls));
|
mTaskEntity = DbEntity.findData(DownloadGroupTaskEntity.class, "key=?", mGroupName);
|
||||||
if (mTaskEntity == null) {
|
if (mTaskEntity == null) {
|
||||||
mTaskEntity = new DownloadGroupTaskEntity();
|
mTaskEntity = new DownloadGroupTaskEntity();
|
||||||
|
mTaskEntity.key = mGroupName;
|
||||||
mTaskEntity.entity = new DownloadGroupEntity();
|
mTaskEntity.entity = new DownloadGroupEntity();
|
||||||
}
|
}
|
||||||
if (mTaskEntity.entity == null) {
|
if (mTaskEntity.entity == null) {
|
||||||
mTaskEntity.entity = getDownloadGroupEntity(urls);
|
mTaskEntity.entity = getDownloadGroupEntity();
|
||||||
}
|
}
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadGroupEntity getDownloadGroupEntity(List<String> urls) {
|
private DownloadGroupEntity getDownloadGroupEntity() {
|
||||||
DownloadGroupEntity entity =
|
DownloadGroupEntity entity =
|
||||||
DbEntity.findData(DownloadGroupEntity.class, "urlHash=?", CommonUtil.getMd5Code(urls));
|
DbEntity.findData(DownloadGroupEntity.class, "groupName=?", mGroupName);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
entity = new DownloadGroupEntity();
|
entity = new DownloadGroupEntity();
|
||||||
}
|
}
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置任务组的文件夹路径,在Aria中,任务组的所有子任务都会下载到以任务组组名的文件夹中。
|
||||||
|
* 如:groupDirPath = "/mnt/sdcard/download/", groupName = "group_test"
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* + mnt
|
||||||
|
* + sdcard
|
||||||
|
* + download
|
||||||
|
* + group_test
|
||||||
|
* - task1.apk
|
||||||
|
* - task2.apk
|
||||||
|
* - task3.apk
|
||||||
|
* ....
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param groupDirPath 任务组保存文件夹路径
|
||||||
|
*/
|
||||||
|
public DownloadGroupTarget setDownloadPath(String groupDirPath) {
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置保存路径组
|
* 设置保存路径组
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,7 @@ import java.util.concurrent.Executors;
|
|||||||
* 任务组下载工具
|
* 任务组下载工具
|
||||||
*/
|
*/
|
||||||
public class DownloadGroupUtil implements IDownloadUtil {
|
public class DownloadGroupUtil implements IDownloadUtil {
|
||||||
private static final String TAG = "DownloadGroupUtil";
|
private final String TAG = "DownloadGroupUtil";
|
||||||
/**
|
/**
|
||||||
* 任务组所有任务总大小
|
* 任务组所有任务总大小
|
||||||
*/
|
*/
|
||||||
|
@ -134,7 +134,7 @@ class Downloader implements Runnable, IDownloadUtil {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mEntity);
|
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mTaskEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void stopDownload() {
|
@Override public void stopDownload() {
|
||||||
|
@ -19,7 +19,16 @@ package com.arialyy.aria.core.inf;
|
|||||||
* Created by AriaL on 2017/6/29.
|
* Created by AriaL on 2017/6/29.
|
||||||
* 任务组超类
|
* 任务组超类
|
||||||
*/
|
*/
|
||||||
public abstract class AbsGroupTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
|
public abstract class AbsGroupTarget<TARGET extends AbsGroupTarget, ENTITY extends AbsGroupEntity, TASK_ENTITY extends AbsTaskEntity>
|
||||||
extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
|
extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置任务组的组名,如果不设置任务组,Aria会自动将任务组的所有子任务的key相加,取md5码作为任务组组名
|
||||||
|
*
|
||||||
|
* @param groupName 任务组组名
|
||||||
|
*/
|
||||||
|
public TARGET setGroupName(String groupName) {
|
||||||
|
mEntity.setGroupName(groupName);
|
||||||
|
return (TARGET) this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
|
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
|
||||||
<activity android:name=".download.HighestPriorityActivity"/>
|
<activity android:name=".download.HighestPriorityActivity"/>
|
||||||
<activity android:name=".test.TestMutilTaskSysDownload"/>
|
<activity android:name=".test.TestMutilTaskSysDownload"/>
|
||||||
|
<activity android:name=".download.group.DownloadGroupActivity"/>
|
||||||
|
|
||||||
<service android:name=".download.service_download.DownloadService"/>
|
<service android:name=".download.service_download.DownloadService"/>
|
||||||
</application>
|
</application>
|
||||||
|
@ -18,11 +18,8 @@ package com.arialyy.simple;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import butterknife.Bind;
|
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import com.arialyy.aria.core.Aria;
|
|
||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivityMainBinding;
|
import com.arialyy.simple.databinding.ActivityMainBinding;
|
||||||
import com.arialyy.simple.download.DownloadActivity;
|
import com.arialyy.simple.download.DownloadActivity;
|
||||||
@ -45,15 +42,20 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
|||||||
return R.layout.activity_main;
|
return R.layout.activity_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.download) public void downloadDemo() {
|
|
||||||
|
@OnClick({R.id.download, R.id.upload, R.id.download_task_group})
|
||||||
|
public void funcation(View view){
|
||||||
|
switch (view.getId()){
|
||||||
|
case R.id.download:
|
||||||
startActivity(new Intent(this, DownloadActivity.class));
|
startActivity(new Intent(this, DownloadActivity.class));
|
||||||
}
|
break;
|
||||||
|
case R.id.upload:
|
||||||
@OnClick(R.id.upload) public void uploadDemo() {
|
|
||||||
startActivity(new Intent(this, UploadActivity.class));
|
startActivity(new Intent(this, UploadActivity.class));
|
||||||
|
break;
|
||||||
|
case R.id.download_task_group:
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.multi_test) public void mutliTest() {
|
|
||||||
startActivity(new Intent(this, TestMutilTaskSysDownload.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.simple.download.group;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import com.arialyy.aria.core.Aria;
|
||||||
|
import com.arialyy.aria.core.download.DownloadTask;
|
||||||
|
import com.arialyy.aria.core.scheduler.AbsSchedulerListener;
|
||||||
|
import com.arialyy.simple.R;
|
||||||
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
|
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
|
||||||
|
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Aria.Lao on 2017/7/6.
|
||||||
|
*/
|
||||||
|
public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBinding> {
|
||||||
|
|
||||||
|
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
||||||
|
@Bind(R.id.start) Button mStart;
|
||||||
|
@Bind(R.id.stop) Button mStop;
|
||||||
|
@Bind(R.id.cancel) Button mCancel;
|
||||||
|
@Bind(R.id.size) TextView mSize;
|
||||||
|
@Bind(R.id.speed) TextView mSpeed;
|
||||||
|
List<String> mUrls;
|
||||||
|
|
||||||
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
|
super.init(savedInstanceState);
|
||||||
|
setTitle("任务组");
|
||||||
|
mUrls = getModule(GroupModule.class).getUrls();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected int setLayoutId() {
|
||||||
|
return R.layout.activity_download_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
//Aria.download(this).addSchedulerListener(new AbsSchedulerListener<DownloadTask>() {
|
||||||
|
//
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
|
||||||
|
//public void onClick(View view) {
|
||||||
|
// switch (view.getId()) {
|
||||||
|
// case R.id.start:
|
||||||
|
// String text = ((TextView) view).getText().toString();
|
||||||
|
// if (text.equals("重新开始?") || text.equals("开始")) {
|
||||||
|
// Aria.download(this)
|
||||||
|
// .load(mUrls)
|
||||||
|
// .setDownloadPaths()
|
||||||
|
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||||
|
// .start();
|
||||||
|
// } else if (text.equals("恢复")) {
|
||||||
|
// Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case R.id.stop:
|
||||||
|
// Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||||
|
// break;
|
||||||
|
// case R.id.cancel:
|
||||||
|
// Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.simple.download.group;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import com.arialyy.simple.R;
|
||||||
|
import com.arialyy.simple.base.BaseModule;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Aria.Lao on 2017/7/6.
|
||||||
|
*/
|
||||||
|
public class GroupModule extends BaseModule {
|
||||||
|
public GroupModule(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> getUrls() {
|
||||||
|
List<String> urls = new ArrayList<>();
|
||||||
|
String[] str = getContext().getResources().getStringArray(R.array.download_url);
|
||||||
|
Collections.addAll(urls, str);
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
//List<String> convertPath(List<String> urls){
|
||||||
|
// List<String> paths = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (String url : urls){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
18
app/src/main/res/layout/activity_download_group.xml
Normal file
18
app/src/main/res/layout/activity_download_group.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?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"
|
||||||
|
>
|
||||||
|
|
||||||
|
<include layout="@layout/layout_bar"/>
|
||||||
|
|
||||||
|
<include layout="@layout/content_single"/>
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</layout>
|
@ -13,7 +13,7 @@
|
|||||||
android:id="@+id/download"
|
android:id="@+id/download"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="下载 demo"
|
android:text="下载"
|
||||||
style="?buttonBarButtonStyle"
|
style="?buttonBarButtonStyle"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -21,15 +21,15 @@
|
|||||||
android:id="@+id/upload"
|
android:id="@+id/upload"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="上传 demo"
|
android:text="上传"
|
||||||
style="?buttonBarButtonStyle"
|
style="?buttonBarButtonStyle"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/multi_test"
|
android:id="@+id/download_task_group"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="多任务测试"
|
android:text="下载任务组"
|
||||||
style="?buttonBarButtonStyle"
|
style="?buttonBarButtonStyle"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -44,4 +44,18 @@
|
|||||||
<item>https://res5.d.cn/6f78ee3bcfdd033ef8e38596afb298d87de07e5f0f1f91f22acd57750f8ae68270531e2b266ea41c86cd196da839a0afef1952dde89773c7e26b9019249503174ca0513fa0a36a6472c4202bbf94da382964a0478471b753ebd95b67aac7ad89.apk</item>
|
<item>https://res5.d.cn/6f78ee3bcfdd033ef8e38596afb298d87de07e5f0f1f91f22acd57750f8ae68270531e2b266ea41c86cd196da839a0afef1952dde89773c7e26b9019249503174ca0513fa0a36a6472c4202bbf94da382964a0478471b753ebd95b67aac7ad89.apk</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="group_urls">
|
||||||
|
<item>http://img.sc115.com/uploads/allimg/110420/20110420225600154.jpg</item>
|
||||||
|
<item>https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQv8s5M31tFNvbjtGgxqmx14eh2h2651gkbrx-kN0cNYPD0qvRi</item>
|
||||||
|
<item>http://img03.tooopen.com/images/20130811/tooopen_15265353.jpg</item>
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
<!--<item></item>-->
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user