修复数据错乱的bug

pull/9/head
AriaLyy 8 years ago
parent ec7cfd3549
commit 6ac3648bba
  1. 7
      Aria/src/main/java/com/arialyy/aria/core/AMReceiver.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/task/Task.java
  3. 17
      README.md
  4. 9
      app/src/main/AndroidManifest.xml
  5. 10
      app/src/main/java/com/arialyy/simple/MainActivity.java
  6. 187
      app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java
  7. 2
      app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
  8. 3
      app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
  9. 2
      app/src/main/java/com/arialyy/simple/fragment_task/FragmentActivity.java
  10. 29
      app/src/main/java/com/arialyy/simple/module/DownloadModule.java
  11. 86
      app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
  12. 15
      app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java
  13. 2
      app/src/main/java/com/arialyy/simple/multi_task/DownloadNumDialog.java
  14. 100
      app/src/main/java/com/arialyy/simple/multi_task/FileListAdapter.java
  15. 9
      app/src/main/java/com/arialyy/simple/multi_task/FileListEntity.java
  16. 118
      app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
  17. 4
      app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
  18. 7
      app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java
  19. 19
      app/src/main/res/layout/activity_download.xml
  20. 2
      app/src/main/res/layout/activity_fragment.xml
  21. 6
      app/src/main/res/layout/activity_multi.xml
  22. 2
      app/src/main/res/layout/activity_single.xml
  23. 2
      app/src/main/res/layout/content_single.xml
  24. 32
      app/src/main/res/layout/item_download.xml
  25. 40
      app/src/main/res/layout/item_file_list.xml
  26. 17
      app/src/main/res/values/strings.xml
  27. BIN
      img/download_img.gif
  28. BIN
      img/img.gif

@ -29,14 +29,12 @@ import com.arialyy.aria.util.CheckUtil;
public class AMReceiver {
String targetName;
OnSchedulerListener listener;
DownloadEntity entity;
Object obj;
/**
* {@link #load(String)}请使用该方法
*/
@Deprecated public AMTarget load(DownloadEntity entity) {
this.entity = entity;
return new AMTarget(entity, targetName);
}
@ -45,9 +43,8 @@ public class AMReceiver {
*/
public AMTarget load(@NonNull String downloadUrl) {
CheckUtil.checkDownloadUrl(downloadUrl);
if (entity == null) {
entity = DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl);
}
DownloadEntity entity =
DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl);
if (entity == null) {
entity = new DownloadEntity();
}

@ -78,6 +78,13 @@ public class Task {
return mEntity.getCurrentProgress();
}
/**
* 获取当前下载任务的下载地址
*/
public String getDownloadUrl() {
return mEntity.getDownloadUrl();
}
/**
* 开始下载
*/
@ -202,6 +209,7 @@ public class Task {
public Task build() {
Task task = new Task(context, downloadEntity, outHandler);
task.setTargetName(targetName);
//Log.w(TAG, "downloadEntity hashcode ==> " + downloadEntity.hashCode());
downloadEntity.save();
return task;
}

@ -16,7 +16,7 @@ Aria,致力于让下载傻瓜化</br>
## 下载
[![Download](https://api.bintray.com/packages/arialyy/maven/Aria/images/download.svg)](https://bintray.com/arialyy/maven/Aria/_latestVersion)</br>
```java
compile 'com.arialyy.aria:Aria:2.3.6'
compile 'com.arialyy.aria:Aria:2.3.8'
```
@ -30,7 +30,13 @@ compile 'com.arialyy.aria:Aria:2.3.6'
***
## 使用
### 一、只需要以下参数,你便能很简单的使用Aria下载文件了
### 一、添加权限
```xml
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
```
### 二、只需要以下参数,你便能很简单的使用Aria下载文件了
```java
Aria.whit(this)
.load(DOWNLOAD_URL) //下载地址,必填
@ -38,14 +44,14 @@ compile 'com.arialyy.aria:Aria:2.3.6'
.setDownloadName("test.apk") //文件名,必填
.start();
```
### 、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume
### 、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume
```java
@Override protected void onResume() {
super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
}
```
### 、通过下载链接,你还能使用Aria执行很多操作,如:
### 、通过下载链接,你还能使用Aria执行很多操作,如:
- 添加任务(不进行下载)
```java
@ -85,7 +91,7 @@ compile 'com.arialyy.aria:Aria:2.3.6'
Aria.whit(this).load(DOWNLOAD_URL).getFileSize();
```
### 、关于Aria,你还需要知道的一些东西
### 、关于Aria,你还需要知道的一些东西
- 设置下载任务数,Aria默认下载任务为**2**
```java
@ -114,6 +120,7 @@ compile 'com.arialyy.aria:Aria:2.3.6'
***
## 开发日志
+ v_2.3.8 修复数据错乱的bug、添加fragment支持
+ v_2.3.6 添加dialog、popupWindow支持
+ v_2.3.3
- 添加断点支持

@ -15,7 +15,7 @@
android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".activity.SingleTaskActivity"-->
<activity
android:name=".activity.MainActivity"
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -24,9 +24,10 @@
</intent-filter>
</activity>
<activity android:name=".activity.SingleTaskActivity"/>
<activity android:name=".activity.MultiTaskActivity"/>
<activity android:name=".activity.FragmentActivity"/>
<activity android:name=".single_task.SingleTaskActivity"/>
<activity android:name=".multi_task.MultiTaskActivity"/>
<activity android:name=".fragment_task.FragmentActivity"/>
<activity android:name=".multi_task.DownloadActivity"/>
</application>
</manifest>

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.activity;
package com.arialyy.simple;
import android.Manifest;
import android.content.Intent;
@ -28,11 +28,13 @@ import butterknife.Bind;
import com.arialyy.frame.permission.OnPermissionCallback;
import com.arialyy.frame.permission.PermissionManager;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMainBinding;
import com.arialyy.simple.dialog.DownloadDialog;
import com.arialyy.simple.pop.DownloadPopupWindow;
import com.arialyy.simple.dialog_task.DownloadDialog;
import com.arialyy.simple.fragment_task.FragmentActivity;
import com.arialyy.simple.multi_task.MultiTaskActivity;
import com.arialyy.simple.pop_task.DownloadPopupWindow;
import com.arialyy.simple.single_task.SingleTaskActivity;
/**
* Created by Lyy on 2016/10/13.

@ -1,187 +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.simple.activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.Bind;
import com.arialyy.aria.core.AMTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.adapter.DownloadAdapter;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import com.arialyy.simple.dialog.DownloadNumDialog;
import com.arialyy.simple.module.DownloadModule;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Lyy on 2016/9/27.
*/
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Bind(R.id.list) RecyclerView mList;
@Bind(R.id.toolbar) Toolbar mBar;
DownloadAdapter mAdapter;
List<DownloadEntity> mData = new ArrayList<>();
@Override protected int setLayoutId() {
return R.layout.activity_multi;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
mBar.setTitle("多任务下载");
mData.addAll(getModule(DownloadModule.class).getDownloadData());
mAdapter = new DownloadAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
//private BroadcastReceiver mReceiver = new BroadcastReceiver() {
// long len = 0;
//
// @Override public void onReceive(Context context, Intent intent) {
// String action = intent.getAction();
// DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
// switch (action) {
// case DownloadManager.ACTION_PRE:
// L.d(TAG, "download pre");
// mAdapter.updateState(entity);
// break;
// case DownloadManager.ACTION_POST_PRE:
// len = entity.getFileSize();
// L.d(TAG, "download post pre");
// break;
// case DownloadManager.ACTION_START:
// L.d(TAG, "download start");
// break;
// case DownloadManager.ACTION_RESUME:
// L.d(TAG, "download resume");
// long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
// mAdapter.updateState(entity);
// break;
// case DownloadManager.ACTION_RUNNING:
// long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
// long speed = intent.getLongExtra(DownloadManager.CURRENT_SPEED, 0);
// //mAdapter.setProgress(entity.getDownloadUrl(), current, speed);
// mAdapter.setProgress(entity);
// break;
// case DownloadManager.ACTION_STOP:
// L.d(TAG, "download stop");
// mAdapter.updateState(entity);
// break;
// case DownloadManager.ACTION_COMPLETE:
// L.d(TAG, "download complete");
// mAdapter.updateState(entity);
// break;
// case DownloadManager.ACTION_CANCEL:
// L.d(TAG, "download cancel");
// mAdapter.updateState(entity);
// break;
// case DownloadManager.ACTION_FAIL:
// L.d(TAG, "download fail");
// break;
// }
// }
//};
public void onClick(View view) {
switch (view.getId()) {
case R.id.num:
DownloadNumDialog dialog = new DownloadNumDialog(this);
dialog.show(getSupportFragmentManager(), "download_num");
break;
case R.id.stop_all:
Aria.get(this).stopAllTask();
break;
case R.id.add_task:
mData.add(getModule(DownloadModule.class).createRandomDownloadEntity());
mAdapter.notifyDataSetChanged();
break;
}
}
@Override protected void onResume() {
super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
}
@Override protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(mReceiver);
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE) {
mAdapter.setDownloadNum(Integer.parseInt(data + ""));
}
}
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
@Override public void onTaskPre(Task task) {
super.onTaskPre(task);
L.d(TAG, "download pre");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStart(Task task) {
super.onTaskStart(task);
L.d(TAG, "download start");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskResume(Task task) {
super.onTaskResume(task);
L.d(TAG, "download resume");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskRunning(Task task) {
super.onTaskRunning(task);
mAdapter.setProgress(task.getDownloadEntity());
}
@Override public void onTaskStop(Task task) {
super.onTaskStop(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskCancel(Task task) {
super.onTaskCancel(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskComplete(Task task) {
super.onTaskComplete(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskFail(Task task) {
super.onTaskFail(task);
L.d(TAG, "download fail");
}
}
}

@ -1,4 +1,4 @@
package com.arialyy.simple.dialog;
package com.arialyy.simple.dialog_task;
import android.content.Context;
import android.os.Environment;

@ -1,4 +1,4 @@
package com.arialyy.simple.fragment;
package com.arialyy.simple.fragment_task;
import android.os.Bundle;
import android.os.Environment;
@ -15,7 +15,6 @@ import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R;
import com.arialyy.simple.databinding.FragmentDownloadBinding;
import com.arialyy.simple.dialog.DownloadDialog;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
/**

@ -1,4 +1,4 @@
package com.arialyy.simple.activity;
package com.arialyy.simple.fragment_task;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;

@ -24,13 +24,13 @@ import android.os.Environment;
import android.os.Handler;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadManager;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.AndroidUtils;
import com.arialyy.frame.util.StringUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.activity.SingleTaskActivity;
import com.arialyy.simple.multi_task.FileListEntity;
import com.arialyy.simple.single_task.SingleTaskActivity;
import com.arialyy.simple.base.BaseModule;
import java.io.File;
import java.util.ArrayList;
@ -45,9 +45,9 @@ public class DownloadModule extends BaseModule {
public DownloadModule(Context context) {
super(context);
mTestDownloadUrl.add("static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
mTestDownloadUrl.add("static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
mTestDownloadUrl.add("static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
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 String getRadomUrl() {
@ -60,6 +60,25 @@ public class DownloadModule extends BaseModule {
return createDownloadEntity(getRadomUrl());
}
/**
* 创建下载地址
*/
public List<FileListEntity> createFileList() {
String[] names = getContext().getResources().getStringArray(R.array.file_nams);
String[] downloadUrl = getContext().getResources().getStringArray(R.array.download_url);
List<FileListEntity> list = new ArrayList<>();
int i = 0;
for (String name : names) {
FileListEntity entity = new FileListEntity();
entity.name = name;
entity.downloadUrl = downloadUrl[i];
entity.downloadPath = Environment.getExternalStorageDirectory() + "/Download/" + name;
list.add(entity);
i++;
}
return list;
}
/**
* 设置下载数据
*/

@ -0,0 +1,86 @@
package com.arialyy.simple.multi_task;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.Task;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadBinding;
/**
* Created by AriaL on 2017/1/6.
*/
public class DownloadActivity extends BaseActivity<ActivityDownloadBinding> {
@Bind(R.id.list) RecyclerView mList;
private DownloadAdapter mAdapter;
@Override protected int setLayoutId() {
return R.layout.activity_download;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mAdapter = new DownloadAdapter(this, Aria.get(this).getDownloadList());
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
@Override protected void dataCallback(int result, Object data) {
}
@Override protected void onResume() {
super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
}
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
@Override public void onTaskPre(Task task) {
super.onTaskPre(task);
L.d(TAG, "download pre");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStart(Task task) {
super.onTaskStart(task);
L.d(TAG, "download start");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskResume(Task task) {
super.onTaskResume(task);
L.d(TAG, "download resume");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskRunning(Task task) {
super.onTaskRunning(task);
mAdapter.setProgress(task.getDownloadEntity());
}
@Override public void onTaskStop(Task task) {
super.onTaskStop(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskCancel(Task task) {
super.onTaskCancel(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskComplete(Task task) {
super.onTaskComplete(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskFail(Task task) {
super.onTaskFail(task);
L.d(TAG, "download fail");
}
}
}

@ -14,12 +14,10 @@
* limitations under the License.
*/
package com.arialyy.simple.adapter;
package com.arialyy.simple.multi_task;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@ -40,16 +38,15 @@ import java.util.concurrent.ConcurrentHashMap;
* Created by Lyy on 2016/9/27.
* 下载列表适配器
*/
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
private static final String TAG = "DownloadAdapter";
private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
public DownloadAdapter(Context context, List<DownloadEntity> data) {
DownloadAdapter(Context context, List<DownloadEntity> data) {
super(context, data);
int i = 0;
for (DownloadEntity entity : data) {
mPositions.put(entity.getDownloadUrl(), i);
Aria.whit(getContext()).load(entity).add();
i++;
}
}
@ -111,6 +108,9 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
holder.progress.setProgress(current);
BtClickListener listener = new BtClickListener(item);
holder.bt.setOnClickListener(listener);
holder.name.setText("文件名:" + item.getFileName());
holder.url.setText("下载地址:" + item.getDownloadUrl());
holder.path.setText("保持路径:" + item.getDownloadPath());
String str = "";
int color = android.R.color.holo_green_light;
switch (item.getState()) {
@ -197,6 +197,9 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
@Bind(R.id.speed) TextView speed;
@Bind(R.id.fileSize) TextView fileSize;
@Bind(R.id.del) TextView cancel;
@Bind(R.id.name) TextView name;
@Bind(R.id.download_url) TextView url;
@Bind(R.id.download_path) TextView path;
MyHolder(View itemView) {
super(itemView);

@ -15,7 +15,7 @@
*/
package com.arialyy.simple.dialog;
package com.arialyy.simple.multi_task;
import android.annotation.SuppressLint;
import android.os.Bundle;

@ -0,0 +1,100 @@
package com.arialyy.simple.multi_task;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import com.arialyy.absadapter.common.AbsHolder;
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
import com.arialyy.aria.core.Aria;
import com.arialyy.simple.R;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by AriaL on 2017/1/6.
*/
final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter.FileListHolder> {
//SparseBooleanArray mBtStates = new SparseBooleanArray();
Map<String, Boolean> mBtStates = new ConcurrentHashMap<>();
private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
public FileListAdapter(Context context, List<FileListEntity> 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);
}
}
@Override protected FileListHolder getViewHolder(View convertView, int viewType) {
return new FileListHolder(convertView);
}
@Override protected int setLayoutId(int type) {
return R.layout.item_file_list;
}
@Override
protected void bindData(FileListHolder holder, int position, final FileListEntity item) {
holder.name.setText("文件名:" + item.name);
holder.url.setText("下载地址:" + item.downloadUrl);
holder.path.setText("保存路径:" + item.downloadPath);
if (mBtStates.get(item.downloadUrl)) {
holder.bt.setEnabled(true);
holder.bt.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
Aria.whit(getContext())
.load(item.downloadUrl)
.setDownloadName(item.name)
.setDownloadPath(item.downloadPath)
.start();
}
});
} else {
holder.bt.setEnabled(false);
}
}
public void updateBtState(String downloadUrl, boolean able) {
Set<String> keys = mBtStates.keySet();
for (String key : keys) {
if (key.equals(downloadUrl)) {
Log.d(TAG, "able ==> " + able);
mBtStates.put(downloadUrl, able);
notifyItemChanged(indexItem(downloadUrl));
return;
}
}
}
private synchronized int indexItem(String url) {
Set<String> keys = mPositions.keySet();
for (String key : keys) {
if (key.equals(url)) {
int index = mPositions.get(key);
Log.d(TAG, "index ==> " + index);
return index;
}
}
return -1;
}
class FileListHolder extends AbsHolder {
@Bind(R.id.name) TextView name;
@Bind(R.id.download_url) TextView url;
@Bind(R.id.download_path) TextView path;
@Bind(R.id.bt) Button bt;
FileListHolder(View itemView) {
super(itemView);
}
}
}

@ -0,0 +1,9 @@
package com.arialyy.simple.multi_task;
/**
* Created by AriaL on 2017/1/6.
*/
public class FileListEntity {
public String name, downloadUrl, downloadPath;
}

@ -0,0 +1,118 @@
/*
* 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.multi_task;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import com.arialyy.simple.module.DownloadModule;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Lyy on 2016/9/27.
*/
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Bind(R.id.list) RecyclerView mList;
@Bind(R.id.toolbar) Toolbar mBar;
private FileListAdapter mAdapter;
List<FileListEntity> mData = new ArrayList<>();
@Override protected int setLayoutId() {
return R.layout.activity_multi;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
mBar.setTitle("多任务下载");
mData.addAll(getModule(DownloadModule.class).createFileList());
mAdapter = new FileListAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.num:
DownloadNumDialog dialog = new DownloadNumDialog(this);
dialog.show(getSupportFragmentManager(), "download_num");
break;
case R.id.stop_all:
Aria.get(this).stopAllTask();
break;
case R.id.turn:
startActivity(new Intent(this, DownloadActivity.class));
break;
}
}
@Override protected void onResume() {
super.onResume();
Aria.whit(this).addSchedulerListener(new DownloadListener());
}
@Override protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(mReceiver);
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE) {
Aria.get(this).setMaxDownloadNum(Integer.parseInt(data + ""));
}
}
private class DownloadListener extends Aria.SimpleSchedulerListener {
@Override public void onTaskStart(Task task) {
super.onTaskStart(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
}
@Override public void onTaskRunning(Task task) {
super.onTaskRunning(task);
}
@Override public void onTaskResume(Task task) {
super.onTaskResume(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
}
@Override public void onTaskStop(Task task) {
super.onTaskStop(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
}
@Override public void onTaskComplete(Task task) {
super.onTaskComplete(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
}
}
}

@ -1,8 +1,7 @@
package com.arialyy.simple.pop;
package com.arialyy.simple.pop_task;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Environment;
import android.view.View;
@ -15,7 +14,6 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
import com.arialyy.frame.core.AbsPopupWindow;
import com.arialyy.simple.R;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;

@ -14,13 +14,11 @@
* limitations under the License.
*/
package com.arialyy.simple.activity;
package com.arialyy.simple.single_task;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@ -35,15 +33,12 @@ import butterknife.Bind;
import com.arialyy.aria.core.AMTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadManager;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.orm.DbEntity;
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.ActivitySingleBinding;
import com.arialyy.simple.module.DownloadModule;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.arial.test.MainActivity"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</layout>

@ -8,7 +8,7 @@
>
<fragment
android:id="@+id/fragment1"
android:name="com.arialyy.simple.fragment.DownloadFragment"
android:name="com.arialyy.simple.fragment_task.DownloadFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

@ -15,8 +15,8 @@
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:layout_above="@+id/num"
android:layout_below="@+id/toolbar"
/>
<Button
@ -43,14 +43,14 @@
<Button
android:id="@+id/add_task"
android:id="@+id/turn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:onClick="onClick"
android:text="添加任务"
android:text="下载列表"
/>
</RelativeLayout>

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
tools:context="com.arialyy.simple.single_task.SingleTaskActivity"
>
<android.support.design.widget.AppBarLayout

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
tools:context="com.arialyy.simple.single_task.SingleTaskActivity"
tools:showIn="@layout/activity_single"
>

@ -5,6 +5,12 @@
android:padding="16dp"
>
<RelativeLayout
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
android:id="@+id/progressBar"
android:layout_width="match_parent"
@ -54,5 +60,31 @@
android:text="删除"
android:textColor="@color/bt_selector_cancel"
/>
</RelativeLayout>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bar"
android:layout_marginTop="10dp"
android:text="name"
/>
<TextView
android:id="@+id/download_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/download_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/download_url"
android:layout_marginTop="10dp"
/>
</RelativeLayout>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
/>
<TextView
android:id="@+id/download_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/download_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/download_url"
android:layout_marginTop="10dp"
/>
<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/download_path"
android:text="点击下载"
/>
</RelativeLayout>

@ -15,4 +15,21 @@
<!--<item>http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk</item>-->
</string-array>
<string-array name="file_nams">
<item>阴阳师</item>
<item>奇迹暖暖</item>
<item>幻影纹章</item>
<item>史上最坑爹的游戏10</item>
<item>鲜果消消乐</item>
</string-array>
<string-array name="download_url">
<item>http://g37.gdl.netease.com/onmyoji_netease.apk</item>
<item>http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk</item>
<item>http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk</item>
<item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item>
<item>http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk</item>
</string-array>
</resources>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Loading…
Cancel
Save