Merge branch 'v_3.0'

pull/330/head
AriaLyy 7 years ago
commit d584d07488
  1. 35
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  3. 41
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  4. 6
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java
  6. 12
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  7. 24
      Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  9. 18
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  10. 20
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
  11. 82
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  12. 23
      Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java
  13. 3
      DEV_LOG.md
  14. 12
      README.md
  15. 6
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  16. 12
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  17. 7
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  18. 4
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  19. 5
      app/src/main/res/values/strings.xml
  20. 2
      build.gradle

@ -32,6 +32,8 @@ import java.math.BigDecimal;
import java.util.Properties; import java.util.Properties;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* Created by lyy on 2017/1/18. * Created by lyy on 2017/1/18.
@ -60,6 +62,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
private String mTaskType; private String mTaskType;
private Timer mFailTimer; private Timer mFailTimer;
private long mLastSaveTime; private long mLastSaveTime;
private ExecutorService mConfigThreadPool;
private Thread mConfigThread = new Thread(new Runnable() {
@Override public void run() {
final long currentTemp = mChildCurrentLocation;
try {
writeConfig(false, currentTemp);
} catch (IOException e) {
e.printStackTrace();
}
}
});
protected AbsThreadTask(StateConstance constance, IEventListener listener, protected AbsThreadTask(StateConstance constance, IEventListener listener,
SubThreadConfig<TASK_ENTITY> info) { SubThreadConfig<TASK_ENTITY> info) {
@ -76,6 +89,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed()); setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
mTaskType = getTaskType(); mTaskType = getTaskType();
mLastSaveTime = System.currentTimeMillis(); mLastSaveTime = System.currentTimeMillis();
mConfigThreadPool = Executors.newCachedThreadPool();
} }
protected abstract String getTaskType(); protected abstract String getTaskType();
@ -94,6 +108,13 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
} }
@Override protected void finalize() throws Throwable {
super.finalize();
if (mConfigThreadPool != null) {
mConfigThreadPool.shutdown();
}
}
/** /**
* 停止任务 * 停止任务
*/ */
@ -134,20 +155,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
mChildCurrentLocation += len; mChildCurrentLocation += len;
STATE.CURRENT_LOCATION += len; STATE.CURRENT_LOCATION += len;
//mIncrement += len;
if (System.currentTimeMillis() - mLastSaveTime > 5000 if (System.currentTimeMillis() - mLastSaveTime > 5000
&& mChildCurrentLocation < mConfig.END_LOCATION) { && mChildCurrentLocation < mConfig.END_LOCATION) {
mLastSaveTime = System.currentTimeMillis(); mLastSaveTime = System.currentTimeMillis();
new Thread(new Runnable() { if (!mConfigThreadPool.isShutdown()) {
@Override public void run() { mConfigThreadPool.execute(mConfigThread);
final long currentTemp = mChildCurrentLocation; }
try {
writeConfig(false, currentTemp);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} }
} }
} }

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -36,8 +37,7 @@ public class DownloadGroupTarget
this.mUrls.addAll(groupEntity.getUrls()); this.mUrls.addAll(groupEntity.getUrls());
} }
mGroupName = CommonUtil.getMd5Code(groupEntity.getUrls()); mGroupName = CommonUtil.getMd5Code(groupEntity.getUrls());
mTaskEntity = TEManager.getInstance() mTaskEntity = TEManager.getInstance().getTEntity(DownloadGroupTaskEntity.class, mGroupName);
.getTEntity(DownloadGroupTaskEntity.class, mGroupName);
if (mTaskEntity == null) { if (mTaskEntity == null) {
mTaskEntity = mTaskEntity =
TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity); TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity);

@ -24,6 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener;
@ -65,8 +66,18 @@ public class DownloadReceiver extends AbsReceiver {
* 使用下载实体执行下载操作 * 使用下载实体执行下载操作
* *
* @param refreshInfo 是否刷新下载信息 * @param refreshInfo 是否刷新下载信息
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/ */
public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) { @Deprecated public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity); CheckUtil.checkDownloadEntity(entity);
return new DownloadTarget(entity, targetName, refreshInfo); return new DownloadTarget(entity, targetName, refreshInfo);
} }
@ -84,9 +95,19 @@ public class DownloadReceiver extends AbsReceiver {
* 加载Httphttps单任务下载地址 * 加载Httphttps单任务下载地址
* *
* @param url 下载地址 * @param url 下载地址
* @param refreshInfo 是否刷新下载信息 * @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/ */
public DownloadTarget load(@NonNull String url, boolean refreshInfo) { @Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrl(url); CheckUtil.checkUrl(url);
return new DownloadTarget(url, targetName, refreshInfo); return new DownloadTarget(url, targetName, refreshInfo);
} }
@ -111,9 +132,19 @@ public class DownloadReceiver extends AbsReceiver {
/** /**
* 使用下载实体执行下载操作 * 使用下载实体执行下载操作
* *
* @param refreshInfo 是否刷新下载信息 * @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/ */
public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) { @Deprecated public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity); CheckUtil.checkDownloadEntity(entity);
if (!entity.getUrl().startsWith("ftp")) { if (!entity.getUrl().startsWith("ftp")) {
throw new IllegalArgumentException("非FTP请求不能使用该方法"); throw new IllegalArgumentException("非FTP请求不能使用该方法");

@ -21,6 +21,7 @@ import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -63,6 +64,11 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
@Override protected void onStart() { @Override protected void onStart() {
super.onStart(); super.onStart();
if (mExeMap.size() == 0){
ALog.e(TAG, "任务组无可执行任务");
mListener.onFail(false);
return;
}
Set<String> keys = mExeMap.keySet(); Set<String> keys = mExeMap.keySet();
int i = 0; int i = 0;
for (String key : keys) { for (String key : keys) {

@ -27,7 +27,7 @@ public abstract class AbsGroupTask<TASK_ENTITY extends AbsGroupTaskEntity>
protected AbsGroupUtil mUtil; protected AbsGroupUtil mUtil;
@Override public String getKey() { @Override public String getKey() {
return mTaskEntity.getEntity().getGroupName(); return mTaskEntity.getEntity().getKey();
} }
/** /**

@ -24,6 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -41,6 +42,16 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
protected TASK_ENTITY mTaskEntity; protected TASK_ENTITY mTaskEntity;
protected String mTargetName; protected String mTargetName;
/**
* 重置下载状态将任务状态设置为未开始状态
*/
public TARGET resetState() {
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
mTaskEntity.refreshInfo = true;
mTaskEntity.update();
return (TARGET) this;
}
/** /**
* 删除记录如果任务正在执行则会删除正在下载的任务 * 删除记录如果任务正在执行则会删除正在下载的任务
*/ */
@ -50,6 +61,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
cancel(); cancel();
} else { } else {
mTaskEntity.deleteData(); mTaskEntity.deleteData();
TEManager.getInstance().removeTEntity(mEntity.getKey());
} }
} }

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.core.manager; package com.arialyy.aria.core.manager;
import android.support.v4.util.LruCache;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
@ -23,8 +24,6 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -35,7 +34,7 @@ import java.util.concurrent.locks.ReentrantLock;
public class TEManager { public class TEManager {
private static final String TAG = "TaskManager"; private static final String TAG = "TaskManager";
private static volatile TEManager INSTANCE = null; private static volatile TEManager INSTANCE = null;
private Map<String, AbsTaskEntity> map = new ConcurrentHashMap<>(); private LruCache<String, AbsTaskEntity> cache = new LruCache<>(1024);
private Lock lock; private Lock lock;
public static TEManager getInstance() { public static TEManager getInstance() {
@ -61,7 +60,7 @@ public class TEManager {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
AbsTaskEntity tEntity = map.get(convertKey(key)); AbsTaskEntity tEntity = cache.get(convertKey(key));
if (tEntity == null || tEntity.getClass() != clazz) { if (tEntity == null || tEntity.getClass() != clazz) {
ITEntityFactory factory = chooseFactory(clazz); ITEntityFactory factory = chooseFactory(clazz);
if (factory == null) { if (factory == null) {
@ -69,7 +68,7 @@ public class TEManager {
return null; return null;
} }
tEntity = factory.create(key); tEntity = factory.create(key);
map.put(convertKey(key), tEntity); cache.put(convertKey(key), tEntity);
} }
return (TE) tEntity; return (TE) tEntity;
} finally { } finally {
@ -87,7 +86,7 @@ public class TEManager {
lock.lock(); lock.lock();
try { try {
String groupName = CommonUtil.getMd5Code(urls); String groupName = CommonUtil.getMd5Code(urls);
AbsTaskEntity tEntity = map.get(convertKey(groupName)); AbsTaskEntity tEntity = cache.get(convertKey(groupName));
if (tEntity == null || tEntity.getClass() != clazz) { if (tEntity == null || tEntity.getClass() != clazz) {
IGTEntityFactory factory = chooseGroupFactory(clazz); IGTEntityFactory factory = chooseGroupFactory(clazz);
if (factory == null) { if (factory == null) {
@ -95,7 +94,7 @@ public class TEManager {
return null; return null;
} }
tEntity = factory.create(groupName, urls); tEntity = factory.create(groupName, urls);
map.put(convertKey(groupName), tEntity); cache.put(convertKey(groupName), tEntity);
} }
return (TE) tEntity; return (TE) tEntity;
} finally { } finally {
@ -112,7 +111,7 @@ public class TEManager {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
AbsTaskEntity tEntity = map.get(convertKey(absEntity.getKey())); AbsTaskEntity tEntity = cache.get(convertKey(absEntity.getKey()));
if (tEntity == null || tEntity.getClass() != clazz) { if (tEntity == null || tEntity.getClass() != clazz) {
ITEntityFactory factory = chooseFactory(clazz); ITEntityFactory factory = chooseFactory(clazz);
if (factory == null) { if (factory == null) {
@ -120,7 +119,7 @@ public class TEManager {
return null; return null;
} }
tEntity = factory.create(absEntity); tEntity = factory.create(absEntity);
map.put(convertKey(absEntity.getKey()), tEntity); cache.put(convertKey(absEntity.getKey()), tEntity);
} }
return (TE) tEntity; return (TE) tEntity;
} finally { } finally {
@ -153,7 +152,7 @@ public class TEManager {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
AbsTaskEntity tEntity = map.get(convertKey(key)); AbsTaskEntity tEntity = cache.get(convertKey(key));
if (tEntity == null) { if (tEntity == null) {
return null; return null;
} else { } else {
@ -177,7 +176,7 @@ public class TEManager {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
return map.put(convertKey(te.key), te) != null; return cache.put(convertKey(te.key), te) != null;
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@ -185,12 +184,13 @@ public class TEManager {
/** /**
* 通过key删除任务实体 * 通过key删除任务实体
* 当任务complete或删除记录时将删除缓存
*/ */
public AbsTaskEntity removeTEntity(String key) { public AbsTaskEntity removeTEntity(String key) {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
return map.remove(convertKey(key)); return cache.remove(convertKey(key));
} finally { } finally {
lock.unlock(); lock.unlock();
} }

@ -34,7 +34,7 @@ import java.util.Map;
class DBConfig { class DBConfig {
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 20; static int VERSION = 22;
static { static {
if (TextUtils.isEmpty(DB_NAME)) { if (TextUtils.isEmpty(DB_NAME)) {

@ -36,15 +36,15 @@ public class DbEntity {
} }
/** ///**
* 关键字模糊检索全文 // * 关键字模糊检索全文
* // *
* @param column 需要查找的列 // * @param column 需要查找的列
* @param mathSql 关键字语法exsimple white OR greenblue AND redwhite NOT green // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
*/ // */
public static <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) { //public static <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) {
return DbUtil.getInstance().searchData(clazz, column, mathSql); // return DbUtil.getInstance().searchData(clazz, column, mathSql);
} //}
/** /**
* 检查某个字段的值是否存在 * 检查某个字段的值是否存在

@ -64,16 +64,16 @@ public class DbUtil {
return INSTANCE; return INSTANCE;
} }
/** ///**
* 关键字模糊检索全文 // * 关键字模糊检索全文
* // *
* @param column 需要查找的列 // * @param column 需要查找的列
* @param mathSql 关键字语法exsimple white OR greenblue AND redwhite NOT green // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
*/ // */
public <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) { //public <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) {
checkDb(); // checkDb();
return SqlHelper.searchData(mDb, clazz, column, mathSql); // return SqlHelper.searchData(mDb, clazz, column, mathSql);
} //}
/** /**
* 检查某个字段的值是否存在 * 检查某个字段的值是否存在

@ -21,6 +21,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.util.LruCache;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -49,6 +50,7 @@ final class SqlHelper extends SQLiteOpenHelper {
private static final int DEL_DATA = 6; private static final int DEL_DATA = 6;
private static volatile SqlHelper INSTANCE = null; private static volatile SqlHelper INSTANCE = null;
private static LruCache<Integer, DbEntity> mDataCache = new LruCache<>(1024);
static SqlHelper init(Context context) { static SqlHelper init(Context context) {
if (INSTANCE == null) { if (INSTANCE == null) {
@ -162,27 +164,27 @@ final class SqlHelper extends SQLiteOpenHelper {
return count; return count;
} }
/** ///**
* 关键字模糊检索全文 // * 关键字模糊检索全文
* // *
* @param column 需要查找的列 // * @param column 需要查找的列
* @param mathSql 关键字语法exsimple white OR greenblue AND redwhite NOT green // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
*/ // */
public static <T extends DbEntity> List<T> searchData(SQLiteDatabase db, Class<T> clazz, //public static <T extends DbEntity> List<T> searchData(SQLiteDatabase db, Class<T> clazz,
String column, String mathSql) { // String column, String mathSql) {
String sql = "SELECT * FROM " // String sql = "SELECT * FROM "
+ CommonUtil.getClassName(clazz) // + CommonUtil.getClassName(clazz)
+ " WHERE " // + " WHERE "
+ column // + column
+ " MATCH '" // + " MATCH '"
+ mathSql // + mathSql
+ "'"; // + "'";
//
Cursor cursor = db.rawQuery(sql, null); // Cursor cursor = db.rawQuery(sql, null);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; // List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
closeCursor(cursor); // closeCursor(cursor);
return data; // return data;
} //}
/** /**
* 检查某个字段的值是否存在 * 检查某个字段的值是否存在
@ -328,19 +330,27 @@ final class SqlHelper extends SQLiteOpenHelper {
db = checkDb(db); db = checkDb(db);
Class<?> clazz = dbEntity.getClass(); Class<?> clazz = dbEntity.getClass();
List<Field> fields = CommonUtil.getAllFields(clazz); List<Field> fields = CommonUtil.getAllFields(clazz);
DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode());
if (fields != null && fields.size() > 0) { if (fields != null && fields.size() > 0) {
StringBuilder sb = new StringBuilder(); StringBuilder sql = new StringBuilder();
sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); StringBuilder prams = new StringBuilder();
sql.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET ");
int i = 0; int i = 0;
for (Field field : fields) { for (Field field : fields) {
field.setAccessible(true); field.setAccessible(true);
if (SqlUtil.ignoreField(field)) { if (SqlUtil.ignoreField(field)) {
continue; continue;
} }
sb.append(i > 0 ? ", " : "");
try { try {
if (cacheEntity != null && field.get(dbEntity) == field.get(cacheEntity)) {
continue;
}
//sb.append(i > 0 ? ", " : "");
//sb.append(field.getName()).append("='");
String value; String value;
sb.append(field.getName()).append("='"); prams.append(i > 0 ? ", " : "");
prams.append(field.getName()).append("='");
Type type = field.getType(); Type type = field.getType();
if (type == Map.class) { if (type == Map.class) {
value = SqlUtil.map2Str((Map<String, String>) field.get(dbEntity)); value = SqlUtil.map2Str((Map<String, String>) field.get(dbEntity));
@ -357,16 +367,21 @@ final class SqlHelper extends SQLiteOpenHelper {
value = obj == null ? "" : obj.toString(); value = obj == null ? "" : obj.toString();
} }
sb.append(value == null ? "" : value); //sb.append(value == null ? "" : value);
sb.append("'"); //sb.append("'");
prams.append(TextUtils.isEmpty(value) ? "" : value);
prams.append("'");
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
i++; i++;
} }
sb.append(" where rowid=").append(dbEntity.rowID); if (!TextUtils.isEmpty(prams.toString())) {
print(MODIFY_DATA, sb.toString()); sql.append(prams.toString());
db.execSQL(sb.toString()); sql.append(" where rowid=").append(dbEntity.rowID);
print(MODIFY_DATA, sql.toString());
db.execSQL(sql.toString());
}
} }
close(db); close(db);
} }
@ -477,9 +492,11 @@ final class SqlHelper extends SQLiteOpenHelper {
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后 //外键Map,在Sqlite3中foreign修饰的字段必须放在最后
final List<Field> foreignArray = new ArrayList<>(); final List<Field> foreignArray = new ArrayList<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("create VIRTUAL table ") //sb.append("create VIRTUAL table ")
sb.append("create table ")
.append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName) .append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName)
.append(" USING fts4("); //.append(" USING fts4(");
.append(" (");
for (Field field : fields) { for (Field field : fields) {
field.setAccessible(true); field.setAccessible(true);
if (SqlUtil.ignoreField(field)) { if (SqlUtil.ignoreField(field)) {
@ -656,6 +673,7 @@ final class SqlHelper extends SQLiteOpenHelper {
} }
} }
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid")); entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
mDataCache.put(entity.hashCode(), entity);
entitys.add(entity); entitys.add(entity);
} }
closeCursor(cursor); closeCursor(cursor);

@ -110,10 +110,19 @@ final class SqlUtil {
if (TextUtils.isEmpty(str)) { if (TextUtils.isEmpty(str)) {
return map; return map;
} }
boolean isDecode = false;
if (str.endsWith("_&_decode_&_")) {
isDecode = true;
str = str.substring(0, str.length() - 12);
}
String[] element = str.split(","); String[] element = str.split(",");
for (String data : element) { for (String data : element) {
String[] s = data.split("\\$"); String[] s = data.split("\\$");
map.put(s[0], s[1]); if (isDecode) {
map.put(CommonUtil.decryptBASE64(s[0]), CommonUtil.decryptBASE64(s[1]));
} else {
map.put(s[0], s[1]);
}
} }
return map; return map;
} }
@ -128,10 +137,18 @@ final class SqlUtil {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Set<String> keys = map.keySet(); Set<String> keys = map.keySet();
for (String key : keys) { for (String key : keys) {
sb.append(key).append("$").append(map.get(key)).append(","); sb.append(CommonUtil.encryptBASE64(key))
.append("$")
.append(CommonUtil.encryptBASE64(map.get(key)))
.append(",");
} }
String str = sb.toString(); String str = sb.toString();
return TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1); str = TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1);
//3.3.10版本之前没有decode,需要加标志
if (map.size() != 0) {
str += "_&_decode_&_";
}
return str;
} }
/** /**

@ -1,4 +1,7 @@
## 开发日志 ## 开发日志
+ 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.9 + v_3.3.9
- 添加POST支持 - 添加POST支持
- 任务执行的过程中,如果调用removeRecord()方法,将会取消任务 https://github.com/AriaLyy/Aria/issues/174 - 任务执行的过程中,如果调用removeRecord()方法,将会取消任务 https://github.com/AriaLyy/Aria/issues/174

@ -1,5 +1,5 @@
# Aria # Aria
![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)</br> ![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_3.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)</br>
## [ENGLISH DOC](https://github.com/AriaLyy/Aria/blob/master/ENGLISH_README.md)</br> ## [ENGLISH DOC](https://github.com/AriaLyy/Aria/blob/master/ENGLISH_README.md)</br>
Aria项目源于工作中遇到的一个文件下载管理的需求,当时被下载折磨的痛不欲生,从那时起便萌生了编写一个简单易用,稳当高效的下载框架,aria经历了1.0到3.0的开发,算是越来越接近当初所制定的目标了。 Aria项目源于工作中遇到的一个文件下载管理的需求,当时被下载折磨的痛不欲生,从那时起便萌生了编写一个简单易用,稳当高效的下载框架,aria经历了1.0到3.0的开发,算是越来越接近当初所制定的目标了。
@ -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/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) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:aria-core:3.3.7' compile 'com.arialyy.aria:aria-core:3.3.10'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.7' annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.10'
``` ```
如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html)
@ -97,9 +97,9 @@ protected void onCreate(Bundle savedInstanceState) {
### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki)
### 升级日志 ### 升级日志
+ v_3.3.7 + v_3.3.10
- 修复一个线程重启的问题 https://github.com/AriaLyy/Aria/issues/160 - 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181
- 修复配置文件异常问题、格式化速度为0问题 https://github.com/AriaLyy/Aria/issues/161 - 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182
[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

@ -209,7 +209,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//Aria.download(this).load(DOWNLOAD_URL).removeRecord(); //Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break; break;
case R.id.cancel: case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel(); //Aria.download(this).load(DOWNLOAD_URL).cancel();
Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break; break;
} }
} }
@ -225,7 +226,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.addHeader("groupName", "value") //.addHeader("groupName", "value")
.addHeaders(map) .addHeaders(map)
//.setRequestMode(RequestEnum.POST) //.setRequestMode(RequestEnum.POST)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
.resetState()
.start(); .start();
} }

@ -26,6 +26,7 @@ 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.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -66,6 +67,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
}); });
} }
private void showPopupWindow(int position) { private void showPopupWindow(int position) {
@ -95,6 +97,16 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
break; break;
case R.id.cancel: case R.id.cancel:
Aria.download(this).load(mUrls).cancel(true); Aria.download(this).load(mUrls).cancel(true);
//mUrls = getModule(GroupModule.class).getUrls1();
//Aria.download(this)
// .load(mUrls)
// .setDownloadDirPath(
// Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
// .setGroupAlias("任务组测试")
// .resetState()
// .setSubFileName(getModule(GroupModule.class).getSubName())
// //.setFileSize(32895492)
// .start();
break; break;
} }
} }

@ -31,6 +31,13 @@ public class GroupModule extends BaseModule {
} }
List<String> getUrls() { List<String> getUrls() {
List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
Collections.addAll(urls, str);
return urls;
}
List<String> getUrls1() {
List<String> urls = new ArrayList<>(); List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_urls); String[] str = getContext().getResources().getStringArray(R.array.group_urls);
Collections.addAll(urls, str); Collections.addAll(urls, str);

@ -66,8 +66,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
dialog.show(getSupportFragmentManager(), "download_num"); dialog.show(getSupportFragmentManager(), "download_num");
break; break;
case R.id.stop_all: case R.id.stop_all:
//Aria.download(this).stopAllTask(); Aria.download(this).stopAllTask();
Aria.download(this).removeAllTask(false); //Aria.download(this).removeAllTask(false);
break; break;
case R.id.turn: case R.id.turn:
startActivity(new Intent(this, MultiDownloadActivity.class)); startActivity(new Intent(this, MultiDownloadActivity.class));

@ -58,13 +58,14 @@
<string-array name="group_urls"> <string-array name="group_urls">
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>--> <!--<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>--> <!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item> <!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item> <item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item> <item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>
</string-array> </string-array>
<string-array name="group_urls_1"> <string-array name="group_urls_1">
<item>http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk</item> <item>http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk</item>
<!--<item>https://atom-installer.github.com/v1.13.0/AtomSetup.exe</item>-->
<item>http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk</item> <item>http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk</item>
</string-array> </string-array>
@ -79,7 +80,7 @@
</string-array> </string-array>
<string-array name="group_names"> <string-array name="group_names">
<item>王者荣耀.apk</item> <!--<item>王者荣耀.apk</item>-->
<item>战斗吧剑灵.apk</item> <item>战斗吧剑灵.apk</item>
<item>天魔幻想.apk</item> <item>天魔幻想.apk</item>
</string-array> </string-array>

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.3.9' publishVersion = '3.3.10'
// publishVersion = '1.0.3' //FTP插件 // publishVersion = '1.0.3' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save