From 503916be6d2227d35f9acf953a0cdc0eceedf252 Mon Sep 17 00:00:00 2001 From: Tianhua Ran Date: Fri, 9 Mar 2018 23:33:35 +0800 Subject: [PATCH] fix: correct variable names and add some useful notation --- .../liulishuo/filedownloader/database/RemitDatabase.java | 4 ++++ .../liulishuo/filedownloader/download/ConnectTask.java | 8 ++++---- .../filedownloader/download/DownloadRunnable.java | 2 +- .../liulishuo/filedownloader/download/FetchDataTask.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/liulishuo/filedownloader/database/RemitDatabase.java b/library/src/main/java/com/liulishuo/filedownloader/database/RemitDatabase.java index 7274b067..24a0b92c 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/database/RemitDatabase.java +++ b/library/src/main/java/com/liulishuo/filedownloader/database/RemitDatabase.java @@ -93,6 +93,10 @@ private void syncCacheToDB(int id) { FileDownloadLog.d(this, "sync cache to db %d", id); } + // need to attention that the `sofar` in `FileDownloadModel` database will + // be updated even through this is a multiple connections task. But the + // multi-connections task only concern about the `ConnectionModel` database, + // so it doesn't matter in current. realDatabase.update(cachedDatabase.find(id)); final List modelList = cachedDatabase.findConnectionModel(id); realDatabase.removeConnections(id); diff --git a/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java b/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java index d40b3933..392ca154 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java +++ b/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java @@ -57,18 +57,18 @@ private ConnectTask(ConnectionProfile profile, this.profile = profile; } - void updateConnectionProfile(long haveFinishedOffset) { - if (haveFinishedOffset == profile.currentOffset) { + void updateConnectionProfile(long downloadedOffset) { + if (downloadedOffset == profile.currentOffset) { if (FileDownloadLog.NEED_LOG) { FileDownloadLog.w(this, "no data download, no need to update"); } return; } final long newContentLength = - profile.contentLength - (haveFinishedOffset - profile.currentOffset); + profile.contentLength - (downloadedOffset - profile.currentOffset); profile = ConnectionProfile.ConnectionProfileBuild.buildConnectionProfile( profile.startOffset, - haveFinishedOffset, + downloadedOffset, profile.endOffset, newContentLength); if (FileDownloadLog.NEED_LOG) { diff --git a/library/src/main/java/com/liulishuo/filedownloader/download/DownloadRunnable.java b/library/src/main/java/com/liulishuo/filedownloader/download/DownloadRunnable.java index 5ce4a6f5..a092e119 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/download/DownloadRunnable.java +++ b/library/src/main/java/com/liulishuo/filedownloader/download/DownloadRunnable.java @@ -137,7 +137,7 @@ public void run() { //update currentOffset in ConnectionProfile final long downloadedOffset = getDownloadedOffset(); if (downloadedOffset > 0) { - connectTask.updateConnectionProfile(fetchDataTask.currentOffset); + connectTask.updateConnectionProfile(downloadedOffset); } } callback.onRetry(e); diff --git a/library/src/main/java/com/liulishuo/filedownloader/download/FetchDataTask.java b/library/src/main/java/com/liulishuo/filedownloader/download/FetchDataTask.java index cd915b4e..b92bc953 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/download/FetchDataTask.java +++ b/library/src/main/java/com/liulishuo/filedownloader/download/FetchDataTask.java @@ -93,7 +93,7 @@ public void run() throws IOException, IllegalAccessException, IllegalArgumentExc if (this.contentLength > 0 && contentLength != this.contentLength) { final String range; - if (endOffset <= 0) { + if (endOffset == ConnectionProfile.RANGE_INFINITE) { range = FileDownloadUtils.formatString("range[%d-)", currentOffset); } else { range = FileDownloadUtils.formatString("range[%d-%d)", currentOffset, endOffset);