From 2fabf1a168cc598bb234640bf1bed361b854149a Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Sun, 4 Jun 2017 00:07:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=83=A8=E5=88=86=E7=9A=84=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E4=BD=93=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/command/AbsCmd.java | 4 +- .../com/arialyy/aria/core/command/AddCmd.java | 4 +- .../arialyy/aria/core/command/CancelCmd.java | 4 +- .../arialyy/aria/core/command/CmdFactory.java | 4 +- .../aria/core/command/HighestPriorityCmd.java | 4 +- .../arialyy/aria/core/command/StartCmd.java | 4 +- .../arialyy/aria/core/command/StopCmd.java | 4 +- .../aria/core/download/DownloadEntity.java | 149 +---------------- .../aria/core/download/DownloadTask.java | 131 +-------------- .../core/download/DownloadTaskEntity.java | 7 +- .../com/arialyy/aria/core/inf/AbsEntity.java | 140 +++++++++++++++- .../com/arialyy/aria/core/inf/AbsTarget.java | 2 +- .../com/arialyy/aria/core/inf/AbsTask.java | 156 +++++++++++++++++- .../{ITaskEntity.java => AbsTaskEntity.java} | 4 +- .../com/arialyy/aria/core/inf/IEntity.java | 4 - .../java/com/arialyy/aria/core/inf/ITask.java | 4 +- .../arialyy/aria/core/queue/AbsTaskQueue.java | 6 +- .../aria/core/queue/DownloadTaskQueue.java | 8 - .../arialyy/aria/core/queue/ITaskQueue.java | 4 +- .../arialyy/aria/core/queue/TaskFactory.java | 4 +- .../aria/core/scheduler/UploadSchedulers.java | 6 +- .../aria/core/upload/UploadEntity.java | 84 +--------- .../arialyy/aria/core/upload/UploadTask.java | 134 +-------------- .../aria/core/upload/UploadTaskEntity.java | 7 +- .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 18 +- .../java/com/arialyy/aria/util/CheckUtil.java | 6 +- .../com/arialyy/aria/util/CommonUtil.java | 6 +- 28 files changed, 366 insertions(+), 544 deletions(-) rename Aria/src/main/java/com/arialyy/aria/core/inf/{ITaskEntity.java => AbsTaskEntity.java} (93%) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java index 3a93f415..1107dbfd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command; import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.inf.ICmd; @@ -30,7 +30,7 @@ import com.arialyy.aria.util.CommonUtil; * Created by lyy on 2016/8/22. * 下载命令 */ -public abstract class AbsCmd implements ICmd { +public abstract class AbsCmd implements ICmd { ITaskQueue mQueue; T mEntity; String TAG; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java index 0048d520..6bad005f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java @@ -18,13 +18,13 @@ package com.arialyy.aria.core.command; import android.util.Log; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/8/22. * 添加任务的命令 */ -class AddCmd extends AbsCmd { +class AddCmd extends AbsCmd { AddCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java index ee474d01..ad2aecd8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java @@ -18,13 +18,13 @@ package com.arialyy.aria.core.command; import android.text.TextUtils; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/9/20. * 取消命令 */ -class CancelCmd extends AbsCmd { +class CancelCmd extends AbsCmd { CancelCmd(String targetName, T entity) { super(targetName, entity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java index 84f9641a..7be00923 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java @@ -16,7 +16,7 @@ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by Lyy on 2016/9/23. @@ -72,7 +72,7 @@ public class CmdFactory { * @param type 命令类型{@link #TASK_CREATE}、{@link #TASK_START}、{@link #TASK_CANCEL}、{@link * #TASK_STOP}、{@link #TASK_HIGHEST_PRIORITY} */ - public AbsCmd createCmd(String target, T entity, int type) { + public AbsCmd createCmd(String target, T entity, int type) { switch (type) { case TASK_CREATE: return new AddCmd(target, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java index b693ec3c..7a3147b2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command; import android.text.TextUtils; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2017/6/2. @@ -29,7 +29,7 @@ import com.arialyy.aria.core.inf.ITaskEntity; * 5、如果下载队列中已经满了,则会停止队尾的任务 * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 */ -final class HighestPriorityCmd extends AbsCmd { +final class HighestPriorityCmd extends AbsCmd { /** * @param targetName 产生任务的对象名 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java index ce60242f..82821ea8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java @@ -18,13 +18,13 @@ package com.arialyy.aria.core.command; import android.text.TextUtils; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/8/22. * 开始命令 */ -class StartCmd extends AbsCmd { +class StartCmd extends AbsCmd { StartCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java index 645bf197..1e1fb295 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java @@ -20,13 +20,13 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/9/20. * 停止命令 */ -class StopCmd extends AbsCmd { +class StopCmd extends AbsCmd { StopCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index f937d321..5c0e18bf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -18,10 +18,8 @@ package com.arialyy.aria.core.download; import android.os.Parcel; import android.os.Parcelable; -import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.orm.Ignore; -import com.arialyy.aria.orm.DbEntity; /** * Created by lyy on 2015/12/25. @@ -29,50 +27,16 @@ import com.arialyy.aria.orm.DbEntity; * !!! 注意:CREATOR要进行@Ignore注解 * !!!并且需要Parcelable时需要手动填写rowID; */ -public class DownloadEntity extends DbEntity implements Parcelable, IEntity { - @Ignore private long speed = 0; //下载速度 - @Ignore private String convertSpeed = "0b/s"; - @Ignore private int failNum = 0; +public class DownloadEntity extends AbsEntity implements Parcelable { private String downloadUrl = ""; //下载路径 private String downloadPath = ""; //保存路径 - private String fileName = ""; //文件名 - private String str = ""; //其它字段 - private long fileSize = 1; - private int state = STATE_WAIT; private boolean isDownloadComplete = false; //是否下载完成 - private long currentProgress = 0; //当前下载进度 - private long completeTime; //完成时间 - private boolean isRedirect = false; + private boolean isRedirect = false; //是否重定向 private String redirectUrl = ""; //重定向链接 public DownloadEntity() { } - public String getStr() { - return str; - } - - public void setStr(String str) { - this.str = str; - } - - public String getFileName() { - return fileName; - } - - public DownloadEntity setFileName(String fileName) { - this.fileName = fileName; - return this; - } - - public int getFailNum() { - return failNum; - } - - @Override - public void setFailNum(int failNum) { - this.failNum = failNum; - } public String getDownloadUrl() { return downloadUrl; @@ -83,14 +47,6 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity { return this; } - public long getCompleteTime() { - return completeTime; - } - - public void setCompleteTime(long completeTime) { - this.completeTime = completeTime; - } - public String getDownloadPath() { return downloadPath; } @@ -100,22 +56,6 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity { return this; } - public long getFileSize() { - return fileSize; - } - - public void setFileSize(long fileSize) { - this.fileSize = fileSize; - } - - @Override public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - public boolean isDownloadComplete() { return isDownloadComplete; } @@ -124,30 +64,6 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity { isDownloadComplete = downloadComplete; } - public String getConvertSpeed() { - return convertSpeed; - } - - public void setConvertSpeed(String convertSpeed) { - this.convertSpeed = convertSpeed; - } - - public long getSpeed() { - return speed; - } - - public void setSpeed(long speed) { - this.speed = speed; - } - - public long getCurrentProgress() { - return currentProgress; - } - - public void setCurrentProgress(long currentProgress) { - this.currentProgress = currentProgress; - } - @Override public DownloadEntity clone() throws CloneNotSupportedException { return (DownloadEntity) super.clone(); } @@ -168,79 +84,24 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity { this.redirectUrl = redirectUrl; } - @Override public String toString() { - return "DownloadEntity{" - + "speed=" - + speed - + ", convertSpeed='" - + convertSpeed - + '\'' - + ", failNum=" - + failNum - + ", downloadUrl='" - + downloadUrl - + '\'' - + ", downloadPath='" - + downloadPath - + '\'' - + ", fileName='" - + fileName - + '\'' - + ", str='" - + str - + '\'' - + ", fileSize=" - + fileSize - + ", state=" - + state - + ", isDownloadComplete=" - + isDownloadComplete - + ", currentProgress=" - + currentProgress - + ", completeTime=" - + completeTime - + ", isRedirect=" - + isRedirect - + ", redirectUrl='" - + redirectUrl - + '\'' - + '}'; - } - @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(this.speed); - dest.writeString(this.convertSpeed); - dest.writeInt(this.failNum); + super.writeToParcel(dest, flags); dest.writeString(this.downloadUrl); dest.writeString(this.downloadPath); - dest.writeString(this.fileName); - dest.writeString(this.str); - dest.writeLong(this.fileSize); - dest.writeInt(this.state); dest.writeByte(this.isDownloadComplete ? (byte) 1 : (byte) 0); - dest.writeLong(this.currentProgress); - dest.writeLong(this.completeTime); dest.writeByte(this.isRedirect ? (byte) 1 : (byte) 0); dest.writeString(this.redirectUrl); } protected DownloadEntity(Parcel in) { - this.speed = in.readLong(); - this.convertSpeed = in.readString(); - this.failNum = in.readInt(); + super(in); this.downloadUrl = in.readString(); this.downloadPath = in.readString(); - this.fileName = in.readString(); - this.str = in.readString(); - this.fileSize = in.readLong(); - this.state = in.readInt(); this.isDownloadComplete = in.readByte() != 0; - this.currentProgress = in.readLong(); - this.completeTime = in.readLong(); this.isRedirect = in.readByte() != 0; this.redirectUrl = in.readString(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 99ea4c93..998902d4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -22,7 +22,7 @@ import android.os.Handler; import android.util.Log; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.inf.ITask; +import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CheckUtil; @@ -33,18 +33,12 @@ import java.lang.ref.WeakReference; * Created by lyy on 2016/8/11. * 下载任务类 */ -public class DownloadTask implements ITask { +public class DownloadTask extends AbsTask { public static final String TAG = "DownloadTask"; - /** - * 产生该任务对象的hash码 - */ - private String mTargetName; - private DownloadEntity mEntity; + private IDownloadListener mListener; private Handler mOutHandler; private IDownloadUtil mUtil; - private Context mContext; - private boolean isHeighestTask = false; private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { mEntity = taskEntity.downloadEntity; @@ -54,98 +48,6 @@ public class DownloadTask implements ITask { mUtil = new DownloadUtil(mContext, taskEntity, mListener); } - /** - * @return 返回原始byte速度,需要你在配置文件中配置 - *
-   *   {@code
-   *    
-   *      
-   *        ...
-   *        
-   *      
-   *
-   *      或在代码中设置
-   *      Aria.get(this).getDownloadConfig().setConvertSpeed(false);
-   *    
-   *   }
-   * 
- * 才能生效 - */ - @Override public long getSpeed() { - return mEntity.getSpeed(); - } - - /** - * @return 返回转换单位后的速度,需要你在配置文件中配置,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s - *
-   *   {@code
-   *    
-   *      
-   *        ...
-   *        
-   *      
-   *
-   *      或在代码中设置
-   *      Aria.get(this).getDownloadConfig().setConvertSpeed(true);
-   *    
-   *   }
-   * 
- * 才能生效 - */ - @Override public String getConvertSpeed() { - return mEntity.getConvertSpeed(); - } - - /** - * 获取百分比进度 - * - * @return 返回百分比进度,如果文件长度为0,返回0 - */ - @Override public int getPercent() { - if (mEntity.getFileSize() == 0) { - return 0; - } - return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()); - } - - /** - * 获取文件大小 - */ - @Override public long getFileSize() { - return mEntity.getFileSize(); - } - - /** - * 转换单位后的文件长度 - * - * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb - */ - @Override public String getConvertFileSize() { - if (mEntity.getFileSize() == 0) { - return "0mb"; - } - return CommonUtil.formatFileSize(mEntity.getFileSize()); - } - - /** - * 获取当前下载进度 - */ - @Override public long getCurrentProgress() { - return mEntity.getCurrentProgress(); - } - - /** - * 获取单位转换后的进度 - * - * @return 如:已经下载3mb的大小,则返回{@code 3mb} - */ - @Override public String getConvertCurrentProgress() { - if (mEntity.getCurrentProgress() == 0) { - return "0b"; - } - return CommonUtil.formatFileSize(mEntity.getCurrentProgress()); - } - /** * 获取当前下载任务的下载地址 * @@ -155,14 +57,6 @@ public class DownloadTask implements ITask { return mEntity.getDownloadUrl(); } - @Override public void setHighestPriority(boolean isHighestPriority) { - isHeighestTask = isHighestPriority; - } - - @Override public boolean isHighestPriorityTask() { - return isHeighestTask; - } - @Override public String getKey() { return getDownloadUrl(); } @@ -180,10 +74,11 @@ public class DownloadTask implements ITask { return isDownloading(); } - @Override public DownloadEntity getEntity() { + public DownloadEntity getDownloadEntity() { return mEntity; } + /** * 开始下载 */ @@ -198,22 +93,6 @@ public class DownloadTask implements ITask { } } - public DownloadEntity getDownloadEntity() { - return mEntity; - } - - public String getTargetName() { - return mTargetName; - } - - @Override public void setTargetName(String targetName) { - this.mTargetName = targetName; - } - - @Override public void removeRecord() { - mEntity.deleteData(); - } - /** * 停止下载 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java index 817e134e..9a9fd416 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java @@ -15,14 +15,13 @@ */ package com.arialyy.aria.core.download; -import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2017/1/23. * 下载任务实体 */ -public class DownloadTaskEntity extends ITaskEntity { +public class DownloadTaskEntity extends AbsTaskEntity { public DownloadEntity downloadEntity; @@ -30,7 +29,7 @@ public class DownloadTaskEntity extends ITaskEntity { this.downloadEntity = downloadEntity; } - @Override public IEntity getEntity() { + @Override public DownloadEntity getEntity() { return downloadEntity; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java index 8ebc028f..e6b4d2b9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -15,11 +15,149 @@ */ package com.arialyy.aria.core.inf; +import android.os.Parcel; +import android.os.Parcelable; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.orm.Ignore; /** * Created by AriaL on 2017/6/3. */ -public abstract class AbsEntity extends DbEntity implements IEntity { +public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable { + /** + * 速度 + */ + @Ignore private long speed = 0; + /** + * 单位转换后的速度 + */ + @Ignore private String convertSpeed = "0b/s"; + /** + * 下载失败计数,每次开始都重置为0 + */ + @Ignore private int failNum = 0; + /** + * 扩展字段 + */ + private String str = ""; + /** + * 文件大小 + */ + private long fileSize = 1; + private int state = STATE_WAIT; + /** + * 当前下载进度 + */ + private long currentProgress = 0; + /** + * 完成时间 + */ + private long completeTime; + /** + * 文件名 + */ + private String fileName = ""; + public long getSpeed() { + return speed; + } + + public void setSpeed(long speed) { + this.speed = speed; + } + + public String getConvertSpeed() { + return convertSpeed; + } + + public void setConvertSpeed(String convertSpeed) { + this.convertSpeed = convertSpeed; + } + + public int getFailNum() { + return failNum; + } + + public void setFailNum(int failNum) { + this.failNum = failNum; + } + + public String getStr() { + return str; + } + + public void setStr(String str) { + this.str = str; + } + + public long getFileSize() { + return fileSize; + } + + public void setFileSize(long fileSize) { + this.fileSize = fileSize; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public long getCurrentProgress() { + return currentProgress; + } + + public void setCurrentProgress(long currentProgress) { + this.currentProgress = currentProgress; + } + + public long getCompleteTime() { + return completeTime; + } + + public void setCompleteTime(long completeTime) { + this.completeTime = completeTime; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public AbsEntity() { + } + + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeLong(this.speed); + dest.writeString(this.convertSpeed); + dest.writeInt(this.failNum); + dest.writeString(this.str); + dest.writeLong(this.fileSize); + dest.writeInt(this.state); + dest.writeLong(this.currentProgress); + dest.writeLong(this.completeTime); + dest.writeString(this.fileName); + } + + protected AbsEntity(Parcel in) { + this.speed = in.readLong(); + this.convertSpeed = in.readString(); + this.failNum = in.readInt(); + this.str = in.readString(); + this.fileSize = in.readLong(); + this.state = in.readInt(); + this.currentProgress = in.readLong(); + this.completeTime = in.readLong(); + this.fileName = in.readString(); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 6ef8e687..779a178c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -33,7 +33,7 @@ import java.util.Set; /** * Created by lyy on 2017/2/28. */ -public abstract class AbsTarget { +public abstract class AbsTarget { protected ENTITY entity; protected TASK_ENTITY taskEntity; protected String targetName; diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index 38e795ae..8f6695bf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -1,9 +1,163 @@ +/* + * 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.inf; +import android.content.Context; +import com.arialyy.aria.util.CommonUtil; + /** * Created by lyy on 2017/6/3. */ -public abstract class AbsTask implements ITask{ +public abstract class AbsTask + implements ITask { + + protected ENTITY mEntity; + + /** + * 用于生成该任务对象的hash码 + */ + private String mTargetName; + protected Context mContext; + private boolean isHeighestTask = false; + + /** + * @return 返回原始byte速度,需要你在配置文件中配置 + *
+   *   {@code
+   *    
+   *      
+   *        ...
+   *        
+   *      
+   *
+   *      或在代码中设置
+   *      Aria.get(this).getDownloadConfig().setConvertSpeed(false);
+   *    
+   *   }
+   * 
+ * 才能生效 + */ + @Override public long getSpeed() { + return mEntity.getSpeed(); + } + + /** + * @return 返回转换单位后的速度,需要你在配置文件中配置,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s + *
+   *   {@code
+   *    
+   *      
+   *        ...
+   *        
+   *      
+   *
+   *      或在代码中设置
+   *      Aria.get(this).getDownloadConfig().setConvertSpeed(true);
+   *    
+   *   }
+   * 
+ * 才能生效 + */ + @Override public String getConvertSpeed() { + return mEntity.getConvertSpeed(); + } + + /** + * 最高优先级命令,最高优先级命令有以下属性 + * 1、在下载队列中,有且只有一个最高优先级任务 + * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 + * 3、任务调度器不会暂停最高优先级任务 + * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 + * 5、如果下载队列中已经满了,则会停止队尾的任务 + * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 + */ + @Override public void setHighestPriority(boolean isHighestPriority) { + isHeighestTask = isHighestPriority; + } + + @Override public boolean isHighestPriorityTask() { + return isHeighestTask; + } + + /** + * 获取百分比进度 + * + * @return 返回百分比进度,如果文件长度为0,返回0 + */ + @Override public int getPercent() { + if (mEntity.getFileSize() == 0) { + return 0; + } + return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()); + } + + /** + * 获取文件大小 + */ + @Override public long getFileSize() { + return mEntity.getFileSize(); + } + + /** + * 转换单位后的文件长度 + * + * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb + */ + @Override public String getConvertFileSize() { + if (mEntity.getFileSize() == 0) { + return "0mb"; + } + return CommonUtil.formatFileSize(mEntity.getFileSize()); + } + + /** + * 获取当前下载进度 + */ + @Override public long getCurrentProgress() { + return mEntity.getCurrentProgress(); + } + + /** + * 获取单位转换后的进度 + * + * @return 如:已经下载3mb的大小,则返回{@code 3mb} + */ + @Override public String getConvertCurrentProgress() { + if (mEntity.getCurrentProgress() == 0) { + return "0b"; + } + return CommonUtil.formatFileSize(mEntity.getCurrentProgress()); + } + + @Override public ENTITY getEntity() { + return mEntity; + } + + /** + * 删除任务记录,删除后,再次启动该任务的下载时,将重新下载 + */ + @Override public void removeRecord() { + mEntity.deleteData(); + } + public String getTargetName() { + return mTargetName; + } + @Override public void setTargetName(String targetName) { + this.mTargetName = targetName; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java similarity index 93% rename from Aria/src/main/java/com/arialyy/aria/core/inf/ITaskEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java index 828cd989..eefa1f3a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java @@ -23,7 +23,7 @@ import java.util.Map; * Created by lyy on 2017/2/23. */ -public abstract class ITaskEntity { +public abstract class AbsTaskEntity { /** * http 请求头 */ @@ -39,5 +39,5 @@ public abstract class ITaskEntity { */ public String redirectUrlKey = "location"; - public abstract IEntity getEntity(); + public abstract AbsEntity getEntity(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java index d405f442..6b60f1bb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java @@ -58,8 +58,4 @@ public interface IEntity { * 取消下载 */ @Ignore public static final int STATE_CANCEL = 7; - - public int getState(); - - public void setFailNum(int failNum); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index c988f655..8d1aeca8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -19,7 +19,7 @@ package com.arialyy.aria.core.inf; * Created by lyy on 2017/2/13. */ -public interface ITask { +public interface ITask { /** * 设置任务为最高优先级任务,在下载队列中,有且只有一个最高优先级任务 @@ -48,7 +48,7 @@ public interface ITask { /** * 获取工具实体 */ - public IEntity getEntity(); + public ENTITY getEntity(); public void start(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index d17b5509..a979739a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -17,9 +17,9 @@ package com.arialyy.aria.core.queue; import android.util.Log; -import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.queue.pool.CachePool; import com.arialyy.aria.core.queue.pool.ExecutePool; @@ -27,7 +27,7 @@ import com.arialyy.aria.core.queue.pool.ExecutePool; * Created by lyy on 2017/2/23. * 任务队列 */ -abstract class AbsTaskQueue +abstract class AbsTaskQueue implements ITaskQueue { private final String TAG = "AbsTaskQueue"; CachePool mCachePool = new CachePool<>(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index fed5dc13..e51daeb5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -88,14 +88,6 @@ public class DownloadTaskQueue for (DownloadTask temp : tempTasks){ mExecutePool.putTask(temp); } - - //int i = 0, len = tempTasks.size() - 1; - //for (DownloadTask oldTask : tempTasks) { - // if (i < len) { - // startTask(oldTask); - // } - // i++; - //} } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index fcdcac43..cb2ce357 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -21,7 +21,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTaskEntity; @@ -30,7 +30,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity; * Created by lyy on 2016/8/16. * 任务功能接口 */ -public interface ITaskQueue { +public interface ITaskQueue { /** * 设置任务为最高优先级任务 diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java b/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java index 34b6f043..acd44dd5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java @@ -19,7 +19,7 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.ITask; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.upload.UploadTask; @@ -57,7 +57,7 @@ public class TaskFactory { * @param {@link DownloadSchedulers} * @return {@link DownloadTask}、{@link UploadTask} */ - ITask createTask(String targetName, + ITask createTask(String targetName, ENTITY entity, SCHEDULER schedulers) { if (entity instanceof DownloadTaskEntity) { return createDownloadTask(targetName, (DownloadTaskEntity) entity, schedulers); diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java index 1c6821c4..d2077881 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java @@ -78,7 +78,7 @@ public class UploadSchedulers implements ISchedulers { } @Override public void onFinish() { - UploadEntity entity = task.getUploadEntity(); + UploadEntity entity = task.getEntity(); if (entity.getFailNum() <= reTryNum) { UploadTask task = mQueue.getTask(entity); mQueue.reTryStart(task); @@ -102,7 +102,7 @@ public class UploadSchedulers implements ISchedulers { Log.w(TAG, "没有下一任务"); return; } - if (newTask.getUploadEntity().getState() == IEntity.STATE_WAIT) { + if (newTask.getEntity().getState() == IEntity.STATE_WAIT) { mQueue.startTask(newTask); } } @@ -169,7 +169,7 @@ public class UploadSchedulers implements ISchedulers { return true; } callback(msg.what, task); - UploadEntity entity = task.getUploadEntity(); + UploadEntity entity = task.getEntity(); switch (msg.what) { case STOP: case CANCEL: diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java index d8de9a98..dafc69d9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java @@ -17,33 +17,17 @@ package com.arialyy.aria.core.upload; import android.os.Parcel; import android.os.Parcelable; -import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.orm.Ignore; /** * Created by lyy on 2017/2/9. * 上传文件实体 */ -public class UploadEntity extends DbEntity implements IEntity, Parcelable { +public class UploadEntity extends AbsEntity implements Parcelable { private String filePath; //文件路径 - private String fileName; //文件名 - private long fileSize; //文件大小 - private int state = STATE_WAIT; - private long currentProgress = 0; private boolean isComplete = false; - @Ignore private long speed = 0; //下载速度 - @Ignore private String convertSpeed = "0/s"; - @Ignore private int failNum = 0; - - public String getConvertSpeed() { - return convertSpeed; - } - - public void setConvertSpeed(String convertSpeed) { - this.convertSpeed = convertSpeed; - } public boolean isComplete() { return isComplete; @@ -53,46 +37,6 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable { isComplete = complete; } - public long getCurrentProgress() { - return currentProgress; - } - - public void setCurrentProgress(long currentProgress) { - this.currentProgress = currentProgress; - } - - public long getFileSize() { - return fileSize; - } - - public void setFileSize(long fileSize) { - this.fileSize = fileSize; - } - - public long getSpeed() { - return speed; - } - - public void setSpeed(long speed) { - this.speed = speed; - } - - public int getFailNum() { - return failNum; - } - - @Override public void setFailNum(int failNum) { - this.failNum = failNum; - } - - @Override public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - public String getFilePath() { return filePath; } @@ -101,14 +45,6 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable { this.filePath = filePath; } - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - public UploadEntity() { } @@ -117,27 +53,15 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable { } @Override public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); dest.writeString(this.filePath); - dest.writeString(this.fileName); - dest.writeLong(this.fileSize); - dest.writeInt(this.state); - dest.writeLong(this.currentProgress); dest.writeByte(this.isComplete ? (byte) 1 : (byte) 0); - dest.writeLong(this.speed); - dest.writeString(this.convertSpeed); - dest.writeInt(this.failNum); } protected UploadEntity(Parcel in) { + super(in); this.filePath = in.readString(); - this.fileName = in.readString(); - this.fileSize = in.readLong(); - this.state = in.readInt(); - this.currentProgress = in.readLong(); this.isComplete = in.readByte() != 0; - this.speed = in.readLong(); - this.convertSpeed = in.readString(); - this.failNum = in.readInt(); } @Ignore public static final Creator CREATOR = new Creator() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index b81dc90d..ba799ca0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -22,8 +22,8 @@ import android.util.Log; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CommonUtil; @@ -33,55 +33,28 @@ import java.lang.ref.WeakReference; * Created by lyy on 2017/2/23. * 上传任务 */ -public class UploadTask implements ITask { +public class UploadTask extends AbsTask { private static final String TAG = "UploadTask"; private Handler mOutHandler; - private UploadEntity mUploadEntity; - private String mTargetName; private UploadUtil mUtil; private UListener mListener; - private boolean isHeighestTask = false; private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) { mOutHandler = outHandler; - mUploadEntity = taskEntity.uploadEntity; + mEntity = taskEntity.uploadEntity; mListener = new UListener(mOutHandler, this); mUtil = new UploadUtil(taskEntity, mListener); } - @Override public void setTargetName(String targetName) { - mTargetName = targetName; - } - - @Override public void removeRecord() { - mUploadEntity.deleteData(); - } - - @Override public void setHighestPriority(boolean isHighestPriority) { - isHeighestTask = isHighestPriority; - } - - @Override public boolean isHighestPriorityTask() { - return isHeighestTask; - } - @Override public String getKey() { - return mUploadEntity.getFilePath(); + return mEntity.getFilePath(); } @Override public boolean isRunning() { return mUtil.isRunning(); } - public UploadEntity getUploadEntity() { - return mUploadEntity; - } - - @Override public IEntity getEntity() { - return mUploadEntity; - } - @Override public void start() { if (mUtil.isRunning()) { Log.d(TAG, "任务正在下载"); @@ -99,111 +72,20 @@ public class UploadTask implements ITask { @Override public void cancel() { - if (!mUploadEntity.isComplete()) { + if (!mEntity.isComplete()) { // 如果任务不是下载状态 mUtil.cancel(); - mUploadEntity.deleteData(); + mEntity.deleteData(); if (mOutHandler != null) { mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget(); } //发送取消下载的广播 Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_CANCEL); - intent.putExtra(Aria.UPLOAD_ENTITY, mUploadEntity); + intent.putExtra(Aria.UPLOAD_ENTITY, mEntity); AriaManager.APP.sendBroadcast(intent); } } - public String getTargetName() { - return mTargetName; - } - - /** - * @return 返回原始byte速度,需要你在配置文件中配置 - *
-   *  {@code
-   *   
-   *    
-   *      ...
-   *      
-   *    
-   *
-   *    或在代码中设置
-   *    Aria.get(this).getUploadConfig().setConvertSpeed(false);
-   *   
-   *  }
-   * 
- * 才能生效 - */ - @Override public long getSpeed() { - return mUploadEntity.getSpeed(); - } - - /** - * @return 返回转换单位后的速度,需要你在配置文件中配置,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s - *
-   *   {@code
-   *   
-   *    
-   *      ...
-   *      
-   *    
-   *
-   *    或在代码中设置
-   *    Aria.get(this).getUploadConfig().setConvertSpeed(true);
-   *   
-   *   }
-   * 
- * - * 才能生效 - */ - @Override public String getConvertSpeed() { - return mUploadEntity.getConvertSpeed(); - } - - /** - * 获取百分比进度 - * - * @return 返回百分比进度,如果文件长度为0,返回0 - */ - @Override public int getPercent() { - if (mUploadEntity.getFileSize() == 0) { - return 0; - } - return (int) (mUploadEntity.getCurrentProgress() * 100 / mUploadEntity.getFileSize()); - } - - /** - * 转换单位后的文件长度 - * - * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb - */ - @Override public String getConvertFileSize() { - if (mUploadEntity.getFileSize() == 0) { - return "0m"; - } - return CommonUtil.formatFileSize(mUploadEntity.getFileSize()); - } - - @Override public long getFileSize() { - return mUploadEntity.getFileSize(); - } - - @Override public long getCurrentProgress() { - return mUploadEntity.getCurrentProgress(); - } - - /** - * 获取单位转换后的进度 - * - * @return 如:已经下载3mb的大小,则返回{@code 3mb} - */ - @Override public String getConvertCurrentProgress() { - if (mUploadEntity.getCurrentProgress() == 0) { - return "0b"; - } - return CommonUtil.formatFileSize(mUploadEntity.getCurrentProgress()); - } - private static class UListener extends UploadListener { WeakReference outHandler; WeakReference task; @@ -220,7 +102,7 @@ public class UploadTask implements ITask { UListener(Handler outHandle, UploadTask task) { this.outHandler = new WeakReference<>(outHandle); this.task = new WeakReference<>(task); - uploadEntity = this.task.get().getUploadEntity(); + uploadEntity = this.task.get().getEntity(); sendIntent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_RUNNING); sendIntent.putExtra(Aria.UPLOAD_ENTITY, uploadEntity); context = AriaManager.APP; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java index 55e89685..5da1923e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java @@ -15,8 +15,7 @@ */ package com.arialyy.aria.core.upload; -import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import java.util.HashMap; import java.util.Map; @@ -24,7 +23,7 @@ import java.util.Map; * Created by lyy on 2017/2/9. * 上传任务实体 */ -public class UploadTaskEntity extends ITaskEntity { +public class UploadTaskEntity extends AbsTaskEntity { public UploadEntity uploadEntity; public String uploadUrl; //上传路径 public String attachment; //文件上传需要的key @@ -41,7 +40,7 @@ public class UploadTaskEntity extends ITaskEntity { this.uploadEntity = downloadEntity; } - @Override public IEntity getEntity() { + @Override public UploadEntity getEntity() { return uploadEntity; } } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index 5cee79b2..faf40925 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -28,7 +28,7 @@ import java.util.Map; public class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 2; + static int VERSION = 3; static { if (TextUtils.isEmpty(DB_NAME)) { 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 41bb990d..f3f82bde 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -140,8 +140,8 @@ final class SqlHelper extends SQLiteOpenHelper { */ private int getEntityAttr(Class clazz) { int count = 1; - Field[] fields = CommonUtil.getFields(clazz); - if (fields != null && fields.length > 0) { + List fields = CommonUtil.getAllFields(clazz); + if (fields != null && fields.size() > 0) { for (Field field : fields) { field.setAccessible(true); if (ignoreField(field)) { @@ -258,8 +258,8 @@ final class SqlHelper extends SQLiteOpenHelper { static synchronized void modifyData(SQLiteDatabase db, DbEntity dbEntity) { db = checkDb(db); Class clazz = dbEntity.getClass(); - Field[] fields = CommonUtil.getFields(clazz); - if (fields != null && fields.length > 0) { + List fields = CommonUtil.getAllFields(clazz); + if (fields != null && fields.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); int i = 0; @@ -293,8 +293,8 @@ final class SqlHelper extends SQLiteOpenHelper { static synchronized void insertData(SQLiteDatabase db, DbEntity dbEntity) { db = checkDb(db); Class clazz = dbEntity.getClass(); - Field[] fields = CommonUtil.getFields(clazz); - if (fields != null && fields.length > 0) { + List fields = CommonUtil.getAllFields(clazz); + if (fields != null && fields.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO ").append(CommonUtil.getClassName(dbEntity)).append("("); int i = 0; @@ -369,9 +369,7 @@ final class SqlHelper extends SQLiteOpenHelper { */ static synchronized void createTable(SQLiteDatabase db, Class clazz, String tableName) { db = checkDb(db); - //Field[] fields = CommonUtil.getFields(clazz); List fields = CommonUtil.getAllFields(clazz); - //Field[] fields = CommonUtil.getAllFields(clazz); if (fields != null && fields.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("create table ") @@ -451,9 +449,9 @@ final class SqlHelper extends SQLiteOpenHelper { */ static synchronized List newInstanceEntity(Class clazz, Cursor cursor) { - Field[] fields = CommonUtil.getFields(clazz); + List fields = CommonUtil.getAllFields(clazz); List entitys = new ArrayList<>(); - if (fields != null && fields.length > 0) { + if (fields != null && fields.size() > 0) { try { while (cursor.moveToNext()) { T entity = clazz.newInstance(); diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index eb008022..c083c46e 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -20,7 +20,7 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.exception.FileException; @@ -86,7 +86,7 @@ public class CheckUtil { /** * 检查任务实体 */ - public static void checkTaskEntity(ITaskEntity entity) { + public static void checkTaskEntity(AbsTaskEntity entity) { if (entity instanceof DownloadTaskEntity) { checkDownloadTaskEntity(((DownloadTaskEntity) entity).downloadEntity); } else if (entity instanceof UploadTaskEntity) { @@ -100,7 +100,7 @@ public class CheckUtil { * @param checkType 删除命令和停止命令不需要检查下载链接和保存路径 * @return {@code false}实体无效 */ - public static boolean checkCmdEntity(ITaskEntity entity, boolean checkType) { + public static boolean checkCmdEntity(AbsTaskEntity entity, boolean checkType) { boolean b = false; if (entity instanceof DownloadTaskEntity) { DownloadEntity entity1 = ((DownloadTaskEntity) entity).downloadEntity; diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 51ea0293..290930ad 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -24,7 +24,7 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.AbsCmd; -import com.arialyy.aria.core.inf.ITaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -149,7 +149,7 @@ public class CommonUtil { } } - public static AbsCmd createCmd(String target, T entity, int cmd) { + public static AbsCmd createCmd(String target, T entity, int cmd) { return CmdFactory.getInstance().createCmd(target, entity, cmd); } @@ -206,7 +206,7 @@ public class CommonUtil { } /** - * 获取类里面的所在字段 + * 获取当前类里面的所在字段 */ public static Field[] getFields(Class clazz) { Field[] fields = null;