添加resetState()方法,刷新下载信息。 https://github.com/AriaLyy/Aria/issues/182
This commit is contained in:
@@ -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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -85,8 +96,18 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
*
|
*
|
||||||
* @param url 下载地址
|
* @param url 下载地址
|
||||||
* @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true}
|
* @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);
|
||||||
}
|
}
|
||||||
@@ -112,8 +133,18 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* 使用下载实体执行下载操作
|
* 使用下载实体执行下载操作
|
||||||
*
|
*
|
||||||
* @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true}
|
* @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请求不能使用该方法");
|
||||||
|
@@ -47,6 +47,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
|||||||
*/
|
*/
|
||||||
public TARGET resetState() {
|
public TARGET resetState() {
|
||||||
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
||||||
|
mTaskEntity.refreshInfo = true;
|
||||||
mTaskEntity.update();
|
mTaskEntity.update();
|
||||||
return (TARGET) this;
|
return (TARGET) this;
|
||||||
}
|
}
|
||||||
|
@@ -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 = 21;
|
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 green”、“blue AND red”、“white 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 green”、“blue AND red”、“white 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);
|
||||||
}
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查某个字段的值是否存在
|
* 检查某个字段的值是否存在
|
||||||
|
@@ -164,27 +164,27 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* 关键字模糊检索全文
|
// * 关键字模糊检索全文
|
||||||
*
|
// *
|
||||||
* @param column 需要查找的列
|
// * @param column 需要查找的列
|
||||||
* @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white 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;
|
||||||
}
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查某个字段的值是否存在
|
* 检查某个字段的值是否存在
|
||||||
@@ -492,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)) {
|
||||||
|
@@ -61,8 +61,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
//"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1";
|
//"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1";
|
||||||
//不支持断点的链接
|
//不支持断点的链接
|
||||||
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||||
"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk";
|
//"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk";
|
||||||
//"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2";
|
"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2";
|
||||||
@Bind(R.id.start) Button mStart;
|
@Bind(R.id.start) Button mStart;
|
||||||
@Bind(R.id.stop) Button mStop;
|
@Bind(R.id.stop) Button mStop;
|
||||||
@Bind(R.id.cancel) Button mCancel;
|
@Bind(R.id.cancel) Button mCancel;
|
||||||
@@ -227,6 +227,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
.addHeaders(map)
|
.addHeaders(map)
|
||||||
//.setRequestMode(RequestEnum.POST)
|
//.setRequestMode(RequestEnum.POST)
|
||||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||||
|
.resetState()
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -96,16 +96,17 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
|||||||
Aria.download(this).load(mUrls).stop();
|
Aria.download(this).load(mUrls).stop();
|
||||||
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();
|
//mUrls = getModule(GroupModule.class).getUrls1();
|
||||||
Aria.download(this)
|
//Aria.download(this)
|
||||||
.load(mUrls)
|
// .load(mUrls)
|
||||||
.setDownloadDirPath(
|
// .setDownloadDirPath(
|
||||||
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
|
// Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
|
||||||
.setGroupAlias("任务组测试")
|
// .setGroupAlias("任务组测试")
|
||||||
.setSubFileName(getModule(GroupModule.class).getSubName())
|
// .resetState()
|
||||||
//.setFileSize(32895492)
|
// .setSubFileName(getModule(GroupModule.class).getSubName())
|
||||||
.start();
|
// //.setFileSize(32895492)
|
||||||
|
// .start();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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));
|
||||||
|
@@ -65,6 +65,7 @@
|
|||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
|
@@ -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.10'
|
publishVersion = '3.3.10_dev'
|
||||||
// publishVersion = '1.0.3' //FTP插件
|
// publishVersion = '1.0.3' //FTP插件
|
||||||
repoName='maven'
|
repoName='maven'
|
||||||
desc = 'android 下载框架'
|
desc = 'android 下载框架'
|
||||||
|
Reference in New Issue
Block a user