From 28784ab1bf4ddeedfa8157129fcdbf2ecad2d39d Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 17 Aug 2012 14:53:14 +0200 Subject: [PATCH] Fixed problems with the Downloadlog listadapter --- .../activity/DownloadLogActivity.java | 34 ++++++++++++++++++- .../danoeh/antennapod/feed/FeedManager.java | 29 ++++++++++++---- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java index 11a15accb..2c19b5649 100644 --- a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java +++ b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java @@ -1,5 +1,9 @@ package de.danoeh.antennapod.activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import com.actionbarsherlock.app.SherlockListActivity; @@ -9,7 +13,10 @@ import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.adapter.DownloadLogAdapter; import de.danoeh.antennapod.feed.FeedManager; -/** Displays completed and failed downloads in a list. The data comes from the FeedManager. */ +/** + * Displays completed and failed downloads in a list. The data comes from the + * FeedManager. + */ public class DownloadLogActivity extends SherlockListActivity { private static final String TAG = "DownloadLogActivity"; @@ -26,6 +33,20 @@ public class DownloadLogActivity extends SherlockListActivity { setListAdapter(dla); } + @Override + protected void onPause() { + super.onPause(); + unregisterReceiver(contentUpdate); + } + + @Override + protected void onResume() { + super.onResume(); + registerReceiver(contentUpdate, new IntentFilter( + FeedManager.ACTION_DOWNLOADLOG_UPDATE)); + dla.notifyDataSetChanged(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { return true; @@ -43,4 +64,15 @@ public class DownloadLogActivity extends SherlockListActivity { return true; } + private BroadcastReceiver contentUpdate = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction() + .equals(FeedManager.ACTION_DOWNLOADLOG_UPDATE)) { + dla.notifyDataSetChanged(); + } + } + }; + } diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index d49e73e0c..f0e119b64 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -37,6 +37,7 @@ public class FeedManager { public static final String ACITON_FEED_LIST_UPDATE = "de.danoeh.antennapod.action.feed.feedlistUpdate"; public static final String ACTION_UNREAD_ITEMS_UPDATE = "de.danoeh.antennapod.action.feed.unreadItemsUpdate"; public static final String ACTION_QUEUE_UPDATE = "de.danoeh.antennapod.action.feed.queueUpdate"; + public static final String ACTION_DOWNLOADLOG_UPDATE = "de.danoeh.antennapod.action.feed.downloadLogUpdate"; public static final String EXTRA_FEED_ITEM_ID = "de.danoeh.antennapod.extra.feed.feedItemId"; public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feed.feedId"; @@ -332,20 +333,34 @@ public class FeedManager { public void addDownloadStatus(final Context context, final DownloadStatus status) { - downloadLog.add(status); - dbExec.execute(new Runnable() { + contentChanger.post(new Runnable() { @Override public void run() { - PodDBAdapter adapter = new PodDBAdapter(context); - adapter.open(); + downloadLog.add(status); + final DownloadStatus removedStatus; if (downloadLog.size() > DOWNLOAD_LOG_SIZE) { - adapter.removeDownloadStatus(downloadLog.remove(0)); + removedStatus = downloadLog.remove(0); + } else { + removedStatus = null; } - adapter.setDownloadStatus(status); - adapter.close(); + context.sendBroadcast(new Intent(ACTION_DOWNLOADLOG_UPDATE)); + dbExec.execute(new Runnable() { + + @Override + public void run() { + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + if (removedStatus != null) { + adapter.removeDownloadStatus(removedStatus); + } + adapter.setDownloadStatus(status); + adapter.close(); + } + }); } }); + } public void addQueueItem(final Context context, final FeedItem item) {