添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态

pull/330/head
AriaLyy 7 years ago
parent a903180491
commit 31f0acf059
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 6
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java
  5. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  6. 1
      Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java
  7. 26
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  8. 3
      DEV_LOG.md
  9. 6
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  10. 13
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  11. 7
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  12. 4
      app/src/main/res/values/strings.xml
  13. 2
      build.gradle

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

@ -84,7 +84,7 @@ public class DownloadReceiver extends AbsReceiver {
* 加载Httphttps单任务下载地址 * 加载Httphttps单任务下载地址
* *
* @param url 下载地址 * @param url 下载地址
* @param refreshInfo 是否刷新下载信息 * @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
*/ */
public DownloadTarget load(@NonNull String url, boolean refreshInfo) { public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrl(url); CheckUtil.checkUrl(url);
@ -111,7 +111,7 @@ public class DownloadReceiver extends AbsReceiver {
/** /**
* 使用下载实体执行下载操作 * 使用下载实体执行下载操作
* *
* @param refreshInfo 是否刷新下载信息 * @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
*/ */
public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) { public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity); CheckUtil.checkDownloadEntity(entity);

@ -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();
} }
/** /**

@ -42,6 +42,15 @@ 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.update();
return (TARGET) this;
}
/** /**
* 删除记录如果任务正在执行则会删除正在下载的任务 * 删除记录如果任务正在执行则会删除正在下载的任务
*/ */

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

@ -332,8 +332,9 @@ final class SqlHelper extends SQLiteOpenHelper {
List<Field> fields = CommonUtil.getAllFields(clazz); List<Field> fields = CommonUtil.getAllFields(clazz);
DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode()); 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);
@ -345,9 +346,11 @@ final class SqlHelper extends SQLiteOpenHelper {
continue; continue;
} }
sb.append(i > 0 ? ", " : ""); //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));
@ -364,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);
} }

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

@ -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;
@ -226,7 +226,7 @@ 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")
.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) {
@ -94,7 +96,16 @@ 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();
Aria.download(this)
.load(mUrls)
.setDownloadDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
.setGroupAlias("任务组测试")
.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);

@ -58,7 +58,7 @@
<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>
@ -79,7 +79,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