添加resetState()方法,刷新下载信息。
https://github.com/AriaLyy/Aria/issues/182
pull/330/head
AriaLyy 7 years ago
parent 31f0acf059
commit a73d867445
  1. 33
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  2. 37
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 1
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  5. 18
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  6. 20
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
  7. 48
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  8. 5
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  9. 21
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  10. 4
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  11. 1
      app/src/main/res/values/strings.xml
  12. 2
      build.gradle

@ -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();
}
if (!mConfigThreadPool.isShutdown()) {
mConfigThreadPool.execute(mConfigThread);
}
}).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.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);
}
@ -85,8 +96,18 @@ public class DownloadReceiver extends AbsReceiver {
*
* @param url 下载地址
* @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);
}
@ -112,8 +133,18 @@ public class DownloadReceiver extends AbsReceiver {
* 使用下载实体执行下载操作
*
* @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请求不能使用该方法");

@ -47,6 +47,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
public TARGET resetState() {
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
mTaskEntity.refreshInfo = true;
mTaskEntity.update();
return (TARGET) this;
}

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

@ -36,15 +36,15 @@ public class DbEntity {
}
/**
* 关键字模糊检索全文
*
* @param column 需要查找的列
* @param mathSql 关键字语法exsimple white OR greenblue AND redwhite 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 greenblue AND redwhite 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);
//}
/**
* 检查某个字段的值是否存在

@ -164,27 +164,27 @@ final class SqlHelper extends SQLiteOpenHelper {
return count;
}
/**
* 关键字模糊检索全文
*
* @param column 需要查找的列
* @param mathSql 关键字语法exsimple white OR greenblue AND redwhite 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;
//}
/**
* 检查某个字段的值是否存在
@ -492,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)) {

@ -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://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk";
//"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2";
//"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk";
"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@ -227,6 +227,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
.addHeaders(map)
//.setRequestMode(RequestEnum.POST)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
.resetState()
.start();
}

@ -96,16 +96,17 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this).load(mUrls).stop();
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("任务组测试")
.setSubFileName(getModule(GroupModule.class).getSubName())
//.setFileSize(32895492)
.start();
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;
}
}

@ -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));

@ -65,6 +65,7 @@
<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>

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

Loading…
Cancel
Save