Merge branch 'v_3.0'
This commit is contained in:
@@ -32,6 +32,8 @@ import java.math.BigDecimal;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/1/18.
|
||||
@@ -60,6 +62,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
private String mTaskType;
|
||||
private Timer mFailTimer;
|
||||
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,
|
||||
SubThreadConfig<TASK_ENTITY> info) {
|
||||
@@ -76,6 +89,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
|
||||
mTaskType = getTaskType();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
mConfigThreadPool = Executors.newCachedThreadPool();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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) {
|
||||
mChildCurrentLocation += len;
|
||||
STATE.CURRENT_LOCATION += len;
|
||||
//mIncrement += len;
|
||||
if (System.currentTimeMillis() - mLastSaveTime > 5000
|
||||
&& mChildCurrentLocation < mConfig.END_LOCATION) {
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
final long currentTemp = mChildCurrentLocation;
|
||||
try {
|
||||
writeConfig(false, currentTemp);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
if (!mConfigThreadPool.isShutdown()) {
|
||||
mConfigThreadPool.execute(mConfigThread);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
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.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -36,8 +37,7 @@ public class DownloadGroupTarget
|
||||
this.mUrls.addAll(groupEntity.getUrls());
|
||||
}
|
||||
mGroupName = CommonUtil.getMd5Code(groupEntity.getUrls());
|
||||
mTaskEntity = TEManager.getInstance()
|
||||
.getTEntity(DownloadGroupTaskEntity.class, mGroupName);
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadGroupTaskEntity.class, mGroupName);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity =
|
||||
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.inf.AbsEntity;
|
||||
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.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulerListener;
|
||||
@@ -65,8 +66,18 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* 使用下载实体执行下载操作
|
||||
*
|
||||
* @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);
|
||||
return new DownloadTarget(entity, targetName, refreshInfo);
|
||||
}
|
||||
@@ -84,9 +95,19 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* 加载Http、https单任务下载地址
|
||||
*
|
||||
* @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);
|
||||
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);
|
||||
if (!entity.getUrl().startsWith("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.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -63,6 +64,11 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
|
||||
@Override protected void onStart() {
|
||||
super.onStart();
|
||||
if (mExeMap.size() == 0){
|
||||
ALog.e(TAG, "任务组无可执行任务");
|
||||
mListener.onFail(false);
|
||||
return;
|
||||
}
|
||||
Set<String> keys = mExeMap.keySet();
|
||||
int i = 0;
|
||||
for (String key : keys) {
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class AbsGroupTask<TASK_ENTITY extends AbsGroupTaskEntity>
|
||||
protected AbsGroupUtil mUtil;
|
||||
|
||||
@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.download.DownloadGroupTaskEntity;
|
||||
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.util.ALog;
|
||||
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 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();
|
||||
} else {
|
||||
mTaskEntity.deleteData();
|
||||
TEManager.getInstance().removeTEntity(mEntity.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
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.DownloadTaskEntity;
|
||||
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.CommonUtil;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -35,7 +34,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class TEManager {
|
||||
private static final String TAG = "TaskManager";
|
||||
private static volatile TEManager INSTANCE = null;
|
||||
private Map<String, AbsTaskEntity> map = new ConcurrentHashMap<>();
|
||||
private LruCache<String, AbsTaskEntity> cache = new LruCache<>(1024);
|
||||
private Lock lock;
|
||||
|
||||
public static TEManager getInstance() {
|
||||
@@ -61,7 +60,7 @@ public class TEManager {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(key));
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
ITEntityFactory factory = chooseFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -69,7 +68,7 @@ public class TEManager {
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(key);
|
||||
map.put(convertKey(key), tEntity);
|
||||
cache.put(convertKey(key), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
@@ -87,7 +86,7 @@ public class TEManager {
|
||||
lock.lock();
|
||||
try {
|
||||
String groupName = CommonUtil.getMd5Code(urls);
|
||||
AbsTaskEntity tEntity = map.get(convertKey(groupName));
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(groupName));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
IGTEntityFactory factory = chooseGroupFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -95,7 +94,7 @@ public class TEManager {
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(groupName, urls);
|
||||
map.put(convertKey(groupName), tEntity);
|
||||
cache.put(convertKey(groupName), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
@@ -112,7 +111,7 @@ public class TEManager {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(absEntity.getKey()));
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(absEntity.getKey()));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
ITEntityFactory factory = chooseFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -120,7 +119,7 @@ public class TEManager {
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(absEntity);
|
||||
map.put(convertKey(absEntity.getKey()), tEntity);
|
||||
cache.put(convertKey(absEntity.getKey()), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
@@ -153,7 +152,7 @@ public class TEManager {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(key));
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -177,7 +176,7 @@ public class TEManager {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
return map.put(convertKey(te.key), te) != null;
|
||||
return cache.put(convertKey(te.key), te) != null;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
@@ -185,12 +184,13 @@ public class TEManager {
|
||||
|
||||
/**
|
||||
* 通过key删除任务实体
|
||||
* 当任务complete或删除记录时将删除缓存
|
||||
*/
|
||||
public AbsTaskEntity removeTEntity(String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
return map.remove(convertKey(key));
|
||||
return cache.remove(convertKey(key));
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Map;
|
||||
class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 20;
|
||||
static int VERSION = 22;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
|
||||
@@ -36,15 +36,15 @@ public class DbEntity {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @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) {
|
||||
return DbUtil.getInstance().searchData(clazz, column, mathSql);
|
||||
}
|
||||
///**
|
||||
// * 关键字模糊检索全文
|
||||
// *
|
||||
// * @param column 需要查找的列
|
||||
// * @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) {
|
||||
// return DbUtil.getInstance().searchData(clazz, column, mathSql);
|
||||
//}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
|
||||
@@ -64,16 +64,16 @@ public class DbUtil {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @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) {
|
||||
checkDb();
|
||||
return SqlHelper.searchData(mDb, clazz, column, mathSql);
|
||||
}
|
||||
///**
|
||||
// * 关键字模糊检索全文
|
||||
// *
|
||||
// * @param column 需要查找的列
|
||||
// * @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) {
|
||||
// checkDb();
|
||||
// return SqlHelper.searchData(mDb, clazz, column, mathSql);
|
||||
//}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -49,6 +50,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
private static final int DEL_DATA = 6;
|
||||
|
||||
private static volatile SqlHelper INSTANCE = null;
|
||||
private static LruCache<Integer, DbEntity> mDataCache = new LruCache<>(1024);
|
||||
|
||||
static SqlHelper init(Context context) {
|
||||
if (INSTANCE == null) {
|
||||
@@ -162,27 +164,27 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @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,
|
||||
String column, String mathSql) {
|
||||
String sql = "SELECT * FROM "
|
||||
+ CommonUtil.getClassName(clazz)
|
||||
+ " WHERE "
|
||||
+ column
|
||||
+ " MATCH '"
|
||||
+ mathSql
|
||||
+ "'";
|
||||
|
||||
Cursor cursor = db.rawQuery(sql, null);
|
||||
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
||||
closeCursor(cursor);
|
||||
return data;
|
||||
}
|
||||
///**
|
||||
// * 关键字模糊检索全文
|
||||
// *
|
||||
// * @param column 需要查找的列
|
||||
// * @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,
|
||||
// String column, String mathSql) {
|
||||
// String sql = "SELECT * FROM "
|
||||
// + CommonUtil.getClassName(clazz)
|
||||
// + " WHERE "
|
||||
// + column
|
||||
// + " MATCH '"
|
||||
// + mathSql
|
||||
// + "'";
|
||||
//
|
||||
// Cursor cursor = db.rawQuery(sql, null);
|
||||
// List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
||||
// closeCursor(cursor);
|
||||
// return data;
|
||||
//}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
@@ -328,19 +330,27 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
db = checkDb(db);
|
||||
Class<?> clazz = dbEntity.getClass();
|
||||
List<Field> fields = CommonUtil.getAllFields(clazz);
|
||||
DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode());
|
||||
if (fields != null && fields.size() > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET ");
|
||||
StringBuilder sql = new StringBuilder();
|
||||
StringBuilder prams = new StringBuilder();
|
||||
sql.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET ");
|
||||
int i = 0;
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (SqlUtil.ignoreField(field)) {
|
||||
continue;
|
||||
}
|
||||
sb.append(i > 0 ? ", " : "");
|
||||
try {
|
||||
if (cacheEntity != null && field.get(dbEntity) == field.get(cacheEntity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//sb.append(i > 0 ? ", " : "");
|
||||
//sb.append(field.getName()).append("='");
|
||||
String value;
|
||||
sb.append(field.getName()).append("='");
|
||||
prams.append(i > 0 ? ", " : "");
|
||||
prams.append(field.getName()).append("='");
|
||||
Type type = field.getType();
|
||||
if (type == Map.class) {
|
||||
value = SqlUtil.map2Str((Map<String, String>) field.get(dbEntity));
|
||||
@@ -357,16 +367,21 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
value = obj == null ? "" : obj.toString();
|
||||
}
|
||||
|
||||
sb.append(value == null ? "" : value);
|
||||
sb.append("'");
|
||||
//sb.append(value == null ? "" : value);
|
||||
//sb.append("'");
|
||||
prams.append(TextUtils.isEmpty(value) ? "" : value);
|
||||
prams.append("'");
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sb.append(" where rowid=").append(dbEntity.rowID);
|
||||
print(MODIFY_DATA, sb.toString());
|
||||
db.execSQL(sb.toString());
|
||||
if (!TextUtils.isEmpty(prams.toString())) {
|
||||
sql.append(prams.toString());
|
||||
sql.append(" where rowid=").append(dbEntity.rowID);
|
||||
print(MODIFY_DATA, sql.toString());
|
||||
db.execSQL(sql.toString());
|
||||
}
|
||||
}
|
||||
close(db);
|
||||
}
|
||||
@@ -477,9 +492,11 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后
|
||||
final List<Field> foreignArray = new ArrayList<>();
|
||||
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(" USING fts4(");
|
||||
//.append(" USING fts4(");
|
||||
.append(" (");
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (SqlUtil.ignoreField(field)) {
|
||||
@@ -656,6 +673,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
}
|
||||
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
||||
mDataCache.put(entity.hashCode(), entity);
|
||||
entitys.add(entity);
|
||||
}
|
||||
closeCursor(cursor);
|
||||
|
||||
@@ -110,10 +110,19 @@ final class SqlUtil {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return map;
|
||||
}
|
||||
boolean isDecode = false;
|
||||
if (str.endsWith("_&_decode_&_")) {
|
||||
isDecode = true;
|
||||
str = str.substring(0, str.length() - 12);
|
||||
}
|
||||
String[] element = str.split(",");
|
||||
for (String data : element) {
|
||||
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;
|
||||
}
|
||||
@@ -128,10 +137,18 @@ final class SqlUtil {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<String> keys = map.keySet();
|
||||
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();
|
||||
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
|
||||
- 添加POST支持
|
||||
- 任务执行的过程中,如果调用removeRecord()方法,将会取消任务 https://github.com/AriaLyy/Aria/issues/174
|
||||
|
||||
12
README.md
12
README.md
@@ -1,5 +1,5 @@
|
||||
# Aria
|
||||
</br>
|
||||
</br>
|
||||
## [ENGLISH DOC](https://github.com/AriaLyy/Aria/blob/master/ENGLISH_README.md)</br>
|
||||
Aria项目源于工作中遇到的一个文件下载管理的需求,当时被下载折磨的痛不欲生,从那时起便萌生了编写一个简单易用,稳当高效的下载框架,aria经历了1.0到3.0的开发,算是越来越接近当初所制定的目标了。
|
||||
|
||||
@@ -28,8 +28,8 @@ Aria有以下特点:
|
||||
[](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
|
||||
[](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
|
||||
```java
|
||||
compile 'com.arialyy.aria:aria-core:3.3.7'
|
||||
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.7'
|
||||
compile 'com.arialyy.aria:aria-core:3.3.10'
|
||||
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.10'
|
||||
```
|
||||
如果你使用的是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)
|
||||
|
||||
### 升级日志
|
||||
+ v_3.3.7
|
||||
- 修复一个线程重启的问题 https://github.com/AriaLyy/Aria/issues/160
|
||||
- 修复配置文件异常问题、格式化速度为0问题 https://github.com/AriaLyy/Aria/issues/161
|
||||
+ 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
|
||||
|
||||
[更多版本记录](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();
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +226,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
//.addHeader("groupName", "value")
|
||||
.addHeaders(map)
|
||||
//.setRequestMode(RequestEnum.POST)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg.apk")
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||
.resetState()
|
||||
.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.DownloadGroupTask;
|
||||
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.T;
|
||||
import com.arialyy.simple.R;
|
||||
@@ -66,6 +67,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void showPopupWindow(int position) {
|
||||
@@ -95,6 +97,16 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
break;
|
||||
case R.id.cancel:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,13 @@ public class GroupModule extends BaseModule {
|
||||
}
|
||||
|
||||
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<>();
|
||||
String[] str = getContext().getResources().getStringArray(R.array.group_urls);
|
||||
Collections.addAll(urls, str);
|
||||
|
||||
@@ -66,8 +66,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
break;
|
||||
case R.id.stop_all:
|
||||
//Aria.download(this).stopAllTask();
|
||||
Aria.download(this).removeAllTask(false);
|
||||
Aria.download(this).stopAllTask();
|
||||
//Aria.download(this).removeAllTask(false);
|
||||
break;
|
||||
case R.id.turn:
|
||||
startActivity(new Intent(this, MultiDownloadActivity.class));
|
||||
|
||||
@@ -58,13 +58,14 @@
|
||||
<string-array name="group_urls">
|
||||
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.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.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_urls_1">
|
||||
<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>
|
||||
</string-array>
|
||||
|
||||
@@ -79,7 +80,7 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_names">
|
||||
<item>王者荣耀.apk</item>
|
||||
<!--<item>王者荣耀.apk</item>-->
|
||||
<item>战斗吧剑灵.apk</item>
|
||||
<item>天魔幻想.apk</item>
|
||||
</string-array>
|
||||
|
||||
@@ -39,7 +39,7 @@ task clean(type: Delete) {
|
||||
ext {
|
||||
userOrg = 'arialyy'
|
||||
groupId = 'com.arialyy.aria'
|
||||
publishVersion = '3.3.9'
|
||||
publishVersion = '3.3.10'
|
||||
// publishVersion = '1.0.3' //FTP插件
|
||||
repoName='maven'
|
||||
desc = 'android 下载框架'
|
||||
|
||||
Reference in New Issue
Block a user