修复任务组保存数据出现的问题
This commit is contained in:
@ -17,8 +17,10 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.command.AbsCmd;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
@ -40,8 +42,8 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
AbsNormalCmd(String targetName, T entity) {
|
||||
canExeCmd = CheckUtil.checkCmdEntity(entity,
|
||||
!(this instanceof CancelCmd) || !(this instanceof StopCmd));
|
||||
//canExeCmd = CheckUtil.checkCmdEntity(entity,
|
||||
// !(this instanceof CancelCmd) || !(this instanceof StopCmd));
|
||||
mTargetName = targetName;
|
||||
mTaskEntity = entity;
|
||||
TAG = CommonUtil.getClassName(this);
|
||||
@ -51,6 +53,9 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
} else if (entity instanceof UploadTaskEntity) {
|
||||
mQueue = UploadTaskQueue.getInstance();
|
||||
isDownloadCmd = false;
|
||||
} else if (entity instanceof DownloadGroupTaskEntity) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
isDownloadCmd = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ import android.os.Parcel;
|
||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||
import com.arialyy.aria.orm.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -28,26 +27,25 @@ import java.util.List;
|
||||
*/
|
||||
public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
|
||||
@OneToMany(table = DownloadEntity.class, key = "groupName") private List<DownloadEntity>
|
||||
mSubtask = new ArrayList<>();
|
||||
@OneToMany(table = DownloadEntity.class, key = "groupName") private List<DownloadEntity> subtask = new ArrayList<>();
|
||||
|
||||
//任务组下载文件的文件夹地址
|
||||
private String mDirPath = "";
|
||||
private String dirPath = "";
|
||||
|
||||
public List<DownloadEntity> getSubTask() {
|
||||
return mSubtask;
|
||||
return subtask;
|
||||
}
|
||||
|
||||
public void setSubTasks(List<DownloadEntity> subTasks) {
|
||||
this.mSubtask = subTasks;
|
||||
this.subtask = subTasks;
|
||||
}
|
||||
|
||||
public String getDirPath() {
|
||||
return mDirPath;
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
public void setDirPath(String dirPath) {
|
||||
this.mDirPath = dirPath;
|
||||
this.dirPath = dirPath;
|
||||
}
|
||||
|
||||
public DownloadGroupEntity() {
|
||||
@ -59,14 +57,14 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
|
||||
@Override public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeTypedList(this.mSubtask);
|
||||
dest.writeString(this.mDirPath);
|
||||
dest.writeTypedList(this.subtask);
|
||||
dest.writeString(this.dirPath);
|
||||
}
|
||||
|
||||
protected DownloadGroupEntity(Parcel in) {
|
||||
super(in);
|
||||
this.mSubtask = in.createTypedArrayList(DownloadEntity.CREATOR);
|
||||
this.mDirPath = in.readString();
|
||||
this.subtask = in.createTypedArrayList(DownloadEntity.CREATOR);
|
||||
this.dirPath = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<DownloadGroupEntity> CREATOR = new Creator<DownloadGroupEntity>() {
|
||||
|
@ -50,7 +50,8 @@ public class DownloadGroupTarget
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new DownloadGroupTaskEntity();
|
||||
mTaskEntity.key = mGroupName;
|
||||
mTaskEntity.entity = new DownloadGroupEntity();
|
||||
mTaskEntity.entity = getDownloadGroupEntity();
|
||||
mTaskEntity.insert();
|
||||
}
|
||||
if (mTaskEntity.entity == null) {
|
||||
mTaskEntity.entity = getDownloadGroupEntity();
|
||||
@ -63,6 +64,9 @@ public class DownloadGroupTarget
|
||||
DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName);
|
||||
if (entity == null) {
|
||||
entity = new DownloadGroupEntity();
|
||||
entity.setGroupName(mGroupName);
|
||||
entity.setUrlmd5(mGroupName);
|
||||
entity.insert();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
@ -101,12 +105,12 @@ public class DownloadGroupTarget
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
mEntity.setDirPath(groupDirPath);
|
||||
if (!TextUtils.isEmpty(mEntity.getDirPath())) {
|
||||
reChangeDirPath(groupDirPath);
|
||||
} else {
|
||||
mEntity.setSubTasks(createSubTask());
|
||||
}
|
||||
mEntity.setDirPath(groupDirPath);
|
||||
mEntity.update();
|
||||
isSetDirPathed = true;
|
||||
return this;
|
||||
@ -157,15 +161,26 @@ public class DownloadGroupTarget
|
||||
for (int i = 0, len = mUrls.size(); i < len; i++) {
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(mUrls.get(i));
|
||||
String fileName = mSubtaskFileName.get(i);
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
fileName = CommonUtil.keyToHashKey(mUrls.get(i));
|
||||
}
|
||||
String fileName = mSubtaskFileName.isEmpty() ? CommonUtil.keyToHashKey(mUrls.get(i))
|
||||
: mSubtaskFileName.get(i);
|
||||
entity.setDownloadPath(mEntity.getDirPath() + "/" + fileName);
|
||||
entity.setGroupName(mGroupName);
|
||||
entity.save();
|
||||
entity.setGroupChild(true);
|
||||
entity.setFileName(fileName);
|
||||
entity.insert();
|
||||
list.add(entity);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
///**
|
||||
// * 创建文件名,如果url链接有后缀名,则使用url中的后缀名
|
||||
// * @return url 的 hashKey
|
||||
// */
|
||||
//private String createFileName(String url){
|
||||
// if (url.contains(".")){
|
||||
// int s = url.lastIndexOf(".");
|
||||
// String fileName = url.substring()
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
mUtil.stopDownload();
|
||||
mUtil.startDownload();
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@ -117,8 +118,8 @@ class FileInfoThread implements Runnable {
|
||||
if (onFileInfoListener != null) {
|
||||
onFileInfoListener.onComplete(mEntity.getDownloadUrl(), code);
|
||||
}
|
||||
mEntity.save();
|
||||
mTaskEntity.save();
|
||||
mEntity.update();
|
||||
mTaskEntity.update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +128,13 @@ class FileInfoThread implements Runnable {
|
||||
*/
|
||||
private void handle302Turn(HttpURLConnection conn) throws IOException {
|
||||
String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey);
|
||||
Log.d(TAG, "30x跳转,新url为【" + newUrl + "】");
|
||||
Log.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】");
|
||||
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
|
||||
if (onFileInfoListener != null) {
|
||||
onFileInfoListener.onFail(mEntity.getDownloadUrl(), "获取重定向链接失败");
|
||||
}
|
||||
return;
|
||||
}
|
||||
String cookies = conn.getHeaderField("Set-Cookie");
|
||||
conn = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
public class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 6;
|
||||
static int VERSION = 7;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
|
@ -125,7 +125,7 @@ public class DbEntity {
|
||||
*/
|
||||
public void save() {
|
||||
synchronized (LOCK) {
|
||||
if (DbUtil.getInstance().tableExists(getClass()) && thisIsExist()) {
|
||||
if (thisIsExist()) {
|
||||
update();
|
||||
} else {
|
||||
insert();
|
||||
|
@ -373,6 +373,14 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
close(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存一对一的数据
|
||||
* @param field
|
||||
*/
|
||||
private void saveOneToOneFile(Field field){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一对一参数
|
||||
*/
|
||||
@ -602,7 +610,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
if (TextUtils.isEmpty(primaryData)) continue;
|
||||
List<T> list = findForeignData(db, primaryData, params);
|
||||
if (list == null) continue;
|
||||
field.set(entity, findForeignData(db, primaryKey, params));
|
||||
field.set(entity, findForeignData(db, primaryData, params));
|
||||
} else if (isOneToOne(field)) {
|
||||
String primaryKey = getPrimaryName(clazz);
|
||||
if (TextUtils.isEmpty(primaryKey)) {
|
||||
|
@ -23,6 +23,7 @@ import butterknife.OnClick;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMainBinding;
|
||||
import com.arialyy.simple.download.DownloadActivity;
|
||||
import com.arialyy.simple.download.group.DownloadGroupActivity;
|
||||
import com.arialyy.simple.test.TestMutilTaskSysDownload;
|
||||
import com.arialyy.simple.upload.UploadActivity;
|
||||
|
||||
@ -53,7 +54,7 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
startActivity(new Intent(this, UploadActivity.class));
|
||||
break;
|
||||
case R.id.download_task_group:
|
||||
|
||||
startActivity(new Intent(this, DownloadGroupActivity.class));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -61,26 +61,25 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
//});
|
||||
}
|
||||
|
||||
//public void onClick(View view) {
|
||||
// switch (view.getId()) {
|
||||
// case R.id.start:
|
||||
// String text = ((TextView) view).getText().toString();
|
||||
// if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
// Aria.download(this)
|
||||
// .load(mUrls)
|
||||
// .setDownloadPaths()
|
||||
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
// .start();
|
||||
// } else if (text.equals("恢复")) {
|
||||
// Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
// }
|
||||
// break;
|
||||
// case R.id.stop:
|
||||
// Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
// break;
|
||||
// case R.id.cancel:
|
||||
// Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
Aria.download(this)
|
||||
.load(mUrls)
|
||||
.setDownloadDirPath(Environment.getExternalStorageDirectory().getPath() + "/group_test")
|
||||
.start();
|
||||
} else if (text.equals("恢复")) {
|
||||
//Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
}
|
||||
break;
|
||||
case R.id.stop:
|
||||
//Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
//Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user