Skip to content
Permalink
Browse files

优化上传任务target的代码

  • Loading branch information...
AriaLyy committed Apr 8, 2019
1 parent 30c41e4 commit b3501dc3c3ae3284fc01d15b6e233695a27d8fd9
Showing with 2,566 additions and 2,912 deletions.
  1. +70 −70 Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java
  2. +15 −18 Aria/src/main/java/com/arialyy/aria/core/download/{BaseGroupTarget.java → AbsDGTarget.java}
  3. +2 −66 Aria/src/main/java/com/arialyy/aria/core/download/AbsDownloadTarget.java
  4. +0 −199 Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  5. +62 −27 Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java
  6. +14 −21 Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  7. +4 −16 Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  8. +4 −5 Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  9. +6 −6 Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  10. +10 −10 Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  11. +1 −21 Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java
  12. +0 −146 Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java
  13. +3 −1 Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java
  14. +18 −5 Aria/src/main/java/com/arialyy/aria/core/upload/UNormalDelegate.java
  15. +1 −1 Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  16. +194 −199 Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  17. +24 −0 Aria/src/main/java/com/arialyy/aria/exception/ParamException.java
  18. +289 −289 Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  19. +253 −237 Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  20. +1,232 −1,202 Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  21. +4 −0 DEV_LOG.md
  22. +160 −160 app/src/main/assets/aria_config.xml
  23. +2 −2 app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  24. +1 −1 app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java
  25. +4 −17 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  26. +80 −80 app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java
  27. +113 −113 app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
@@ -1,70 +1,70 @@
/*
* 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.aria.core.common.ftp;

import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IFtpTarget;
import com.arialyy.aria.util.ALog;
import java.net.Proxy;

/**
* Created by laoyuyu on 2018/3/9.
* ftp 委托
*/
public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET> {
private static final String TAG = "FtpDelegate";
private FtpUrlEntity mUrlEntity;
private TARGET mTarget;

public FtpDelegate(TARGET target) {
mTarget = target;
mUrlEntity = target.getTaskWrapper().asFtp().getUrlEntity();
}

@Override public TARGET charSet(String charSet) {
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
mTarget.getTaskWrapper().asFtp().setCharSet(charSet);
return mTarget;
}

@Override public TARGET login(String userName, String password) {
return login(userName, password, null);
}

@Override public TARGET login(String userName, String password, String account) {
if (TextUtils.isEmpty(userName)) {
ALog.e(TAG, "用户名不能为null");
return mTarget;
} else if (TextUtils.isEmpty(password)) {
ALog.e(TAG, "密码不能为null");
return mTarget;
}
mUrlEntity.needLogin = true;
mUrlEntity.user = userName;
mUrlEntity.password = password;
mUrlEntity.account = account;
return mTarget;
}

@Override public TARGET setProxy(Proxy proxy) {
mTarget.getTaskWrapper().asFtp().setProxy(proxy);
return mTarget;
}
}
/*
* 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.aria.core.common.ftp;

import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IFtpTarget;
import com.arialyy.aria.util.ALog;
import java.net.Proxy;

/**
* Created by laoyuyu on 2018/3/9.
* ftp 委托
*/
public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET> {
private static final String TAG = "FtpDelegate";
private TARGET mTarget;

public FtpDelegate(TARGET target) {
mTarget = target;
}

@Override public TARGET charSet(String charSet) {
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
mTarget.getTaskWrapper().asFtp().setCharSet(charSet);
return mTarget;
}

@Override public TARGET login(String userName, String password) {
return login(userName, password, null);
}

@Override public TARGET login(String userName, String password, String account) {
if (TextUtils.isEmpty(userName)) {
ALog.e(TAG, "用户名不能为null");
return mTarget;
} else if (TextUtils.isEmpty(password)) {
ALog.e(TAG, "密码不能为null");
return mTarget;
}
// urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的
FtpUrlEntity urlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity();
urlEntity.needLogin = true;
urlEntity.user = userName;
urlEntity.password = password;
urlEntity.account = account;
return mTarget;
}

@Override public TARGET setProxy(Proxy proxy) {
mTarget.getTaskWrapper().asFtp().setProxy(proxy);
return mTarget;
}
}
@@ -19,6 +19,7 @@
import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.orm.DbEntity;
@@ -30,8 +31,7 @@
/**
* Created by lyy on 2017/7/26.
*/
abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
extends AbsTarget<TARGET, DownloadGroupEntity, DGTaskWrapper> {
abstract class AbsDGTarget<TARGET extends AbsDGTarget> extends AbsTarget<TARGET> {

/**
* 组任务名
@@ -61,32 +61,28 @@ public SubTaskManager getSubTaskManager() {
return mSubTaskManager;
}

@Override public DownloadGroupEntity getEntity() {
return (DownloadGroupEntity) super.getEntity();
}

@Override public DGTaskWrapper getTaskWrapper() {
return (DGTaskWrapper) super.getTaskWrapper();
}

/**
* 设置任务组别名
*/
@CheckResult
public TARGET setGroupAlias(String alias) {
if (TextUtils.isEmpty(alias)) return (TARGET) this;
mEntity.setAlias(alias);
getEntity().setAlias(alias);
return (TARGET) this;
}

@Override public boolean taskExists() {
return DbEntity.checkDataExist(DownloadGroupEntity.class, "groupHash=?", mGroupHash);
}

/**
* 设置任务组的文件夹路径,该api后续会删除
*
* @param groupDirPath 任务组保存文件夹路径
* @deprecated {@link #setDirPath(String)} 请使用这个api
*/
@Deprecated
@CheckResult
public TARGET setDownloadDirPath(String groupDirPath) {
return setDirPath(groupDirPath);
}

/**
* 设置任务组的文件夹路径,在Aria中,任务组的所有子任务都会下载到以任务组组名的文件夹中。
* 如:groupDirPath = "/mnt/sdcard/download/group_test"
@@ -113,7 +109,7 @@ public TARGET setDirPath(String dirPath) {
}

@Override public boolean isRunning() {
DownloadGroupTask task = DownloadGroupTaskQueue.getInstance().getTask(mEntity.getKey());
DownloadGroupTask task = DownloadGroupTaskQueue.getInstance().getTask(getEntity().getKey());
return task != null && task.isRunning();
}

@@ -160,12 +156,13 @@ boolean checkDirPath() {
return false;
}

if (TextUtils.isEmpty(mEntity.getDirPath()) || !mEntity.getDirPath().equals(mDirPathTemp)) {
if (TextUtils.isEmpty(getEntity().getDirPath()) || !getEntity().getDirPath()
.equals(mDirPathTemp)) {
if (!file.exists()) {
file.mkdirs();
}
needModifyPath = true;
mEntity.setDirPath(mDirPathTemp);
getEntity().setDirPath(mDirPathTemp);
ALog.i(TAG, String.format("文件夹路径改变,将更新文件夹路径为:%s", mDirPathTemp));
}

@@ -23,22 +23,7 @@
/**
* Created by lyy on 2017/2/28.
*/
abstract class AbsDownloadTarget<TARGET extends AbsDownloadTarget>
extends AbsTarget<TARGET, DownloadEntity, DTaskWrapper> {

/**
* 设置的文件保存路径的临时变量
*/
private String mTempFilePath;

/**
* {@code true}强制下载,不考虑文件路径是否被占用
*/
private boolean forceDownload = false;
/**
* 资源地址
*/
private String mUrl, mNewUrl;
abstract class AbsDownloadTarget<TARGET extends AbsDownloadTarget> extends AbsTarget<TARGET> {

/**
* 更新下载url
@@ -66,56 +51,7 @@ public void setHighestPriority() {
}
}

/**
* 是否强制下载文件 {@link DownloadTarget#setFilePath(String, boolean)}、
* {@link FtpDownloadTarget#setFilePath(String, boolean)}
*
* @return {@code true} 强制下载文件
*/
boolean isForceDownload() {
return forceDownload;
}

@Override public void setTaskWrapper(DTaskWrapper taskWrapper) {
super.setTaskWrapper(taskWrapper);
}

/**
* 文件保存路径的临时变量
*/
String getTempFilePath() {
return mTempFilePath;
}

void setForceDownload(boolean forceDownload) {
this.forceDownload = forceDownload;
}

public String getUrl() {
return mUrl;
}

void setUrl(String url) {
this.mUrl = url;
}

String getNewUrl() {
return mNewUrl;
}

void setNewUrl(String newUrl) {
this.mNewUrl = newUrl;
}

void setTempFilePath(String mTempFilePath) {
this.mTempFilePath = mTempFilePath;
}

public void setEntity(DownloadEntity entity) {
mEntity = entity;
}

@Override public DownloadEntity getEntity() {
return super.getEntity();
return (DownloadEntity) super.getEntity();
}
}
Oops, something went wrong.

0 comments on commit b3501dc

Please sign in to comment.
You can’t perform that action at this time.