laoyuyu 6 years ago
parent 44f3b4faf1
commit f5967152db
  1. 4
      Aria/build.gradle
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java
  4. 7
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  5. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  7. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java
  8. 27
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  10. 13
      DEV_LOG.md
  11. 4
      app/src/main/AndroidManifest.xml
  12. 7
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  13. 10
      app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java

@ -26,8 +26,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaAnnotations')
compile 'com.arialyy.aria:aria-ftp-plug:1.0.4'
// compile 'com.arialyy.aria:aria-ftp-plug:1.0.4'
// compile project(':AriaFtpPlug')
compile project(':AriaFtpPlug')
}
apply from: 'bintray-release.gradle'

@ -130,6 +130,14 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends
: mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));
}
protected void handleComplete(){
mEntity.setComplete(true);
mEntity.setCompleteTime(System.currentTimeMillis());
mEntity.setCurrentProgress(mEntity.getFileSize());
mEntity.setPercent(100);
handleSpeed(0);
}
/**
* 将任务状态发送给下载器
*

@ -17,6 +17,7 @@ package com.arialyy.aria.core.common.ftp;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import aria.apache.commons.net.ftp.FTP;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPFile;
@ -119,6 +120,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
client.disconnect();
return;
}
// 检查ftp文件是否被打开
//为了防止编码错乱,需要使用原始字符串
mSize = getFileSize(files, client, setRemotePath());
int reply = client.getReplyCode();
@ -339,6 +343,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
for (FTPFile file : files) {
if (file.isFile()) {
size += file.getSize();
ALog.d(TAG, "isValid = " + file.isValid());
handleFile(path + file.getName(), file);
} else {
String remotePath =

@ -54,7 +54,7 @@ public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEnti
protected void saveData(int state, long location) {
mTaskEntity.setState(state);
mEntity.setState(state);
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) {
if (mEntity instanceof DownloadEntity) {
CommonUtil.delTaskRecord(mEntity.getDownloadPath(), 1, mTaskEntity.isRemoveFile());
@ -62,9 +62,8 @@ public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEnti
return;
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());
} else if (mEntity.isComplete()) {
mEntity.setCompleteTime(System.currentTimeMillis());
mEntity.setCurrentProgress(mEntity.getFileSize());
} else if (state == IEntity.STATE_COMPLETE) {
handleComplete();
}
if (location > 0) {
mEntity.setCurrentProgress(location);

@ -27,8 +27,7 @@ import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
/**
* Created by Aria.Lao on 2017/7/20.
* 任务组下载事件
* Created by Aria.Lao on 2017/7/20. 任务组下载事件
*/
class DownloadGroupListener
extends BaseListener<DownloadGroupEntity, DownloadGroupTaskEntity, DownloadGroupTask>
@ -124,7 +123,6 @@ class DownloadGroupListener
@Override protected void saveData(int state, long location) {
mTaskEntity.setState(state);
mEntity.setState(state);
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) {
if (mEntity instanceof DownloadGroupEntity) {
CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), mEntity);
@ -132,9 +130,8 @@ class DownloadGroupListener
return;
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());
} else if (mEntity.isComplete()) {
mEntity.setCompleteTime(System.currentTimeMillis());
mEntity.setCurrentProgress(mEntity.getFileSize());
} else if (state == IEntity.STATE_COMPLETE) {
handleComplete();
}
if (location > 0) {
mEntity.setCurrentProgress(location);

@ -67,7 +67,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable,
/**
* 进度百分比
*/
@Ignore private int percent;
private int percent;
private boolean isComplete = false;

@ -39,7 +39,6 @@ class BaseUListener extends BaseListener<UploadEntity, UploadTaskEntity, UploadT
protected void saveData(int state, long location) {
mTaskEntity.setState(state);
mEntity.setState(state);
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) {
if (mEntity instanceof UploadEntity) {
CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskEntity.isRemoveFile());
@ -47,9 +46,8 @@ class BaseUListener extends BaseListener<UploadEntity, UploadTaskEntity, UploadT
return;
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());
} else if (mEntity.isComplete()) {
mEntity.setCompleteTime(System.currentTimeMillis());
mEntity.setCurrentProgress(mEntity.getFileSize());
} else if (state == IEntity.STATE_COMPLETE) {
handleComplete();
} else if (location > 0) {
mEntity.setCurrentProgress(location);
}

@ -32,11 +32,10 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
* Created by Aria.Lao on 2017/7/28.
* FTP 单线程上传任务需要FTP 服务器给用户打开append和write的权限
* Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务需要FTP 服务器给用户打开append和write的权限
*/
class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
private final String TAG = "FtpUploadThreadTask";
private final String TAG = "FtpThreadTask";
private String dir, remotePath;
FtpThreadTask(StateConstance constance, IEventListener listener,
@ -85,8 +84,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
//file.skipBytes((int) mConfig.START_LOCATION);
file.seek(mConfig.START_LOCATION);
}
upload(client, file);
if (isBreak()) {
boolean complete = upload(client, file);
if (!complete || isBreak()) {
return this;
}
ALog.i(TAG,
@ -131,7 +130,13 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
SERVER_CHARSET);
}
private void upload(final FTPClient client, final BufferedRandomAccessFile bis)
/**
* 上传
*
* @return {@code true}上传成功{@code false} 上传失败
* @throws IOException
*/
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis)
throws IOException {
try {
@ -156,12 +161,18 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
}
});
} catch (IOException e) {
String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(),
client.getReplyString(), mEntity.getFilePath());
if (client.isConnected()) {
client.disconnect();
}
if (e.getMessage().contains("AriaIOException caught while copying")) {
e.printStackTrace();
} else {
fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("上传失败,filePath: %s", mEntity.getFilePath()), e));
new AriaIOException(TAG, msg, e));
}
return false;
}
int reply = client.getReplyCode();
@ -175,6 +186,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
if (client.isConnected()) {
client.disconnect();
}
return false;
}
return true;
}
}

@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 41;
static int VERSION = 42;
/**
* 是否将数据库保存在Sd卡{@code true}

@ -2,6 +2,19 @@
+ v_3.5.3
- 修复ftps不能加载默认证书的bug https://github.com/AriaLyy/Aria/issues/334
- 优化注解性能,移除不必要的判断代码
- 增加广播支持,详情见:http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html
- 增加get参数支持
```java
Aria.download(SingleTaskActivity.this)
.load(DOWNLOAD_URL) // url 必须是主体url,也就是?前面的内容
.setFilePath(path, true)
.asGet()
.setParams(params) // 设置参数
.start();
```
- fix bug https://github.com/AriaLyy/Aria/issues/335
- 新增进度百分比保存 https://github.com/AriaLyy/Aria/issues/336
- fix bug https://github.com/AriaLyy/Aria/issues/335
+ v_3.5.2
- 添加Serializable接口支持 https://github.com/AriaLyy/Aria/issues/320
- 失败回调增加错误原因 https://github.com/AriaLyy/Aria/issues/310

@ -20,7 +20,7 @@
<!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".MainActivity"-->
<activity
android:name=".download.SingleTaskActivity"
android:name=".upload.FtpUploadActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -40,7 +40,7 @@
<activity android:name=".download.FtpDownloadActivity"/>
<activity android:name=".download.group.FTPDirDownloadActivity"/>
<activity android:name=".upload.HttpUploadActivity"/>
<activity android:name=".upload.FtpUploadActivity"/>
<!--<activity android:name=".upload.FtpUploadActivity"/>-->
<service android:name=".download.service_download.DownloadService"/>
</application>

@ -66,7 +66,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//"http://9.9.9.50:5000/download1";
"http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
//"http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
"http://cdn-s1.touchfound.com/theme/1543979562763_6907.zip";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@ -312,8 +313,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
.useServerFileName(true)
.setFilePath(path, true)
//.asGet()
.asPost()
.setParams(params)
//.asPost()
//.setParams(params)
//.setExtendField("{\n"
// + "\"id\":\"你的样子\"\n< > "
// + "}")

@ -22,6 +22,7 @@ import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
@ -35,14 +36,15 @@ import java.io.File;
* Ftp 文件上传demo
*/
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private final String FILE_PATH = "/mnt/sdcard/sql.rar";
private final String URL = "ftp://192.168.1.7:21/aa//你好";
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar";
private final String URL = "ftp://9.9.9.50:21/aa/你好";
@Override protected void init(Bundle savedInstanceState) {
setTile("D_FTP 文件上传");
super.init(savedInstanceState);
Aria.upload(this).register();
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH);
ALog.d(TAG, "pare = >" + entity.getPercent());
if (entity != null) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
@ -96,6 +98,10 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
Log.d(TAG, "删除任务");
}
@Upload.onTaskFail public void taskFail(UploadTask task) {
Log.d(TAG, "上传失败");
}
@Upload.onTaskRunning public void taskRunning(UploadTask task) {
Log.d(TAG, "PP = " + task.getPercent());
getBinding().setProgress(task.getPercent());

Loading…
Cancel
Save