From a6434dc2f1c4588ec897488414edc46901e6b356 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Sat, 9 Sep 2017 13:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=90=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../download/downloader/AbsGroupUtil.java | 4 ++ .../download/downloader/HttpThreadTask.java | 7 ++- .../java/com/arialyy/aria/orm/SqlHelper.java | 21 ++++++--- .../download/group/DownloadGroupActivity.java | 44 ++++++++++++++++--- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 6d13beab..c5d9d164 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -372,16 +372,19 @@ public abstract class AbsGroupUtil implements IUtil { entity.setFileSize(fileSize); entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize)); saveData(IEntity.STATE_POST_PRE, -1); + mListener.onSubPre(entity); } @Override public void onResume(long resumeLocation) { saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); lastLen = resumeLocation; + mListener.onSubStart(entity); } @Override public void onStart(long startLocation) { saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); lastLen = startLocation; + mListener.onSubStart(entity); } @Override public void onProgress(long currentLocation) { @@ -390,6 +393,7 @@ public abstract class AbsGroupUtil implements IUtil { lastLen = currentLocation; entity.setCurrentProgress(currentLocation); handleSpeed(speed); + mListener.onSubRunning(entity); } @Override public void onStop(long stopLocation) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index bcbcd13f..296ff66e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -24,6 +24,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.CommonUtil; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -45,7 +46,7 @@ final class HttpThreadTask extends AbsThreadTask 0) Thread.sleep(mSleepTime); file.write(buffer, 0, len); progress(len); + Log.d(TAG, len + ""); } if (STATE.isCancel || STATE.isStop) return; //支持断点的处理 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index c5affd31..f31fe386 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -26,6 +26,7 @@ import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Type; import java.util.ArrayList; @@ -180,7 +181,7 @@ final class SqlHelper extends SQLiteOpenHelper { print(FIND_DATA, sql); Cursor cursor = db.rawQuery(sql, null); List data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; - cursor.close(); + closeCursor(cursor); close(db); return data; } @@ -223,7 +224,7 @@ final class SqlHelper extends SQLiteOpenHelper { print(FIND_DATA, sb.toString()); Cursor cursor = db.rawQuery(sb.toString(), null); List data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; - cursor.close(); + closeCursor(cursor); close(db); return data; } @@ -238,7 +239,7 @@ final class SqlHelper extends SQLiteOpenHelper { print(FIND_ALL_DATA, sb.toString()); Cursor cursor = db.rawQuery(sb.toString(), null); List data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; - cursor.close(); + closeCursor(cursor); close(db); return data; } @@ -394,7 +395,7 @@ final class SqlHelper extends SQLiteOpenHelper { } catch (Exception e) { e.printStackTrace(); } finally { - if (cursor != null) cursor.close(); + closeCursor(cursor); close(db); } return false; @@ -564,7 +565,7 @@ final class SqlHelper extends SQLiteOpenHelper { entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid")); entitys.add(entity); } - cursor.close(); + closeCursor(cursor); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { @@ -586,6 +587,16 @@ final class SqlHelper extends SQLiteOpenHelper { 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) { //if (db != null && db.isOpen()) db.close(); } diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index 7518d0d3..9ee5b60e 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -46,7 +46,6 @@ public class DownloadGroupActivity extends BaseActivity