最高优先级任务功能实现,demo修改
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
<activity android:name=".download.multi_download.MultiTaskActivity"/>
|
||||
<activity android:name=".download.fragment_download.FragmentActivity"/>
|
||||
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
|
||||
<activity android:name=".download.HighestPriorityActivity"/>
|
||||
|
||||
<service android:name=".download.service_download.DownloadService"/>
|
||||
</application>
|
||||
|
@ -31,7 +31,7 @@
|
||||
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
|
||||
<ca name="" path=""/>
|
||||
|
||||
<!--是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度-->
|
||||
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
|
||||
<convertSpeed value="true"/>
|
||||
|
||||
</download>
|
||||
|
@ -33,11 +33,11 @@ import com.arialyy.simple.upload.UploadActivity;
|
||||
*/
|
||||
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("Aria Demo");
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
|
@ -18,15 +18,21 @@ package com.arialyy.simple.base;
|
||||
|
||||
import android.databinding.ViewDataBinding;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.frame.core.AbsActivity;
|
||||
import com.arialyy.frame.util.AndroidVersionUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.common.MsgDialog;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB> {
|
||||
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB>
|
||||
implements Toolbar.OnMenuItemClickListener {
|
||||
|
||||
@Bind(R.id.toolbar) protected Toolbar mBar;
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -35,11 +41,36 @@ public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivi
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
mBar.setOnMenuItemClickListener(this);
|
||||
}
|
||||
|
||||
protected void setTile(String title){
|
||||
mBar.setTitle(title);
|
||||
}
|
||||
|
||||
protected void showMsgDialog(String title, String msg){
|
||||
MsgDialog dialog = new MsgDialog(this, title, msg);
|
||||
dialog.show(getSupportFragmentManager(), "msg_dialog");
|
||||
}
|
||||
|
||||
@Override public boolean onMenuItemClick(MenuItem item) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
}
|
38
app/src/main/java/com/arialyy/simple/common/MsgDialog.java
Normal file
38
app/src/main/java/com/arialyy/simple/common/MsgDialog.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.arialyy.simple.common;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseDialog;
|
||||
import com.arialyy.simple.databinding.DialogMsgBinding;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/3.
|
||||
*/
|
||||
@SuppressLint("ValidFragment") public class MsgDialog extends BaseDialog<DialogMsgBinding> {
|
||||
|
||||
private String mTitle, mMsg;
|
||||
|
||||
public MsgDialog(Object obj, String title, String msg) {
|
||||
super(obj);
|
||||
mTitle = title;
|
||||
mMsg = msg;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
getBinding().setTitle(mTitle);
|
||||
getBinding().setMsg(mMsg);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.dialog_msg;
|
||||
}
|
||||
|
||||
@OnClick(R.id.enter)
|
||||
public void close(){
|
||||
dismiss();
|
||||
}
|
||||
}
|
@ -39,7 +39,6 @@ import com.arialyy.simple.download.service_download.DownloadService;
|
||||
* Created by Lyy on 2016/10/13.
|
||||
*/
|
||||
public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding> {
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
@Bind(R.id.single_task) Button mSigleBt;
|
||||
@Bind(R.id.multi_task) Button mMultiBt;
|
||||
@Bind(R.id.dialog_task) Button mDialogBt;
|
||||
@ -51,8 +50,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多线程多任务下载");
|
||||
setTitle("Aria下载");
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
setEnable(true);
|
||||
} else { //6.0处理
|
||||
@ -85,6 +83,9 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.highest_priority:
|
||||
startActivity(new Intent(this, HighestPriorityActivity.class));
|
||||
break;
|
||||
case R.id.service:
|
||||
startService(new Intent(this, DownloadService.class));
|
||||
break;
|
||||
@ -100,7 +101,6 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
|
||||
break;
|
||||
case R.id.pop_task:
|
||||
DownloadPopupWindow pop = new DownloadPopupWindow(this);
|
||||
//pop.showAsDropDown(mRootView);
|
||||
pop.showAtLocation(mRootView, Gravity.CENTER_VERTICAL, 0, 0);
|
||||
break;
|
||||
case R.id.fragment_task:
|
||||
|
@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
@ -33,6 +34,7 @@ import com.arialyy.simple.download.multi_download.FileListEntity;
|
||||
import com.arialyy.simple.base.BaseModule;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@ -40,39 +42,29 @@ import java.util.Random;
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class DownloadModule extends BaseModule {
|
||||
private List<String> mTestDownloadUrl = new ArrayList<>();
|
||||
|
||||
public DownloadModule(Context context) {
|
||||
super(context);
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载列表
|
||||
* 最高优先级任务测试列表
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadTaskList() {
|
||||
return Aria.download(getContext()).getTaskList();
|
||||
}
|
||||
|
||||
public String getRadomUrl() {
|
||||
Random random = new Random();
|
||||
int i = random.nextInt(2);
|
||||
return mTestDownloadUrl.get(i);
|
||||
}
|
||||
|
||||
public DownloadEntity createRandomDownloadEntity() {
|
||||
return createDownloadEntity(getRadomUrl());
|
||||
public List<DownloadEntity> getHighestTestList() {
|
||||
List<DownloadEntity> list = new LinkedList<>();
|
||||
Resources res = getContext().getResources();
|
||||
String[] urls = res.getStringArray(R.array.highest_urls);
|
||||
String[] names = res.getStringArray(R.array.highest_names);
|
||||
for (int i = 0, len = urls.length; i < len; i++) {
|
||||
list.add(createDownloadEntity(urls[i], names[i]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建下载地址
|
||||
*/
|
||||
public List<FileListEntity> createFileList() {
|
||||
public List<FileListEntity> createMultiTestList() {
|
||||
String[] names = getContext().getResources().getStringArray(R.array.file_nams);
|
||||
String[] downloadUrl = getContext().getResources().getStringArray(R.array.download_url);
|
||||
List<FileListEntity> list = new ArrayList<>();
|
||||
@ -89,70 +81,17 @@ public class DownloadModule extends BaseModule {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载数据
|
||||
* 创建下载实体,Aria也可以通过下载实体启动下载
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadData() {
|
||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
for (String url : urls) {
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(url);
|
||||
if (entity == null) {
|
||||
entity = createDownloadEntity(url);
|
||||
}
|
||||
list.add(entity);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤任务
|
||||
*
|
||||
* @param sqlEntity 数据库的下载实体
|
||||
* @param createdEntity 通过下载链接生成的下载实体
|
||||
*/
|
||||
private List<DownloadEntity> filter(List<DownloadEntity> sqlEntity,
|
||||
List<DownloadEntity> createdEntity) {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
list.addAll(sqlEntity);
|
||||
for (DownloadEntity cEntity : createdEntity) {
|
||||
int count = 0;
|
||||
for (DownloadEntity sEntity : sqlEntity) {
|
||||
if (cEntity.getDownloadUrl().equals(sEntity.getDownloadUrl())) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
if (count == createdEntity.size()) {
|
||||
list.add(cEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private DownloadEntity createDownloadEntity(String url) {
|
||||
String fileName = CommonUtil.keyToHashCode(url) + ".apk";
|
||||
private DownloadEntity createDownloadEntity(String downloadUrl, String name) {
|
||||
String path = Environment.getExternalStorageDirectory() + "/download/" + name + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
//entity.setFileName("taskName_________" + i);
|
||||
entity.setFileName(name);
|
||||
entity.setDownloadUrl(downloadUrl);
|
||||
entity.setDownloadPath(path);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建下载列表
|
||||
*/
|
||||
private List<DownloadEntity> createNewDownload() {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
int i = 0;
|
||||
for (String url : urls) {
|
||||
list.add(createDownloadEntity(url));
|
||||
i++;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载广播过滤器
|
||||
*/
|
||||
@ -218,18 +157,4 @@ public class DownloadModule extends BaseModule {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载队列
|
||||
*/
|
||||
private String getDownloadPath(String url) {
|
||||
String path =
|
||||
Environment.getExternalStorageDirectory().getPath() + "/" + AndroidUtils.getAppName(
|
||||
getContext()) + "downloads/" + StringUtil.keyToHashKey(url) + ".apk";
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
@ -4,20 +4,27 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
|
||||
import com.arialyy.simple.download.multi_download.DownloadAdapter;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/6/2.
|
||||
@ -29,14 +36,15 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@Bind(R.id.cancel) Button mCancel;
|
||||
@Bind(R.id.size) TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
@Bind(R.id.speed) TextView mSpeed;
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
|
||||
private String mTaskName = "狂野飙车8";
|
||||
private String mTaskName = "光明大陆";
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://static.gaoshouyou.com/d/82/ff/df82ed0af4ff4c1746cb191cf765aa8f.apk";
|
||||
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
|
||||
private DownloadAdapter mAdapter;
|
||||
private List<DownloadEntity> mData = new ArrayList<>();
|
||||
private Set<String> mRecord = new HashSet<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_highest_priority;
|
||||
@ -44,17 +52,27 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setTitle("最高优先级任务演示");
|
||||
getBinding().setTaskName("任务名:" + mTaskName + " (该任务是最高优先级任务)");
|
||||
setTitle("最高优先级任务演示");
|
||||
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
|
||||
initWidget();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
|
||||
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) {
|
||||
mStart.setText("恢复");
|
||||
}
|
||||
}
|
||||
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadTaskList());
|
||||
List<DownloadEntity> temp = Aria.download(this).getTaskList();
|
||||
if (temp != null && !temp.isEmpty()) {
|
||||
for (DownloadEntity entity : temp) {
|
||||
if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue;
|
||||
mData.add(entity);
|
||||
mRecord.add(entity.getDownloadUrl());
|
||||
}
|
||||
}
|
||||
mAdapter = new DownloadAdapter(this, mData);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
@ -64,6 +82,41 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_highest_priority, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_task:
|
||||
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
|
||||
for (DownloadEntity entity : temp) {
|
||||
String url = entity.getDownloadUrl();
|
||||
if (mRecord.contains(url)) {
|
||||
continue;
|
||||
}
|
||||
mAdapter.addDownloadEntity(entity);
|
||||
mRecord.add(url);
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case R.id.help:
|
||||
String title = "最高优先级任务介绍";
|
||||
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
|
||||
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
|
||||
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
|
||||
+ " 3、任务调度器不会暂停最高优先级任务\n"
|
||||
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
|
||||
+ " 5、如果下载队列中已经满了,则会停止队尾的任务\n"
|
||||
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
|
||||
showMsgDialog(title, msg);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
@ -99,45 +152,46 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onPre(DownloadTask task) {
|
||||
super.onPre(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mSize.setText(task.getConvertFileSize());
|
||||
} else {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
} else {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
} else {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
} else {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mStart.setText("恢复");
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
} else {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskFail(DownloadTask task) {
|
||||
@ -152,16 +206,15 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
} else {
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Speed;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
@ -66,7 +67,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@Bind(R.id.cancel) Button mCancel;
|
||||
@Bind(R.id.size) TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
@Bind(R.id.speed) TextView mSpeed;
|
||||
@Bind(R.id.speeds) RadioGroup mRg;
|
||||
private DownloadEntity mEntity;
|
||||
@ -140,11 +140,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
@ -157,16 +152,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setTitle("单任务下载");
|
||||
init();
|
||||
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setTitle("单任务下载");
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
|
||||
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) {
|
||||
mStart.setText("恢复");
|
||||
}
|
||||
}
|
||||
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
@ -193,9 +186,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onPre(String url) {
|
||||
super.onPre(url);
|
||||
Log.d(TAG, "url ==> " + url);
|
||||
@Override public void onPre(DownloadTask task) {
|
||||
super.onPre(task);
|
||||
}
|
||||
|
||||
@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
|
@ -55,6 +55,11 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
return new MyHolder(convertView);
|
||||
}
|
||||
|
||||
public void addDownloadEntity(DownloadEntity entity) {
|
||||
mData.add(entity);
|
||||
mPositions.put(entity.getDownloadUrl(), mPositions.size());
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId(int type) {
|
||||
return R.layout.item_download;
|
||||
}
|
||||
@ -148,7 +153,7 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
|
||||
private String covertCurrentSize(long currentSize) {
|
||||
String size = CommonUtil.formatFileSize(currentSize);
|
||||
return size.substring(0, size.length() - 1);
|
||||
return size.substring(0, size.length() - 2);
|
||||
}
|
||||
|
||||
private int getColor(int color) {
|
||||
|
@ -34,7 +34,6 @@ import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
|
||||
|
||||
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
private DownloadAdapter mAdapter;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@ -43,14 +42,10 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle("下载列表");
|
||||
mAdapter = new DownloadAdapter(this, Aria.download(this).getTaskList());
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
mBar.setTitle("多任务下载");
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
|
@ -47,9 +47,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多任务下载");
|
||||
mData.addAll(getModule(DownloadModule.class).createFileList());
|
||||
setTitle("多任务下载");
|
||||
mData.addAll(getModule(DownloadModule.class).createMultiTestList());
|
||||
mAdapter = new FileListAdapter(this, mData);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
|
@ -108,9 +108,8 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
||||
this.handler = new WeakReference<>(handler);
|
||||
}
|
||||
|
||||
@Override public void onPre(String url) {
|
||||
super.onPre(url);
|
||||
L.e(TAG, "url ==> " + url);
|
||||
@Override public void onPre(UploadTask task) {
|
||||
super.onPre(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(UploadTask task) {
|
||||
|
@ -35,12 +35,18 @@
|
||||
android:layout_below="@+id/name"
|
||||
/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@+id/task"
|
||||
android:background="@android:color/darker_gray"
|
||||
/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/task"
|
||||
android:layout_margin="16dp"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
63
app/src/main/res/layout/dialog_msg.xml
Normal file
63
app/src/main/res/layout/dialog_msg.xml
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<data>
|
||||
<variable
|
||||
name="title"
|
||||
type="java.lang.String"
|
||||
/>
|
||||
<variable
|
||||
name="msg"
|
||||
type="java.lang.String"
|
||||
/>
|
||||
</data>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/background_color"
|
||||
android:gravity="center|left"
|
||||
android:maxHeight="400dp"
|
||||
android:padding="8dp"
|
||||
android:text="@{title}"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="22sp"
|
||||
/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxHeight="400dp"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/msg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center_vertical|left"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:text="@{msg}"
|
||||
android:textColor="#000"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
</ScrollView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/enter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="确定"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -2,7 +2,10 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="8dp"
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
@ -45,8 +48,8 @@
|
||||
android:id="@+id/speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignRight="@+id/progressBar"
|
||||
android:layout_alignTop="@+id/fileSize"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="0kb/s"
|
||||
android:textColor="@color/black"
|
||||
/>
|
||||
@ -55,8 +58,9 @@
|
||||
android:id="@+id/del"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignRight="@+id/progressBar"
|
||||
android:layout_alignTop="@+id/fileSize"
|
||||
android:layout_marginLeft="18dp"
|
||||
android:layout_toRightOf="@+id/progressBar"
|
||||
android:text="删除"
|
||||
android:textColor="@color/bt_selector_cancel"
|
||||
/>
|
||||
@ -67,7 +71,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/bar"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="name"
|
||||
/>
|
||||
|
||||
@ -76,7 +80,9 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/name"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
@ -84,7 +90,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/download_url"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
21
app/src/main/res/menu/menu_highest_priority.xml
Normal file
21
app/src/main/res/menu/menu_highest_priority.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/add_task"
|
||||
android:icon="@mipmap/ic_add_black_48dp"
|
||||
android:orderInCategory="80"
|
||||
android:title="添加一组任务"
|
||||
app:showAsAction="ifRoom"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/help"
|
||||
android:icon="@mipmap/ic_help_black_48dp"
|
||||
android:orderInCategory="90"
|
||||
android:title="最高优先级任务介绍"
|
||||
app:showAsAction="ifRoom"
|
||||
/>
|
||||
|
||||
</menu>
|
BIN
app/src/main/res/mipmap-mdpi/ic_add_black_48dp.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_add_black_48dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
BIN
app/src/main/res/mipmap-mdpi/ic_help_black_48dp.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_help_black_48dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 578 B |
@ -32,4 +32,16 @@
|
||||
<item>http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="highest_names">
|
||||
<item>豪门足球风云</item>
|
||||
<item>碧蓝航线</item>
|
||||
<item>天龙八部手游</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="highest_urls">
|
||||
<item>https://res5.d.cn/6f78ee3bcfdd033e0193c05c74acd280a32d5c1d8da7a68963da81a1403751e88e8f115ea475566c54456b74d82098c836577f54711a35bbb149e0bd88dc15c48845327fae8652cc.apk</item>
|
||||
<item>https://res5.d.cn/6f78ee3bcfdd033e1861859eaef45235b089f60f2e08c0e0e4fc8959d94de1e358a5149b4bec8519eabc62a53eebea280a05ef2d902d3153ae1dec4cb07b505e90a9f50af7dd14c4.apk</item>
|
||||
<item>https://res5.d.cn/6f78ee3bcfdd033ef8e38596afb298d87de07e5f0f1f91f22acd57750f8ae68270531e2b266ea41c86cd196da839a0afef1952dde89773c7e26b9019249503174ca0513fa0a36a6472c4202bbf94da382964a0478471b753ebd95b67aac7ad89.apk</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user