Fixed problems with the Downloadlog listadapter

This commit is contained in:
daniel oeh 2012-08-17 14:53:14 +02:00
parent 1057682860
commit 28784ab1bf
2 changed files with 55 additions and 8 deletions

View File

@ -1,5 +1,9 @@
package de.danoeh.antennapod.activity; 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 android.os.Bundle;
import com.actionbarsherlock.app.SherlockListActivity; import com.actionbarsherlock.app.SherlockListActivity;
@ -9,7 +13,10 @@ import com.actionbarsherlock.view.MenuItem;
import de.danoeh.antennapod.adapter.DownloadLogAdapter; import de.danoeh.antennapod.adapter.DownloadLogAdapter;
import de.danoeh.antennapod.feed.FeedManager; 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 { public class DownloadLogActivity extends SherlockListActivity {
private static final String TAG = "DownloadLogActivity"; private static final String TAG = "DownloadLogActivity";
@ -26,6 +33,20 @@ public class DownloadLogActivity extends SherlockListActivity {
setListAdapter(dla); 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 @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
return true; return true;
@ -43,4 +64,15 @@ public class DownloadLogActivity extends SherlockListActivity {
return true; 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();
}
}
};
} }

View File

@ -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 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_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_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_ITEM_ID = "de.danoeh.antennapod.extra.feed.feedItemId";
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feed.feedId"; public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feed.feedId";
@ -332,21 +333,35 @@ public class FeedManager {
public void addDownloadStatus(final Context context, public void addDownloadStatus(final Context context,
final DownloadStatus status) { final DownloadStatus status) {
contentChanger.post(new Runnable() {
@Override
public void run() {
downloadLog.add(status); downloadLog.add(status);
final DownloadStatus removedStatus;
if (downloadLog.size() > DOWNLOAD_LOG_SIZE) {
removedStatus = downloadLog.remove(0);
} else {
removedStatus = null;
}
context.sendBroadcast(new Intent(ACTION_DOWNLOADLOG_UPDATE));
dbExec.execute(new Runnable() { dbExec.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
PodDBAdapter adapter = new PodDBAdapter(context); PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open(); adapter.open();
if (downloadLog.size() > DOWNLOAD_LOG_SIZE) { if (removedStatus != null) {
adapter.removeDownloadStatus(downloadLog.remove(0)); adapter.removeDownloadStatus(removedStatus);
} }
adapter.setDownloadStatus(status); adapter.setDownloadStatus(status);
adapter.close(); adapter.close();
} }
}); });
} }
});
}
public void addQueueItem(final Context context, final FeedItem item) { public void addQueueItem(final Context context, final FeedItem item) {
contentChanger.post(new Runnable() { contentChanger.post(new Runnable() {