diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index 586ceb4e..1eb12427 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -86,8 +86,27 @@ class ConfigHelper extends DefaultHandler { case "queueMod": loadQueueMod(value); break; + case "updateInterval": + loadUpdateInterval(value); + break; + } + } + } + + private void loadUpdateInterval(String value) { + long temp = 1000; + if (!TextUtils.isEmpty(value)) { + temp = Long.parseLong(value); + if (temp <= 0) { + temp = 1000; } } + if (isDownloadConfig) { + mDownloadConfig.updateInterval = temp; + } + if (isUploadConfig) { + mUploadConfig.updateInterval = temp; + } } private void loadQueueMod(String value) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 78c0fe71..c7fb1145 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -40,6 +40,9 @@ import java.util.concurrent.Executors; */ public abstract class AbsFileer> implements Runnable, IUtil { + public static final String STATE = "_state_"; + public static final String RECORD = "_record_"; + private final String TAG = "AbsFileer"; protected IEventListener mListener; protected TASK_ENTITY mTaskEntity; @@ -63,6 +66,7 @@ public abstract class AbsFileer= 0) { Long r = Long.parseLong(record + ""); - if (r > startL) { + //记录的位置需要在线程区间中 + if (startL < r && r < (i == (mTotalThreadNum - 1) ? fileLength : endL)) { mConstance.CURRENT_LOCATION += r - startL; startL = r; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java index c490372e..fd6952d8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java @@ -263,10 +263,10 @@ public abstract class AbsThreadTask= mConfig.END_LOCATION || isComplete) { - key = mConfig.TEMP_FILE.getName() + "_state_" + mConfig.THREAD_ID; + key = mConfig.TEMP_FILE.getName() + AbsFileer.STATE + mConfig.THREAD_ID; value = "1"; } else if (0 < record && record < mConfig.END_LOCATION) { - key = mConfig.TEMP_FILE.getName() + "_record_" + mConfig.THREAD_ID; + key = mConfig.TEMP_FILE.getName() + AbsFileer.RECORD + mConfig.THREAD_ID; value = String.valueOf(record); } if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java index 386c55f0..e42e3f86 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java @@ -63,7 +63,7 @@ public class StateConstance { * 所有子线程是否都已经完成下载 */ public boolean isComplete() { - return COMPLETE_THREAD_NUM == THREAD_NUM; + return COMPLETE_THREAD_NUM >= THREAD_NUM; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java index 7c68b96d..ce686b2d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java @@ -41,6 +41,7 @@ class BaseDListener(outHandler); @@ -51,6 +52,7 @@ class BaseDListener { Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) { super(listener, taskEntity); + setUpdateInterval( + AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval()); } @Override protected void checkTask() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java index be5e1bc8..b63fad34 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java @@ -36,10 +36,6 @@ public abstract class AbsTaskEntity extends DbEntity { * HTTP任务组下载 */ public static final int DG_HTTP = 0x12; - /** - * HTTP单文件上传 - */ - public static final int U_HTTP = 0xA1; /** * FTP单文件下载 @@ -49,6 +45,11 @@ public abstract class AbsTaskEntity extends DbEntity { * FTP文件夹下载,为避免登录过多,子任务由单线程进行处理 */ public static final int D_FTP_DIR = 0x14; + + /** + * HTTP单文件上传 + */ + public static final int U_HTTP = 0xA1; /** * FTP单文件上传 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java index a0591d78..48aa5b73 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java @@ -41,6 +41,7 @@ class BaseUListener(outHandler); @@ -51,6 +52,7 @@ class BaseUListener { } uploadFile(writer, mTaskEntity.attachment, uploadFile); finish(writer); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); fail(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java index 753be0b9..94c9d486 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload.uploader; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.OnFileInfoCallback; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTaskEntity; @@ -47,19 +48,26 @@ public class SimpleUploadUtil implements IUtil, Runnable { @Override public void run() { mListener.onPre(); - new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() { - @Override public void onComplete(String url, int code) { - if (code == FtpFileInfoThread.CODE_COMPLETE) { - mListener.onComplete(); - } else { - mUploader.start(); - } - } + switch (mTaskEntity.requestType) { + case AbsTaskEntity.U_FTP: + new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() { + @Override public void onComplete(String url, int code) { + if (code == FtpFileInfoThread.CODE_COMPLETE) { + mListener.onComplete(); + } else { + mUploader.start(); + } + } - @Override public void onFail(String url, String errorMsg, boolean needRetry) { - mListener.onFail(needRetry); - } - }).start(); + @Override public void onFail(String url, String errorMsg, boolean needRetry) { + mListener.onFail(needRetry); + } + }).start(); + break; + case AbsTaskEntity.U_HTTP: + mUploader.start(); + break; + } } @Override public long getFileSize() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java index ecfa041a..a8b5b607 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.upload.uploader; +import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.AbsFileer; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.SubThreadConfig; @@ -35,6 +36,8 @@ class Uploader extends AbsFileer { Uploader(IUploadListener listener, UploadTaskEntity taskEntity) { super(listener, taskEntity); mTempFile = new File(mEntity.getFilePath()); + setUpdateInterval( + AriaManager.getInstance(AriaManager.APP).getUploadConfig().getUpdateInterval()); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index e0884fb1..c3dd262b 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -200,7 +200,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "'" + expression[i + 1] + "'"; + params[i] = "\"" + expression[i + 1] + "\""; } sql = String.format(sql, params); print(FIND_DATA, sql); @@ -223,7 +223,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "'" + expression[i + 1] + "'"; + params[i] = "\"" + expression[i + 1] + "\""; } sql = String.format(sql, params); print(FIND_DATA, sql); @@ -265,7 +265,7 @@ final class SqlHelper extends SQLiteOpenHelper { sb.append("SELECT rowid, * FROM ").append(CommonUtil.getClassName(clazz)).append(" where "); int i = 0; for (Object where : wheres) { - sb.append(where).append("=").append("'").append(values[i]).append("'"); + sb.append(where).append("=").append("\"").append(values[i]).append("\""); sb.append(i >= wheres.length - 1 ? "" : " AND "); i++; } @@ -315,7 +315,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "'" + expression[i + 1] + "'"; + params[i] = "\"" + expression[i + 1] + "\""; } sql = String.format(sql, params); SqlHelper.print(DEL_DATA, sql); @@ -350,7 +350,7 @@ final class SqlHelper extends SQLiteOpenHelper { //sb.append(field.getName()).append("='"); String value; prams.append(i > 0 ? ", " : ""); - prams.append(field.getName()).append("='"); + prams.append(field.getName()).append("=\""); Type type = field.getType(); if (type == Map.class) { value = SqlUtil.map2Str((Map) field.get(dbEntity)); @@ -370,7 +370,7 @@ final class SqlHelper extends SQLiteOpenHelper { //sb.append(value == null ? "" : value); //sb.append("'"); prams.append(TextUtils.isEmpty(value) ? "" : value); - prams.append("'"); + prams.append("\""); } catch (IllegalAccessException e) { e.printStackTrace(); } @@ -415,7 +415,7 @@ final class SqlHelper extends SQLiteOpenHelper { continue; } sb.append(i > 0 ? ", " : ""); - sb.append("'"); + sb.append("\""); Type type = field.getType(); if (type == Map.class) { sb.append(SqlUtil.map2Str((Map) field.get(dbEntity))); @@ -430,7 +430,7 @@ final class SqlHelper extends SQLiteOpenHelper { } else { sb.append(field.get(dbEntity)); } - sb.append("'"); + sb.append("\""); i++; } } catch (IllegalAccessException e) { diff --git a/DEV_LOG.md b/DEV_LOG.md index 69d361d2..3b31349b 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,10 @@ ## 开发日志 + + v_3.3.11 + - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 + `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 + - 修复下载过程中kill进程可能出现的文件错误的问题 https://github.com/AriaLyy/Aria/issues/192 + - 修复http上传的空指针问题 https://github.com/AriaLyy/Aria/issues/193 + - 修复下载地址中含有`'`导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/194 + v_3.3.10 - 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181 - 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182 diff --git a/README.md b/README.md index c53e24bc..fa3e5ce3 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.3.10' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.10' +compile 'com.arialyy.aria:aria-core:3.3.11' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.11' ``` 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) @@ -97,9 +97,12 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 升级日志 -+ v_3.3.10 - - 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181 - - 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182 ++ v_3.3.11 + - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 + `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 + - 修复下载过程中kill进程可能出现的文件错误的问题 https://github.com/AriaLyy/Aria/issues/192 + - 修复http上传的空指针问题 https://github.com/AriaLyy/Aria/issues/193 + - 修复下载地址中含有`'`导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/194 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 92324c01..ce92a575 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -34,6 +34,9 @@ + + + @@ -54,6 +57,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index afa60d39..d6b07b78 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -62,7 +62,8 @@ public class SingleTaskActivity extends BaseActivity { //不支持断点的链接 //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; - "http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + "https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -157,6 +158,7 @@ public class SingleTaskActivity extends BaseActivity { mStart.setText("开始"); setBtState(true); getBinding().setSpeed(""); + Log.d(TAG, "cancel"); } @Download.onTaskFail void taskFail(DownloadTask task) { diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java index 0793d9a3..428d3f90 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java @@ -19,6 +19,7 @@ package com.arialyy.simple.download.multi_download; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import butterknife.Bind; @@ -29,10 +30,12 @@ import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.AbsEntity; +import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.show.L; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityMultiDownloadBinding; +import java.io.File; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java index fe422b61..00037fcd 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java @@ -21,6 +21,7 @@ import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.View; import butterknife.Bind; import com.arialyy.annotations.Download; @@ -28,10 +29,12 @@ import com.arialyy.annotations.DownloadGroup; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadTask; +import com.arialyy.frame.util.FileUtil; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityMultiBinding; import com.arialyy.simple.download.DownloadModule; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -95,6 +98,10 @@ public class MultiTaskActivity extends BaseActivity { mAdapter.updateBtState(task.getKey(), true); } + @Download.onTaskComplete void taskComplete(DownloadTask task){ + Log.d(TAG, FileUtil.getFileMD5(new File(task.getDownloadPath()))); + } + //############################### 任务组 ############################## @DownloadGroup.onTaskComplete void groupTaskComplete(DownloadGroupTask task) { mAdapter.updateBtState(task.getKey(), true); diff --git a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java index 6485ed54..91963876 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -35,7 +35,7 @@ public class HttpUploadActivity extends BaseActivity { private static final String TAG = "HttpUploadActivity"; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; - private static final String FILE_PATH = "/sdcard/large.rar"; + private static final String FILE_PATH = "/mnt/sdcard/gg.zip"; @Override protected int setLayoutId() { return R.layout.activity_upload; @@ -50,8 +50,8 @@ public class HttpUploadActivity extends BaseActivity { @OnClick(R.id.upload) void upload() { Aria.upload(HttpUploadActivity.this) .load(FILE_PATH) - .setUploadUrl("http://172.18.104.66:8080/upload/sign_file") - .setAttachment("file") + .setUploadUrl("http://192.168.1.9:8080/upload/") + .setAttachment("serveFile") .start(); } diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java index 6ae2b732..1b4b060e 100644 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -19,6 +19,7 @@ import android.text.TextUtils; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.lang.reflect.Field; @@ -39,6 +40,11 @@ class Configuration { * 通用配置 */ public static class BaseConfig { + /** + * 进度刷新间隔,默认1秒 + */ + long updateInterval = 1000; + /** * 旧任务数 */ @@ -73,6 +79,25 @@ class Configuration { */ String queueMod = "wait"; + public long getUpdateInterval() { + return updateInterval; + } + + /** + * 设置进度更新间隔,该设置对正在运行的任务无效,默认为1000毫秒 + * + * @param updateInterval 不能小于0 + */ + public BaseConfig setUpdateInterval(long updateInterval) { + if (updateInterval <= 0) { + ALog.w("Configuration", "进度更新间隔不能小于0"); + return this; + } + this.updateInterval = updateInterval; + saveKey("updateInterval", String.valueOf(updateInterval)); + return this; + } + public String getQueueMod() { return queueMod; } @@ -272,7 +297,7 @@ class Configuration { return this; } - public void setThreadNum(int threadNum){ + public void setThreadNum(int threadNum) { this.threadNum = threadNum; saveKey("threadNum", String.valueOf(threadNum)); } diff --git a/build.gradle b/build.gradle index f7cca8f1..0f373625 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.10' + publishVersion = '3.3.11' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'