diff options
author | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-31 12:21:58 +0200 |
---|---|---|
committer | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-31 12:21:58 +0200 |
commit | 278fbc224c0cbcb54b47791bbd0c91886e7abd50 (patch) | |
tree | fa5800d98c39c1341f3260793a2d3464e1abecab /src/de/podfetcher/service | |
parent | 7944ea0ba4c820f7be5a0be71256fbb5ed05e24c (diff) | |
download | AntennaPod-278fbc224c0cbcb54b47791bbd0c91886e7abd50.zip |
Added Downloads Activity
Diffstat (limited to 'src/de/podfetcher/service')
-rw-r--r-- | src/de/podfetcher/service/DownloadObserver.java | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/de/podfetcher/service/DownloadObserver.java b/src/de/podfetcher/service/DownloadObserver.java index 4920bfce8..e82e4efab 100644 --- a/src/de/podfetcher/service/DownloadObserver.java +++ b/src/de/podfetcher/service/DownloadObserver.java @@ -62,7 +62,7 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl if (status.done == false) { Cursor cursor = getDownloadCursor(status.feedfile); int statusId = getDownloadStatus(cursor, DownloadManager.COLUMN_STATUS); - status.progressPercent = getDownloadProgress(cursor); + getDownloadProgress(cursor, status); switch(statusId) { case DownloadManager.STATUS_SUCCESSFUL: status.statusMsg = R.string.download_successful; @@ -91,6 +91,7 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl Log.w(TAG, "Thread was interrupted while waiting."); } } + Log.d(TAG, "Background Task finished."); return Boolean.valueOf(true); } @@ -110,17 +111,16 @@ public class DownloadObserver extends AsyncTask<FeedFile, DownloadObserver.Downl } } - private int getDownloadProgress(Cursor c) { - if (c.moveToFirst()) { - long size = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); - long soFar = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); - int progress = (int) (((double) soFar / (double) size) * 100); - Log.d(TAG, "Setting progress to " + progress); - return progress; - } else { - return -1; - } - } + private void getDownloadProgress(Cursor c, DownloadStatus status) { + if (c.moveToFirst()) { + status.size = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); + status.soFar = c.getLong(c.getColumnIndex( + DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); + status.progressPercent = (int) (( + (double) status.soFar / (double) status.size) * 100); + Log.d(TAG, "Setting progress to " + status.progressPercent); + } + } private DownloadManager.Query buildQuery(long id) { DownloadManager.Query query = new DownloadManager.Query(); |