Deleting a feed will now cancel running image and media downloads of

that feed
This commit is contained in:
daniel oeh 2012-08-11 13:12:47 +02:00
parent cd7c368287
commit 9d2a8a7750
2 changed files with 18 additions and 2 deletions

View File

@ -38,7 +38,7 @@ public class FeedManager {
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";
/** Number of completed Download status entries to store. */ /** Number of completed Download status entries to store. */
private static final int DOWNLOAD_LOG_SIZE = 25; private static final int DOWNLOAD_LOG_SIZE = 50;
private static FeedManager singleton; private static FeedManager singleton;
@ -131,14 +131,17 @@ public class FeedManager {
/** Remove a feed with all its items and media files and its image. */ /** Remove a feed with all its items and media files and its image. */
public void deleteFeed(final Context context, final Feed feed) { public void deleteFeed(final Context context, final Feed feed) {
PodDBAdapter adapter = new PodDBAdapter(context); PodDBAdapter adapter = new PodDBAdapter(context);
DownloadRequester requester = DownloadRequester.getInstance();
adapter.open(); adapter.open();
// delete image file // delete image file
if (feed.getImage() != null) { if (feed.getImage() != null) {
if (feed.getImage().isDownloaded() if (feed.getImage().isDownloaded()
&& feed.getImage().getFile_url() == null) { && feed.getImage().getFile_url() != null) {
File imageFile = new File(feed.getImage().getFile_url()); File imageFile = new File(feed.getImage().getFile_url());
imageFile.delete(); imageFile.delete();
} }
} else if (requester.isDownloadingFile(feed.getImage())) {
requester.cancelDownload(context, feed.getImage().getDownloadId());
} }
// delete stored media files and mark them as read // delete stored media files and mark them as read
for (FeedItem item : feed.getItems()) { for (FeedItem item : feed.getItems()) {
@ -151,6 +154,10 @@ public class FeedManager {
if (item.getMedia() != null && item.getMedia().isDownloaded()) { if (item.getMedia() != null && item.getMedia().isDownloaded()) {
File mediaFile = new File(item.getMedia().getFile_url()); File mediaFile = new File(item.getMedia().getFile_url());
mediaFile.delete(); mediaFile.delete();
} else if (item.getMedia() != null
&& requester.isDownloadingFile(item.getMedia())) {
requester.cancelDownload(context, item.getMedia()
.getDownloadId());
} }
} }

View File

@ -7,6 +7,7 @@ package de.danoeh.antennapod.service;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -115,6 +116,14 @@ public class DownloadService extends Service {
public Thread newThread(Runnable r) { public Thread newThread(Runnable r) {
Thread t = new Thread(r); Thread t = new Thread(r);
t.setPriority(Thread.MIN_PRIORITY); t.setPriority(Thread.MIN_PRIORITY);
t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, "Thread exited with uncaught exception");
ex.printStackTrace();
queryDownloads();
}});
return t; return t;
} }
}); });