子任务状态注解实现
This commit is contained in:
@@ -372,16 +372,19 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
entity.setFileSize(fileSize);
|
entity.setFileSize(fileSize);
|
||||||
entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
|
entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
|
||||||
saveData(IEntity.STATE_POST_PRE, -1);
|
saveData(IEntity.STATE_POST_PRE, -1);
|
||||||
|
mListener.onSubPre(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onResume(long resumeLocation) {
|
@Override public void onResume(long resumeLocation) {
|
||||||
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
|
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
|
||||||
lastLen = resumeLocation;
|
lastLen = resumeLocation;
|
||||||
|
mListener.onSubStart(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onStart(long startLocation) {
|
@Override public void onStart(long startLocation) {
|
||||||
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
|
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
|
||||||
lastLen = startLocation;
|
lastLen = startLocation;
|
||||||
|
mListener.onSubStart(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onProgress(long currentLocation) {
|
@Override public void onProgress(long currentLocation) {
|
||||||
@@ -390,6 +393,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
lastLen = currentLocation;
|
lastLen = currentLocation;
|
||||||
entity.setCurrentProgress(currentLocation);
|
entity.setCurrentProgress(currentLocation);
|
||||||
handleSpeed(speed);
|
handleSpeed(speed);
|
||||||
|
mListener.onSubRunning(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onStop(long stopLocation) {
|
@Override public void onStop(long stopLocation) {
|
||||||
|
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
|
|||||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -45,7 +46,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
HttpURLConnection conn = null;
|
HttpURLConnection conn = null;
|
||||||
InputStream is = null;
|
BufferedInputStream is = null;
|
||||||
BufferedRandomAccessFile file = null;
|
BufferedRandomAccessFile file = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
|
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
|
||||||
@@ -69,7 +70,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
|
conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
|
||||||
conn.setConnectTimeout(STATE.CONNECT_TIME_OUT);
|
conn.setConnectTimeout(STATE.CONNECT_TIME_OUT);
|
||||||
conn.setReadTimeout(STATE.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数
|
conn.setReadTimeout(STATE.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数
|
||||||
is = conn.getInputStream();
|
//is = conn.getInputStream();
|
||||||
|
is = new BufferedInputStream(conn.getInputStream());
|
||||||
//创建可设置位置的文件
|
//创建可设置位置的文件
|
||||||
file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize);
|
file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize);
|
||||||
//设置每条线程写入文件的位置
|
//设置每条线程写入文件的位置
|
||||||
@@ -84,6 +86,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
if (mSleepTime > 0) Thread.sleep(mSleepTime);
|
if (mSleepTime > 0) Thread.sleep(mSleepTime);
|
||||||
file.write(buffer, 0, len);
|
file.write(buffer, 0, len);
|
||||||
progress(len);
|
progress(len);
|
||||||
|
Log.d(TAG, len + "");
|
||||||
}
|
}
|
||||||
if (STATE.isCancel || STATE.isStop) return;
|
if (STATE.isCancel || STATE.isStop) return;
|
||||||
//支持断点的处理
|
//支持断点的处理
|
||||||
|
@@ -26,6 +26,7 @@ import android.util.Log;
|
|||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.util.CheckUtil;
|
import com.arialyy.aria.util.CheckUtil;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -180,7 +181,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
print(FIND_DATA, sql);
|
print(FIND_DATA, sql);
|
||||||
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;
|
||||||
cursor.close();
|
closeCursor(cursor);
|
||||||
close(db);
|
close(db);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -223,7 +224,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
print(FIND_DATA, sb.toString());
|
print(FIND_DATA, sb.toString());
|
||||||
Cursor cursor = db.rawQuery(sb.toString(), null);
|
Cursor cursor = db.rawQuery(sb.toString(), null);
|
||||||
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
||||||
cursor.close();
|
closeCursor(cursor);
|
||||||
close(db);
|
close(db);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -238,7 +239,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
print(FIND_ALL_DATA, sb.toString());
|
print(FIND_ALL_DATA, sb.toString());
|
||||||
Cursor cursor = db.rawQuery(sb.toString(), null);
|
Cursor cursor = db.rawQuery(sb.toString(), null);
|
||||||
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
||||||
cursor.close();
|
closeCursor(cursor);
|
||||||
close(db);
|
close(db);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -394,7 +395,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) cursor.close();
|
closeCursor(cursor);
|
||||||
close(db);
|
close(db);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -564,7 +565,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
||||||
entitys.add(entity);
|
entitys.add(entity);
|
||||||
}
|
}
|
||||||
cursor.close();
|
closeCursor(cursor);
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@@ -586,6 +587,16 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
return findData(db, params[0], params[1] + "=?", primary);
|
return findData(db, params[0], params[1] + "=?", primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void closeCursor(Cursor cursor){
|
||||||
|
if (cursor != null && !cursor.isClosed()) {
|
||||||
|
try {
|
||||||
|
cursor.close();
|
||||||
|
} catch (android.database.SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void close(SQLiteDatabase db) {
|
private static void close(SQLiteDatabase db) {
|
||||||
//if (db != null && db.isOpen()) db.close();
|
//if (db != null && db.isOpen()) db.close();
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
|||||||
Aria.download(this).register();
|
Aria.download(this).register();
|
||||||
setTitle("任务组");
|
setTitle("任务组");
|
||||||
mUrls = getModule(GroupModule.class).getUrls();
|
mUrls = getModule(GroupModule.class).getUrls();
|
||||||
DownloadGroupEntity e = Aria.download(this).getGroupTaskList().get(0);
|
|
||||||
DownloadGroupTaskEntity entity = Aria.download(this).getDownloadGroupTask(mUrls);
|
DownloadGroupTaskEntity entity = Aria.download(this).getDownloadGroupTask(mUrls);
|
||||||
if (entity != null && entity.getEntity() != null) {
|
if (entity != null && entity.getEntity() != null) {
|
||||||
DownloadGroupEntity groupEntity = entity.getEntity();
|
DownloadGroupEntity groupEntity = entity.getEntity();
|
||||||
@@ -98,11 +97,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
|
|
||||||
DownloadEntity subEntity) {
|
|
||||||
L.d(TAG, subEntity.getPercent() + "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) {
|
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) {
|
||||||
L.d(TAG, "group pre");
|
L.d(TAG, "group pre");
|
||||||
}
|
}
|
||||||
@@ -154,4 +148,42 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
|||||||
T.showShort(this, "任务组下载完成");
|
T.showShort(this, "任务组下载完成");
|
||||||
L.d(TAG, "任务组下载完成");
|
L.d(TAG, "任务组下载完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////任务组子任务///////////////////////////////////
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getFileName() + "__________" + subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskStop void onSubTaskStop(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskStart void onSubTaskStart(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskComplete void onSubTaskComplete(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask,
|
||||||
|
DownloadEntity subEntity) {
|
||||||
|
L.d(TAG, subEntity.getPercent() + "");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user