This commit is contained in:
AriaLyy
2017-07-31 22:53:56 +08:00
255 changed files with 44854 additions and 1803 deletions

View File

@@ -76,7 +76,7 @@ public class DownloadModule extends BaseModule {
String path = Environment.getExternalStorageDirectory() + "/download/" + name + ".apk";
DownloadEntity entity = new DownloadEntity();
entity.setFileName(name);
entity.setDownloadUrl(downloadUrl);
entity.setUrl(downloadUrl);
entity.setDownloadPath(path);
return entity;
}

View File

@@ -0,0 +1,122 @@
/*
* 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;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityFtpDownloadBinding;
import java.io.File;
/**
* Created by Aria.Lao on 2017/7/25.
* Ftp下载测试
*/
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
//private final String URL = "ftp://172.18.104.129:21/haha/large.rar";
//private final String URL = "ftp://172.18.104.129:21/haha/large.rar";
private final String URL = "ftp://172.18.104.129:21/haha/很大的文件_v100.rar";
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTitle("FTP文件下载");
Aria.download(this).register();
DownloadEntity entity = Aria.download(this).getDownloadEntity(URL);
if (entity != null) {
getBinding().setFileSize(entity.getConvertFileSize());
if (entity.getFileSize() == 0) {
getBinding().setProgress(0);
} else {
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.download(this)
.loadFtp(URL)
.login("lao", "123456")
.setDownloadPath("/mnt/sdcard/")
.start();
break;
case R.id.stop:
Aria.download(this).loadFtp(URL).stop();
break;
case R.id.cancel:
Aria.download(this).loadFtp(URL).cancel();
break;
}
}
@Download.onPre() protected void onPre(DownloadTask task) {
L.d(TAG, "ftp pre");
}
@Download.onTaskPre() protected void onTaskPre(DownloadTask task) {
L.d(TAG, "ftp task pre");
getBinding().setFileSize(task.getConvertFileSize());
}
@Download.onTaskStart() void taskStart(DownloadTask task) {
L.d(TAG, "ftp task start");
}
@Download.onTaskRunning() protected void running(DownloadTask task) {
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
}
@Download.onTaskResume() void taskResume(DownloadTask task) {
L.d(TAG, "ftp task resume");
}
@Download.onTaskStop() void taskStop(DownloadTask task) {
L.d(TAG, "ftp task stop");
getBinding().setSpeed("");
}
@Download.onTaskCancel() void taskCancel(DownloadTask task) {
getBinding().setSpeed("");
getBinding().setProgress(0);
}
@Download.onTaskFail() void taskFail(DownloadTask task) {
L.d(TAG, "ftp task fail");
}
@Download.onTaskComplete() void taskComplete(DownloadTask task) {
getBinding().setSpeed("");
getBinding().setProgress(100);
Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
T.showShort(this, "FTP下载完成");
}
@Override protected int setLayoutId() {
return R.layout.activity_ftp_download;
}
}

View File

@@ -87,9 +87,9 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
List<DownloadEntity> temp = Aria.download(this).getSimpleTaskList();
if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) {
if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue;
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
mData.add(entity);
mRecord.add(entity.getDownloadUrl());
mRecord.add(entity.getUrl());
}
}
mAdapter = new DownloadAdapter(this, mData);
@@ -112,7 +112,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
case R.id.add_task:
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
for (DownloadEntity entity : temp) {
String url = entity.getDownloadUrl();
String url = entity.getUrl();
if (mRecord.contains(url)) {
continue;
}

View File

@@ -24,7 +24,6 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import com.arialyy.annotations.Download;
@@ -83,7 +82,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
msg = "一些小知识点:\n"
+ "1、你可以在注解中增加链接用于指定被注解的方法只能被特定的下载任务回调以防止progress乱跳\n"
+ "2、当遇到网络慢的情况时你可以先使用onPre()更新UI界面待连接成功时再在onTaskPre()获取完整的task数据然后给UI界面设置正确的数据\n"
+ "3、你可以在界面初始化时通过Aria.download(this).load(DOWNLOAD_URL).getPercent()等方法快速获取相关任务的一些数据";
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
showMsgDialog("tip", msg);
break;
case R.id.speed_0:
@@ -188,24 +187,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
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(DOWNLOAD_URL)
// .addHeader("groupName", "value")
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
// .setFileName("hehe.apk")
// .start();
//} else if (text.equals("恢复")) {
// Aria.download(this).load(DOWNLOAD_URL).resume();
//}
Aria.download(this)
.load(DOWNLOAD_URL)
.addHeader("groupName", "value")
.setExtendField("str___ggggggg")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk")
.start();
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).stop();

View File

@@ -42,7 +42,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
private static final String DOWNLOAD_URL = "http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk";
private static final String DOWNLOAD_URL = "https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
@Override protected void init(Bundle savedInstanceState) {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
@@ -65,7 +65,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
case R.id.start:
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/兰空VOEZ.apk")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
.start();
break;
case R.id.stop:
@@ -84,13 +84,13 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
setBtState(true);
getBinding().setSpeed("0.0kb/s");
getBinding().setSpeed("");
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
setBtState(true);
getBinding().setProgress(0);
getBinding().setSpeed("0.0kb/s");
getBinding().setSpeed("");
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {

View File

@@ -17,6 +17,7 @@
package com.arialyy.simple.download.fragment_download;
import android.os.Bundle;
import com.arialyy.aria.core.Aria;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.FragmentDownloadBinding;
@@ -33,5 +34,6 @@ public class FragmentActivity extends BaseActivity<FragmentDownloadBinding> {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTile("Fragment 中使用");
Aria.download(this).register();
}
}

View File

@@ -40,9 +40,6 @@ import java.util.List;
*/
public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBinding> {
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@Bind(R.id.child_list) SubStateLinearLayout mChildList;
List<String> mUrls;
@@ -102,6 +99,9 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
}
@DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) {
if (mChildList.getSubData().size() <= 0) {
mChildList.addData(task.getEntity().getSubTask());
}
L.d(TAG, "group task pre");
getBinding().setFileSize(task.getConvertFileSize());
if (mChildList.getSubData().size() <= 0){
@@ -143,5 +143,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
getBinding().setSpeed("");
mChildList.updateChildProgress(task.getEntity().getSubTask());
T.showShort(this, "任务组下载完成");
L.d(TAG, "任务组下载完成");
}
}

View File

@@ -0,0 +1,131 @@
/*
* 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 butterknife.Bind;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
import com.arialyy.simple.widget.SubStateLinearLayout;
/**
* Created by Aria.Lao on 2017/7/6.
*/
public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBinding> {
private static final String dir = "ftp://172.18.104.129:21/haha/";
@Bind(R.id.child_list) SubStateLinearLayout mChildList;
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
Aria.download(this).register();
setTitle("FTP文件夹下载");
DownloadGroupTaskEntity entity = Aria.download(this).getDownloadGroupTask(dir);
if (entity != null && entity.getEntity() != null) {
DownloadGroupEntity groupEntity = entity.getEntity();
mChildList.addData(groupEntity.getSubTask());
getBinding().setFileSize(groupEntity.getConvertFileSize());
if (groupEntity.getFileSize() == 0) {
getBinding().setProgress(0);
} else {
getBinding().setProgress(groupEntity.isComplete() ? 100
: (int) (groupEntity.getCurrentProgress() * 100 / groupEntity.getFileSize()));
}
}
}
@Override protected int setLayoutId() {
return R.layout.activity_download_group;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.download(this)
.loadFtpDir(dir)
.setDownloadDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/ftp_dir")
.setGroupAlias("ftp文件夹下载")
//.setSubTaskFileName(getModule(GroupModule.class).getSubName())
.login("lao", "123456")
.start();
break;
case R.id.stop:
Aria.download(this).loadFtpDir(dir).stop();
break;
case R.id.cancel:
Aria.download(this).loadFtpDir(dir).cancel();
break;
}
}
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) {
L.d(TAG, "group pre");
}
@DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) {
if (mChildList.getSubData().size() <= 0) {
mChildList.addData(task.getEntity().getSubTask());
}
L.d(TAG, "group task pre");
getBinding().setFileSize(task.getConvertFileSize());
}
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) {
L.d(TAG, "group task start");
}
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
mChildList.updateChildProgress(task.getEntity().getSubTask());
}
@DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) {
L.d(TAG, "group task resume");
}
@DownloadGroup.onTaskStop() void taskStop(DownloadGroupTask task) {
L.d(TAG, "group task stop");
getBinding().setSpeed("");
}
@DownloadGroup.onTaskCancel() void taskCancel(DownloadGroupTask task) {
getBinding().setSpeed("");
getBinding().setProgress(0);
}
@DownloadGroup.onTaskFail() void taskFail(DownloadGroupTask task) {
L.d(TAG, "group task fail");
}
@DownloadGroup.onTaskComplete() void taskComplete(DownloadGroupTask task) {
getBinding().setProgress(100);
mChildList.updateChildProgress(task.getEntity().getSubTask());
T.showShort(this, "任务组下载完成");
L.d(TAG, "任务组下载完成");
}
}

View File

@@ -58,7 +58,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
private String getKey(AbsEntity entity) {
if (entity instanceof DownloadEntity) {
return ((DownloadEntity) entity).getDownloadUrl();
return ((DownloadEntity) entity).getUrl();
} else if (entity instanceof DownloadGroupEntity) {
return ((DownloadGroupEntity) entity).getGroupName();
}
@@ -73,7 +73,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
public void addDownloadEntity(DownloadEntity entity) {
mData.add(entity);
mPositions.put(entity.getDownloadUrl(), mPositions.size());
mPositions.put(entity.getUrl(), mPositions.size());
}
@Override public int getItemViewType(int position) {