summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2016-01-05 14:44:08 +0100
committerMartin Fietz <Martin.Fietz@gmail.com>2016-01-05 14:44:08 +0100
commite19c08de8a328bd08d069267235e989f0ef8f6d0 (patch)
tree38e5a0514281a8f644c48e2be9a3b11c2e5c03b1
parent3ba443a2d5d9acf1c3e2a3fde82d7b545795dd13 (diff)
parent2d2cf2f933207b0230dce14d9fdd95ed4ae6fba2 (diff)
downloadAntennaPod-e19c08de8a328bd08d069267235e989f0ef8f6d0.zip
Merge pull request #1526 from mfietz/issue/1522-download-log-NPE
Prevent DownloadLog NPE
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java16
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java7
3 files changed, 22 insertions, 6 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
index 9d7a509cf..582538fb8 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
@@ -134,12 +134,16 @@ public class DownloadLogAdapter extends BaseAdapter {
}
} else if(holder.typeId == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
FeedMedia media = DBReader.getFeedMedia(holder.id);
- try {
- DBTasks.downloadFeedItems(context, media.getItem());
- Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ if (media != null) {
+ try {
+ DBTasks.downloadFeedItems(context, media.getItem());
+ Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
+ }
+ } else {
+ Log.wtf(TAG, "Could not find media for id: " + holder.id);
}
} else {
Log.wtf(TAG, "Unexpected type id: " + holder.typeId);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
index 24519f10d..f74064cfc 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
@@ -223,6 +223,11 @@ public class DBWriter {
}
EventDistributor.getInstance().sendFeedUpdateBroadcast();
+ // we assume we also removed download log entries for the feed or its media files.
+ // especially important if download or refresh failed, as the user should not be able
+ // to retry these
+ EventDistributor.getInstance().sendDownloadLogUpdateBroadcast();
+
BackupManager backupManager = new BackupManager(context);
backupManager.dataChanged();
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index daff951df..3efdf403b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -886,6 +886,10 @@ public class PodDBAdapter {
}
public void removeFeedMedia(FeedMedia media) {
+ // delete download log entries for feed media
+ db.delete(TABLE_NAME_DOWNLOAD_LOG, KEY_FEEDFILE + "=? AND " + KEY_FEEDFILETYPE +"=?",
+ new String[] { String.valueOf(media.getId()), String.valueOf(FeedMedia.FEEDFILETYPE_FEEDMEDIA) });
+
db.delete(TABLE_NAME_FEED_MEDIA, KEY_ID + "=?",
new String[]{String.valueOf(media.getId())});
}
@@ -930,6 +934,9 @@ public class PodDBAdapter {
removeFeedItem(item);
}
}
+ // delete download log entries for feed
+ db.delete(TABLE_NAME_DOWNLOAD_LOG, KEY_FEEDFILE + "=? AND " + KEY_FEEDFILETYPE +"=?",
+ new String[] { String.valueOf(feed.getId()), String.valueOf(Feed.FEEDFILETYPE_FEED) });
db.delete(TABLE_NAME_FEEDS, KEY_ID + "=?",
new String[]{String.valueOf(feed.getId())});