Fixed issue in the downloadObserver class that could cause a crash

This commit is contained in:
daniel oeh 2012-07-10 16:45:48 +02:00
parent fc98cc8c79
commit 7088df944c
2 changed files with 39 additions and 36 deletions

View File

@ -179,7 +179,8 @@ public class DownloadActivity extends SherlockListActivity implements
@Override @Override
public void onFinish() { public void onFinish() {
Log.d(TAG, "Observer has finished, clearing adapter");
dla.clear(); dla.clear();
dla.notifyDataSetChanged(); dla.notifyDataSetInvalidated();
} }
} }

View File

@ -50,8 +50,6 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
callback.onFinish(); callback.onFinish();
} }
} }
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
@ -94,40 +92,43 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
long downloadId = getDownloadStatus(cursor, long downloadId = getDownloadStatus(cursor,
DownloadManager.COLUMN_ID); DownloadManager.COLUMN_ID);
FeedFile feedFile = requester.getFeedFile(downloadId); FeedFile feedFile = requester.getFeedFile(downloadId);
DownloadStatus status = findDownloadStatus(feedFile); if (feedFile != null) {
if (status == null) { DownloadStatus status = findDownloadStatus(feedFile);
status = new DownloadStatus(feedFile);
statusList.add(status);
} else {
unhandledItems.remove(status);
}
// refresh status if (status == null) {
int statusId = getDownloadStatus(cursor, status = new DownloadStatus(feedFile);
DownloadManager.COLUMN_STATUS); statusList.add(status);
getDownloadProgress(cursor, status); } else {
switch (statusId) { unhandledItems.remove(status);
case DownloadManager.STATUS_SUCCESSFUL: }
status.statusMsg = R.string.download_successful;
status.successful = true; // refresh status
status.done = true; int statusId = getDownloadStatus(cursor,
case DownloadManager.STATUS_RUNNING: DownloadManager.COLUMN_STATUS);
status.statusMsg = R.string.download_running; getDownloadProgress(cursor, status);
break; switch (statusId) {
case DownloadManager.STATUS_FAILED: case DownloadManager.STATUS_SUCCESSFUL:
status.statusMsg = R.string.download_failed; status.statusMsg = R.string.download_successful;
requester.notifyDownloadService(context); status.successful = true;
status.successful = false; status.done = true;
status.done = true; case DownloadManager.STATUS_RUNNING:
status.reason = getDownloadStatus(cursor, status.statusMsg = R.string.download_running;
DownloadManager.COLUMN_REASON); break;
case DownloadManager.STATUS_PENDING: case DownloadManager.STATUS_FAILED:
status.statusMsg = R.string.download_pending; status.statusMsg = R.string.download_failed;
break; requester.notifyDownloadService(context);
default: status.successful = false;
status.done = true; status.done = true;
status.successful = false; status.reason = getDownloadStatus(cursor,
status.statusMsg = R.string.download_cancelled_msg; 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()); } while (cursor.moveToNext());
} }
@ -203,6 +204,7 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
public interface Callback { public interface Callback {
public void onProgressUpdate(); public void onProgressUpdate();
public void onFinish(); public void onFinish();
} }