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;
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();
}
}
};
}

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 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) {