..
This commit is contained in:
@@ -116,7 +116,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
* 设置新任务的最大线程数
|
* 设置新任务的最大线程数
|
||||||
*/
|
*/
|
||||||
protected int getNewTaskThreadNum() {
|
protected int getNewTaskThreadNum() {
|
||||||
return mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.FTP_DIR ? 1
|
return mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR ? 1
|
||||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
|||||||
extends AbsThreadTask<ENTITY, TASK_ENTITY> {
|
extends AbsThreadTask<ENTITY, TASK_ENTITY> {
|
||||||
protected String charSet, serverIp, port;
|
protected String charSet, serverIp, port;
|
||||||
/**
|
/**
|
||||||
* FTP 服务器编码
|
* D_FTP 服务器编码
|
||||||
*/
|
*/
|
||||||
public static String SERVER_CHARSET = "ISO-8859-1";
|
public static String SERVER_CHARSET = "ISO-8859-1";
|
||||||
|
|
||||||
|
@@ -56,6 +56,10 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
|||||||
return getUrl();
|
return getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public int getTaskType() {
|
||||||
|
return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP;
|
||||||
|
}
|
||||||
|
|
||||||
public DownloadEntity() {
|
public DownloadEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ package com.arialyy.aria.core.download;
|
|||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||||
import com.arialyy.aria.orm.NormalList;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.orm.OneToMany;
|
import com.arialyy.aria.orm.OneToMany;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -58,6 +58,10 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
|||||||
this.groupName = key;
|
this.groupName = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public int getTaskType() {
|
||||||
|
return getKey().startsWith("ftp") ? AbsTaskEntity.D_FTP_DIR : AbsTaskEntity.DG_HTTP;
|
||||||
|
}
|
||||||
|
|
||||||
public DownloadGroupEntity() {
|
public DownloadGroupEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,10 +40,10 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity> {
|
|||||||
mContext = AriaManager.APP;
|
mContext = AriaManager.APP;
|
||||||
mListener = new DownloadGroupListener(this, mOutHandler);
|
mListener = new DownloadGroupListener(this, mOutHandler);
|
||||||
switch (taskEntity.requestType) {
|
switch (taskEntity.requestType) {
|
||||||
case AbsTaskEntity.HTTP:
|
case AbsTaskEntity.D_HTTP:
|
||||||
mUtil = new DownloadGroupUtil(mListener, mTaskEntity);
|
mUtil = new DownloadGroupUtil(mListener, mTaskEntity);
|
||||||
break;
|
break;
|
||||||
case AbsTaskEntity.FTP_DIR:
|
case AbsTaskEntity.D_FTP_DIR:
|
||||||
mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity);
|
mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* @param refreshInfo 是否刷新下载信息
|
* @param refreshInfo 是否刷新下载信息
|
||||||
*/
|
*/
|
||||||
public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
|
public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
|
||||||
|
CheckUtil.checkDownloadEntity(entity);
|
||||||
return new DownloadTarget(entity, targetName, refreshInfo);
|
return new DownloadTarget(entity, targetName, refreshInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* @param refreshInfo 是否刷新下载信息
|
* @param refreshInfo 是否刷新下载信息
|
||||||
*/
|
*/
|
||||||
public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
|
public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
|
||||||
CheckUtil.checkDownloadUrl(url);
|
CheckUtil.checkUrl(url);
|
||||||
return new DownloadTarget(url, targetName, refreshInfo);
|
return new DownloadTarget(url, targetName, refreshInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +99,28 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
return new DownloadGroupTarget(urls, targetName);
|
return new DownloadGroupTarget(urls, targetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用下载实体执行FTP下载操作
|
||||||
|
*
|
||||||
|
* @param entity 下载实体
|
||||||
|
*/
|
||||||
|
public FtpDownloadTarget loadFtp(DownloadEntity entity) {
|
||||||
|
return loadFtp(entity, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用下载实体执行下载操作
|
||||||
|
*
|
||||||
|
* @param refreshInfo 是否刷新下载信息
|
||||||
|
*/
|
||||||
|
public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) {
|
||||||
|
CheckUtil.checkDownloadEntity(entity);
|
||||||
|
if (!entity.getUrl().startsWith("ftp")) {
|
||||||
|
throw new IllegalArgumentException("非FTP请求不能使用该方法");
|
||||||
|
}
|
||||||
|
return new FtpDownloadTarget(entity, targetName, refreshInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载ftp单任务下载地址
|
* 加载ftp单任务下载地址
|
||||||
*/
|
*/
|
||||||
@@ -111,7 +134,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* @param refreshInfo 是否刷新下载信息
|
* @param refreshInfo 是否刷新下载信息
|
||||||
*/
|
*/
|
||||||
public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) {
|
public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) {
|
||||||
CheckUtil.checkDownloadUrl(url);
|
CheckUtil.checkUrl(url);
|
||||||
return new FtpDownloadTarget(url, targetName, refreshInfo);
|
return new FtpDownloadTarget(url, targetName, refreshInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +152,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* 加载ftp文件夹下载地址
|
* 加载ftp文件夹下载地址
|
||||||
*/
|
*/
|
||||||
public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) {
|
public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) {
|
||||||
CheckUtil.checkDownloadUrl(dirUrl);
|
CheckUtil.checkUrl(dirUrl);
|
||||||
return new FtpDirDownloadTarget(dirUrl, targetName);
|
return new FtpDirDownloadTarget(dirUrl, targetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +203,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* 通过下载链接获取下载实体
|
* 通过下载链接获取下载实体
|
||||||
*/
|
*/
|
||||||
public DownloadEntity getDownloadEntity(String downloadUrl) {
|
public DownloadEntity getDownloadEntity(String downloadUrl) {
|
||||||
CheckUtil.checkDownloadUrl(downloadUrl);
|
CheckUtil.checkUrl(downloadUrl);
|
||||||
return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'", downloadUrl);
|
return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'", downloadUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +211,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* 通过下载链接获取保存在数据库的下载任务实体
|
* 通过下载链接获取保存在数据库的下载任务实体
|
||||||
*/
|
*/
|
||||||
public DownloadTaskEntity getDownloadTask(String downloadUrl) {
|
public DownloadTaskEntity getDownloadTask(String downloadUrl) {
|
||||||
CheckUtil.checkDownloadUrl(downloadUrl);
|
CheckUtil.checkUrl(downloadUrl);
|
||||||
DownloadEntity entity = getDownloadEntity(downloadUrl);
|
DownloadEntity entity = getDownloadEntity(downloadUrl);
|
||||||
if (entity == null || TextUtils.isEmpty(entity.getDownloadPath())) return null;
|
if (entity == null || TextUtils.isEmpty(entity.getDownloadPath())) return null;
|
||||||
return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
|
return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
|
||||||
|
@@ -36,7 +36,7 @@ public class FtpDirDownloadTarget
|
|||||||
mTargetName = targetName;
|
mTargetName = targetName;
|
||||||
serverIp = pp[0];
|
serverIp = pp[0];
|
||||||
port = Integer.parseInt(pp[1]);
|
port = Integer.parseInt(pp[1]);
|
||||||
mTaskEntity.requestType = AbsTaskEntity.FTP_DIR;
|
mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR;
|
||||||
mTaskEntity.serverIp = serverIp;
|
mTaskEntity.serverIp = serverIp;
|
||||||
mTaskEntity.port = port;
|
mTaskEntity.port = port;
|
||||||
remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
|
remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
|
||||||
|
@@ -35,12 +35,21 @@ public class FtpDownloadTarget extends DownloadTarget {
|
|||||||
this(url, targetName, false);
|
this(url, targetName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
|
||||||
|
super(entity, targetName);
|
||||||
|
init(refreshInfo);
|
||||||
|
}
|
||||||
|
|
||||||
FtpDownloadTarget(String url, String targetName, boolean refreshInfo) {
|
FtpDownloadTarget(String url, String targetName, boolean refreshInfo) {
|
||||||
super(url, targetName);
|
super(url, targetName);
|
||||||
|
init(refreshInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(boolean refreshInfo) {
|
||||||
String[] pp = url.split("/")[2].split(":");
|
String[] pp = url.split("/")[2].split(":");
|
||||||
this.serverIp = pp[0];
|
this.serverIp = pp[0];
|
||||||
this.port = Integer.parseInt(pp[1]);
|
this.port = Integer.parseInt(pp[1]);
|
||||||
mTaskEntity.requestType = AbsTaskEntity.FTP;
|
mTaskEntity.requestType = AbsTaskEntity.D_FTP;
|
||||||
remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
|
remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
|
||||||
if (TextUtils.isEmpty(remotePath)) {
|
if (TextUtils.isEmpty(remotePath)) {
|
||||||
throw new NullPointerException("ftp服务器地址不能为null");
|
throw new NullPointerException("ftp服务器地址不能为null");
|
||||||
|
@@ -91,10 +91,10 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
|
|
||||||
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DownloadTaskEntity> config) {
|
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DownloadTaskEntity> config) {
|
||||||
switch (mTaskEntity.requestType) {
|
switch (mTaskEntity.requestType) {
|
||||||
case AbsTaskEntity.FTP:
|
case AbsTaskEntity.D_FTP:
|
||||||
case AbsTaskEntity.FTP_DIR:
|
case AbsTaskEntity.D_FTP_DIR:
|
||||||
return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
||||||
case AbsTaskEntity.HTTP:
|
case AbsTaskEntity.D_HTTP:
|
||||||
return new HttpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
return new HttpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@@ -51,7 +51,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
|||||||
|
|
||||||
@Override public void onFail(String url, String errorMsg) {
|
@Override public void onFail(String url, String errorMsg) {
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
ErrorHelp.saveError("FTP_DIR", mTaskEntity.getEntity(), "", errorMsg);
|
ErrorHelp.saveError("D_FTP_DIR", mTaskEntity.getEntity(), "", errorMsg);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ import com.arialyy.aria.util.ErrorHelp;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2015/8/25.
|
* Created by lyy on 2015/8/25.
|
||||||
* HTTP\FTP单任务下载工具
|
* D_HTTP\FTP单任务下载工具
|
||||||
*/
|
*/
|
||||||
public class SimpleDownloadUtil implements IUtil, Runnable {
|
public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||||
private static final String TAG = "SimpleDownloadUtil";
|
private static final String TAG = "SimpleDownloadUtil";
|
||||||
@@ -102,7 +102,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
|||||||
*/
|
*/
|
||||||
private Runnable createInfoThread() {
|
private Runnable createInfoThread() {
|
||||||
switch (mTaskEntity.requestType) {
|
switch (mTaskEntity.requestType) {
|
||||||
case AbsTaskEntity.FTP:
|
case AbsTaskEntity.D_FTP:
|
||||||
return new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
return new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
||||||
@Override public void onComplete(String url, int code) {
|
@Override public void onComplete(String url, int code) {
|
||||||
mDownloader.start();
|
mDownloader.start();
|
||||||
@@ -112,7 +112,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
|||||||
failDownload(errorMsg);
|
failDownload(errorMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
case AbsTaskEntity.HTTP:
|
case AbsTaskEntity.D_HTTP:
|
||||||
return new HttpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
return new HttpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
||||||
@Override public void onComplete(String url, int code) {
|
@Override public void onComplete(String url, int code) {
|
||||||
mDownloader.start();
|
mDownloader.start();
|
||||||
|
@@ -19,8 +19,6 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.orm.Ignore;
|
import com.arialyy.aria.orm.Ignore;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by AriaL on 2017/6/29.
|
* Created by AriaL on 2017/6/29.
|
||||||
@@ -162,6 +160,12 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
|
|||||||
*/
|
*/
|
||||||
public abstract String getKey();
|
public abstract String getKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体驱动的下载任务类型
|
||||||
|
* @return {@link AbsTaskEntity#D_FTP}、{@link AbsTaskEntity#D_FTP_DIR}、{@link AbsTaskEntity#}
|
||||||
|
*/
|
||||||
|
public abstract int getTaskType();
|
||||||
|
|
||||||
public AbsEntity() {
|
public AbsEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,17 +28,30 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
||||||
/**
|
/**
|
||||||
* HTTP下载
|
* HTTP单任务载
|
||||||
*/
|
*/
|
||||||
public static final int HTTP = 0x11;
|
public static final int D_HTTP = 0x11;
|
||||||
/**
|
/**
|
||||||
* FTP当文件下载
|
* HTTP任务组下载
|
||||||
*/
|
*/
|
||||||
public static final int FTP = 0x12;
|
public static final int DG_HTTP = 0x12;
|
||||||
|
/**
|
||||||
|
* HTTP单文件上传
|
||||||
|
*/
|
||||||
|
public static final int U_HTTP = 0xA1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FTP单文件下载
|
||||||
|
*/
|
||||||
|
public static final int D_FTP = 0x13;
|
||||||
/**
|
/**
|
||||||
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
||||||
*/
|
*/
|
||||||
public static final int FTP_DIR = 0x13;
|
public static final int D_FTP_DIR = 0x14;
|
||||||
|
/**
|
||||||
|
* FTP单文件上传
|
||||||
|
*/
|
||||||
|
public static final int U_FTP = 0xA2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task实体对应的key
|
* Task实体对应的key
|
||||||
@@ -68,9 +81,9 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求类型
|
* 请求类型
|
||||||
* {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP}
|
* {@link AbsTaskEntity#D_HTTP}、{@link AbsTaskEntity#D_FTP}
|
||||||
*/
|
*/
|
||||||
public int requestType = HTTP;
|
public int requestType = D_HTTP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http 请求头
|
* http 请求头
|
||||||
|
@@ -21,7 +21,6 @@ import com.arialyy.aria.core.upload.UploadEntity;
|
|||||||
import com.arialyy.aria.core.upload.UploadTask;
|
import com.arialyy.aria.core.upload.UploadTask;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.util.CheckUtil;
|
import com.arialyy.aria.util.CheckUtil;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +36,7 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
|
|||||||
* @param uploadUrl 上传路径
|
* @param uploadUrl 上传路径
|
||||||
*/
|
*/
|
||||||
public TARGET setUploadUrl(@NonNull String uploadUrl) {
|
public TARGET setUploadUrl(@NonNull String uploadUrl) {
|
||||||
CheckUtil.checkDownloadUrl(uploadUrl);
|
CheckUtil.checkUrl(uploadUrl);
|
||||||
if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
|
if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
|
||||||
mEntity.setUrl(uploadUrl);
|
mEntity.setUrl(uploadUrl);
|
||||||
//mEntity.setUrl(CommonUtil.convertUrl(uploadUrl));
|
//mEntity.setUrl(CommonUtil.convertUrl(uploadUrl));
|
||||||
|
@@ -40,7 +40,7 @@ public class FtpUploadTarget
|
|||||||
if (mTaskEntity.entity == null) {
|
if (mTaskEntity.entity == null) {
|
||||||
mTaskEntity.entity = getUploadEntity(filePath);
|
mTaskEntity.entity = getUploadEntity(filePath);
|
||||||
}
|
}
|
||||||
mTaskEntity.requestType = AbsTaskEntity.FTP;
|
mTaskEntity.requestType = AbsTaskEntity.U_FTP;
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
mEntity.setFileName(file.getName());
|
mEntity.setFileName(file.getName());
|
||||||
|
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.upload;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||||
import com.arialyy.aria.orm.Ignore;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.orm.Primary;
|
import com.arialyy.aria.orm.Primary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,9 +26,7 @@ import com.arialyy.aria.orm.Primary;
|
|||||||
* 上传文件实体
|
* 上传文件实体
|
||||||
*/
|
*/
|
||||||
public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
||||||
@Primary
|
@Primary private String filePath; //文件路径
|
||||||
private String filePath; //文件路径
|
|
||||||
|
|
||||||
|
|
||||||
public String getFilePath() {
|
public String getFilePath() {
|
||||||
return filePath;
|
return filePath;
|
||||||
@@ -42,6 +40,10 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
|||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public int getTaskType() {
|
||||||
|
return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP;
|
||||||
|
}
|
||||||
|
|
||||||
public UploadEntity() {
|
public UploadEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,12 +16,10 @@
|
|||||||
package com.arialyy.aria.core.upload;
|
package com.arialyy.aria.core.upload;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import com.arialyy.aria.core.inf.AbsDownloadTarget;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.AbsUploadTarget;
|
import com.arialyy.aria.core.inf.AbsUploadTarget;
|
||||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2017/2/28.
|
* Created by lyy on 2017/2/28.
|
||||||
@@ -45,6 +43,7 @@ public class UploadTarget extends AbsUploadTarget<UploadTarget, UploadEntity, Up
|
|||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
//http暂时不支持断点上传
|
//http暂时不支持断点上传
|
||||||
mTaskEntity.isSupportBP = false;
|
mTaskEntity.isSupportBP = false;
|
||||||
|
mTaskEntity.requestType = AbsTaskEntity.U_HTTP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -72,10 +72,9 @@ class Uploader extends AbsFileer<UploadEntity, UploadTaskEntity> {
|
|||||||
|
|
||||||
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<UploadTaskEntity> config) {
|
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<UploadTaskEntity> config) {
|
||||||
switch (mTaskEntity.requestType) {
|
switch (mTaskEntity.requestType) {
|
||||||
case AbsTaskEntity.FTP:
|
case AbsTaskEntity.U_FTP:
|
||||||
case AbsTaskEntity.FTP_DIR:
|
|
||||||
return new FtpThreadTask(mConstance, mListener, config);
|
return new FtpThreadTask(mConstance, mListener, config);
|
||||||
case AbsTaskEntity.HTTP:
|
case AbsTaskEntity.U_HTTP:
|
||||||
return new HttpThreadTask(mConstance, (IUploadListener) mListener, config);
|
return new HttpThreadTask(mConstance, (IUploadListener) mListener, config);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@@ -72,19 +72,33 @@ public class CheckUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测下载链接是否为null
|
* 检查下载实体
|
||||||
*/
|
*/
|
||||||
public static void checkDownloadUrl(String downloadUrl) {
|
public static void checkDownloadEntity(DownloadEntity entity) {
|
||||||
if (TextUtils.isEmpty(downloadUrl)) throw new IllegalArgumentException("下载链接不能为null");
|
checkUrl(entity.getUrl());
|
||||||
|
checkPath(entity.getDownloadPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测下载链接是否为null
|
* 检测下载链接是否为null
|
||||||
*/
|
*/
|
||||||
public static void checkUploadUrl(String downloadUrl) {
|
public static void checkPath(String path) {
|
||||||
if (TextUtils.isEmpty(downloadUrl)) throw new IllegalArgumentException("上传地址不能为null");
|
if (TextUtils.isEmpty(path)) {
|
||||||
|
throw new IllegalArgumentException("保存路径不能为null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测下载链接是否为null
|
||||||
|
*/
|
||||||
|
public static void checkUrl(String url) {
|
||||||
|
Log.d(TAG, url.startsWith("http") + "");
|
||||||
|
if (TextUtils.isEmpty(url)) {
|
||||||
|
throw new IllegalArgumentException("下载链接不能为null");
|
||||||
|
} else if (!url.startsWith("http") && !url.startsWith("ftp")) {
|
||||||
|
throw new IllegalArgumentException("url错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测下载链接组是否为null
|
* 检测下载链接组是否为null
|
||||||
@@ -108,9 +122,13 @@ public class CheckUtil {
|
|||||||
* 检测上传地址是否为null
|
* 检测上传地址是否为null
|
||||||
*/
|
*/
|
||||||
public static void checkUploadPath(String uploadPath) {
|
public static void checkUploadPath(String uploadPath) {
|
||||||
if (TextUtils.isEmpty(uploadPath)) throw new IllegalArgumentException("上传地址不能为null");
|
if (TextUtils.isEmpty(uploadPath)) {
|
||||||
|
throw new IllegalArgumentException("上传地址不能为null");
|
||||||
|
}
|
||||||
File file = new File(uploadPath);
|
File file = new File(uploadPath);
|
||||||
if (!file.exists()) throw new IllegalArgumentException("上传文件不存在");
|
if (!file.exists()) {
|
||||||
|
throw new IllegalArgumentException("上传文件不存在");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -35,7 +35,8 @@ import java.io.File;
|
|||||||
* Ftp下载测试
|
* Ftp下载测试
|
||||||
*/
|
*/
|
||||||
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
||||||
private final String URL = "ftp://172.18.104.229:21/haha/测试ss123/ftp_test.apk";
|
//private final String URL = "ftp://172.18.104.229:21/haha/测试ss123/ftp_test.apk";
|
||||||
|
private final String URL = "ftp://ygdy8:ygdy8@yg72.dydytt.net:8073/[阳光电影www.ygdy8.com].杀人者的记忆法.HD.720p.韩语中字.rmvb";
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
@@ -58,7 +59,8 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
|
|||||||
case R.id.start:
|
case R.id.start:
|
||||||
Aria.download(this)
|
Aria.download(this)
|
||||||
.loadFtp(URL, true)
|
.loadFtp(URL, true)
|
||||||
.login("lao", "123456")
|
.charSet("gbk")
|
||||||
|
//.login("lao", "123456")
|
||||||
.setDownloadPath("/mnt/sdcard/")
|
.setDownloadPath("/mnt/sdcard/")
|
||||||
.start();
|
.start();
|
||||||
break;
|
break;
|
||||||
|
@@ -28,6 +28,7 @@ import com.arialyy.aria.core.Aria;
|
|||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||||
import com.arialyy.aria.core.inf.AbsEntity;
|
import com.arialyy.aria.core.inf.AbsEntity;
|
||||||
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
@@ -206,11 +207,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
|
|||||||
@Override public void onClick(View v) {
|
@Override public void onClick(View v) {
|
||||||
mData.remove(entity);
|
mData.remove(entity);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
if (isSimpleDownload(entity)) {
|
cancel(entity);
|
||||||
Aria.download(getContext()).load((DownloadEntity) entity).cancel(true);
|
|
||||||
} else {
|
|
||||||
Aria.download(getContext()).load((DownloadGroupEntity) entity).cancel(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//if (holder instanceof GroupHolder){
|
//if (holder instanceof GroupHolder){
|
||||||
@@ -267,21 +264,58 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancel(AbsEntity entity) {
|
||||||
|
switch (entity.getTaskType()) {
|
||||||
|
case AbsTaskEntity.D_FTP:
|
||||||
|
Aria.download(getContext())
|
||||||
|
.loadFtp((DownloadEntity) entity)
|
||||||
|
//.login("lao", "123456")
|
||||||
|
.cancel(true);
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_FTP_DIR:
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_HTTP:
|
||||||
|
Aria.download(getContext()).load((DownloadEntity) entity).cancel(true);
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.DG_HTTP:
|
||||||
|
Aria.download(getContext()).load((DownloadGroupEntity) entity).cancel(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void start(AbsEntity entity) {
|
private void start(AbsEntity entity) {
|
||||||
if (isSimpleDownload(entity)) {
|
switch (entity.getTaskType()) {
|
||||||
|
case AbsTaskEntity.D_FTP:
|
||||||
|
//Aria.download(getContext()).loadFtp((DownloadEntity) entity).login("lao", "123456").start();
|
||||||
|
Aria.download(getContext()).loadFtp((DownloadEntity) entity).charSet("GBK").start();
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_FTP_DIR:
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_HTTP:
|
||||||
Aria.download(getContext()).load((DownloadEntity) entity).start();
|
Aria.download(getContext()).load((DownloadEntity) entity).start();
|
||||||
} else {
|
break;
|
||||||
|
case AbsTaskEntity.DG_HTTP:
|
||||||
Aria.download(getContext()).load((DownloadGroupEntity) entity).start();
|
Aria.download(getContext()).load((DownloadGroupEntity) entity).start();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop(AbsEntity entity) {
|
private void stop(AbsEntity entity) {
|
||||||
if (isSimpleDownload(entity)) {
|
switch (entity.getTaskType()) {
|
||||||
|
case AbsTaskEntity.D_FTP:
|
||||||
|
//Aria.download(getContext()).loadFtp((DownloadEntity) entity).login("lao", "123456").stop();
|
||||||
|
Aria.download(getContext()).loadFtp((DownloadEntity) entity).charSet("GBK").stop();
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_FTP_DIR:
|
||||||
|
break;
|
||||||
|
case AbsTaskEntity.D_HTTP:
|
||||||
Aria.download(getContext()).load((DownloadEntity) entity).stop();
|
Aria.download(getContext()).load((DownloadEntity) entity).stop();
|
||||||
} else {
|
break;
|
||||||
|
case AbsTaskEntity.DG_HTTP:
|
||||||
Aria.download(getContext()).load((DownloadGroupEntity) entity).stop();
|
Aria.download(getContext()).load((DownloadGroupEntity) entity).stop();
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
|
|||||||
private final String URL = "ftp://172.18.104.49:21/upload/测试";
|
private final String URL = "ftp://172.18.104.49:21/upload/测试";
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
setTile("FTP 文件上传");
|
setTile("D_FTP 文件上传");
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
Aria.upload(this).register();
|
Aria.upload(this).register();
|
||||||
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH);
|
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH);
|
||||||
|
@@ -42,7 +42,7 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
setTile("HTTP 上传");
|
setTile("D_HTTP 上传");
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
Aria.upload(this).register();
|
Aria.upload(this).register();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user