From 7088df944ceb23f2bbaa1eaeb93384c78adb4817 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Tue, 10 Jul 2012 16:45:48 +0200 Subject: Fixed issue in the downloadObserver class that could cause a crash --- src/de/podfetcher/activity/DownloadActivity.java | 3 +- src/de/podfetcher/asynctask/DownloadObserver.java | 74 ++++++++++++----------- 2 files changed, 40 insertions(+), 37 deletions(-) (limited to 'src/de') diff --git a/src/de/podfetcher/activity/DownloadActivity.java b/src/de/podfetcher/activity/DownloadActivity.java index c71c74743..dddda6f4a 100644 --- a/src/de/podfetcher/activity/DownloadActivity.java +++ b/src/de/podfetcher/activity/DownloadActivity.java @@ -179,7 +179,8 @@ public class DownloadActivity extends SherlockListActivity implements @Override public void onFinish() { + Log.d(TAG, "Observer has finished, clearing adapter"); dla.clear(); - dla.notifyDataSetChanged(); + dla.notifyDataSetInvalidated(); } } diff --git a/src/de/podfetcher/asynctask/DownloadObserver.java b/src/de/podfetcher/asynctask/DownloadObserver.java index 65d3e6129..9234539ef 100644 --- a/src/de/podfetcher/asynctask/DownloadObserver.java +++ b/src/de/podfetcher/asynctask/DownloadObserver.java @@ -50,8 +50,6 @@ public class DownloadObserver extends AsyncTask { callback.onFinish(); } } - - @Override protected void onPostExecute(Void result) { @@ -94,40 +92,43 @@ public class DownloadObserver extends AsyncTask { long downloadId = getDownloadStatus(cursor, DownloadManager.COLUMN_ID); FeedFile feedFile = requester.getFeedFile(downloadId); - DownloadStatus status = findDownloadStatus(feedFile); - if (status == null) { - status = new DownloadStatus(feedFile); - statusList.add(status); - } else { - unhandledItems.remove(status); - } - - // refresh status - int statusId = getDownloadStatus(cursor, - DownloadManager.COLUMN_STATUS); - getDownloadProgress(cursor, status); - switch (statusId) { - case DownloadManager.STATUS_SUCCESSFUL: - status.statusMsg = R.string.download_successful; - status.successful = true; - status.done = true; - case DownloadManager.STATUS_RUNNING: - status.statusMsg = R.string.download_running; - break; - case DownloadManager.STATUS_FAILED: - status.statusMsg = R.string.download_failed; - requester.notifyDownloadService(context); - status.successful = false; - status.done = true; - status.reason = getDownloadStatus(cursor, - DownloadManager.COLUMN_REASON); - case DownloadManager.STATUS_PENDING: - status.statusMsg = R.string.download_pending; - break; - default: - status.done = true; - status.successful = false; - status.statusMsg = R.string.download_cancelled_msg; + if (feedFile != null) { + DownloadStatus status = findDownloadStatus(feedFile); + + if (status == null) { + status = new DownloadStatus(feedFile); + statusList.add(status); + } else { + unhandledItems.remove(status); + } + + // refresh status + int statusId = getDownloadStatus(cursor, + DownloadManager.COLUMN_STATUS); + getDownloadProgress(cursor, status); + switch (statusId) { + case DownloadManager.STATUS_SUCCESSFUL: + status.statusMsg = R.string.download_successful; + status.successful = true; + status.done = true; + case DownloadManager.STATUS_RUNNING: + status.statusMsg = R.string.download_running; + break; + case DownloadManager.STATUS_FAILED: + status.statusMsg = R.string.download_failed; + requester.notifyDownloadService(context); + status.successful = false; + status.done = true; + status.reason = getDownloadStatus(cursor, + DownloadManager.COLUMN_REASON); + case DownloadManager.STATUS_PENDING: + status.statusMsg = R.string.download_pending; + break; + default: + status.done = true; + status.successful = false; + status.statusMsg = R.string.download_cancelled_msg; + } } } while (cursor.moveToNext()); } @@ -203,6 +204,7 @@ public class DownloadObserver extends AsyncTask { public interface Callback { public void onProgressUpdate(); + public void onFinish(); } -- cgit v1.2.3