Imageviews were not updating correctly

This commit is contained in:
daniel oeh 2012-08-11 22:19:08 +02:00
parent 5856c74e79
commit 86ef0f233e
2 changed files with 40 additions and 11 deletions

View File

@ -94,13 +94,15 @@ public class FeedlistFragment extends SherlockFragment implements
listView.setOnItemLongClickListener(this);
listView.setAdapter(fla);
listView.setEmptyView(txtvEmpty);
if (AppConfig.DEBUG) Log.d(TAG, "Using ListView");
if (AppConfig.DEBUG)
Log.d(TAG, "Using ListView");
} else {
gridView.setOnItemClickListener(this);
gridView.setOnItemLongClickListener(this);
gridView.setAdapter(fla);
gridView.setEmptyView(txtvEmpty);
if (AppConfig.DEBUG) Log.d(TAG, "Using GridView");
if (AppConfig.DEBUG)
Log.d(TAG, "Using GridView");
}
}
@ -113,7 +115,7 @@ public class FeedlistFragment extends SherlockFragment implements
filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
filter.addAction(FeedManager.ACITON_FEED_LIST_UPDATE);
filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
pActivity.registerReceiver(contentUpdate, filter);
fla.notifyDataSetChanged();
}
@ -129,15 +131,22 @@ public class FeedlistFragment extends SherlockFragment implements
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, final Intent intent) {
if (AppConfig.DEBUG)
Log.d(TAG, "Received contentUpdate Intent.");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fla.notifyDataSetChanged();
if (intent.getAction().equals(
DownloadService.ACTION_DOWNLOAD_HANDLED)) {
int type = intent.getIntExtra(DownloadService.EXTRA_DOWNLOAD_TYPE, 0);
if (type == DownloadService.DOWNLOAD_TYPE_IMAGE) {
fla.notifyDataSetChanged();
}
} else {
fla.notifyDataSetChanged();
}
}
});
}

View File

@ -68,6 +68,12 @@ public class DownloadService extends Service {
public static final String EXTRA_DOWNLOAD_ID = "extra.de.danoeh.antennapod.service.download_id";
public static final String EXTRA_IMAGE_DOWNLOAD_ID = "extra.de.danoeh.antennapod.service.image_download_id";
// Download types for ACTION_DOWNLOAD_HANDLED
public static final String EXTRA_DOWNLOAD_TYPE = "extra.de.danoeh.antennapod.service.downloadType";
public static final int DOWNLOAD_TYPE_FEED = 1;
public static final int DOWNLOAD_TYPE_MEDIA = 2;
public static final int DOWNLOAD_TYPE_IMAGE = 3;
private ArrayList<DownloadStatus> completedDownloads;
private ExecutorService syncExecutor;
@ -261,7 +267,7 @@ public class DownloadService extends Service {
reason, successful));
requester.removeDownload(download);
sendDownloadHandledIntent(download.getDownloadId(),
false, 0);
false, 0, getDownloadType(download));
download.setDownloadId(0);
}
@ -291,12 +297,26 @@ public class DownloadService extends Service {
completedDownloads.add(status);
manager.addDownloadStatus(this, status);
}
/** Returns correct value for EXTRA_DOWNLOAD_TYPE. */
private int getDownloadType(FeedFile f) {
if (f.getClass() == Feed.class) {
return DOWNLOAD_TYPE_FEED;
} else if (f.getClass() == FeedImage.class) {
return DOWNLOAD_TYPE_IMAGE;
} else if (f.getClass() == FeedMedia.class) {
return DOWNLOAD_TYPE_MEDIA;
} else {
return 0;
}
}
private void sendDownloadHandledIntent(long downloadId,
boolean feedHasImage, long imageDownloadId) {
boolean feedHasImage, long imageDownloadId, int type) {
Intent intent = new Intent(ACTION_DOWNLOAD_HANDLED);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
intent.putExtra(EXTRA_FEED_HAS_IMAGE, feedHasImage);
intent.putExtra(EXTRA_DOWNLOAD_TYPE, type);
if (feedHasImage) {
intent.putExtra(EXTRA_IMAGE_DOWNLOAD_ID, imageDownloadId);
}
@ -479,7 +499,7 @@ public class DownloadService extends Service {
savedFeed = feed;
}
saveDownloadStatus(new DownloadStatus(savedFeed, reason, successful));
sendDownloadHandledIntent(downloadId, hasImage, imageId);
sendDownloadHandledIntent(downloadId, hasImage, imageId, DOWNLOAD_TYPE_FEED);
queryDownloads();
}
@ -527,7 +547,7 @@ public class DownloadService extends Service {
requester.removeDownload(image);
saveDownloadStatus(new DownloadStatus(image, 0, true));
sendDownloadHandledIntent(image.getDownloadId(), false, 0);
sendDownloadHandledIntent(image.getDownloadId(), false, 0, DOWNLOAD_TYPE_IMAGE);
image.setDownloadId(0);
manager.setFeedImage(service, image);
if (image.getFeed() != null) {
@ -567,7 +587,7 @@ public class DownloadService extends Service {
Log.d(TAG, "Duration of file is " + media.getDuration());
mediaplayer.reset();
saveDownloadStatus(new DownloadStatus(media, 0, true));
sendDownloadHandledIntent(media.getDownloadId(), false, 0);
sendDownloadHandledIntent(media.getDownloadId(), false, 0, DOWNLOAD_TYPE_MEDIA);
media.setDownloadId(0);
manager.setFeedMedia(service, media);
boolean autoQueue = PreferenceManager.getDefaultSharedPreferences(