diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-03-03 11:24:24 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-03-17 18:35:41 +0100 |
commit | 4ba81f6c1453ecc93c3cd81462be53e0e37e6e07 (patch) | |
tree | e91cb90fc29fc029afdf30f530d57c1df4d62b69 /core/src/main | |
parent | a241c7aadc50c0aeff9173ce60d83878148a29b8 (diff) | |
download | AntennaPod-4ba81f6c1453ecc93c3cd81462be53e0e37e6e07.zip |
Only have one cursor open at the same time
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 68187306d..61a07ae2d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -590,17 +590,18 @@ public final class DBReader { FeedItem item = null; Cursor itemCursor = adapter.getFeedItemCursor(Long.toString(itemId)); - if (itemCursor.moveToFirst()) { - List<FeedItem> list = extractItemlistFromCursor(adapter, itemCursor); - if (list.size() > 0) { - item = list.get(0); - loadAdditionalFeedItemListData(list); - if (item.hasChapters()) { - loadChaptersOfFeedItem(adapter, item); - } - } + if (!itemCursor.moveToFirst()) { + return null; } + List<FeedItem> list = extractItemlistFromCursor(adapter, itemCursor); itemCursor.close(); + if (list.size() > 0) { + item = list.get(0); + loadAdditionalFeedItemListData(list); + if (item.hasChapters()) { + loadChaptersOfFeedItem(adapter, item); + } + } return item; } @@ -898,19 +899,23 @@ public final class DBReader { adapter.open(); Cursor mediaCursor = adapter.getSingleFeedMediaCursor(mediaId); - FeedMedia media = null; - if (mediaCursor.moveToFirst()) { - int indexFeedItem = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM); - final long itemId = mediaCursor.getLong(indexFeedItem); - media = FeedMedia.fromCursor(mediaCursor); + if (!mediaCursor.moveToFirst()) { + return null; + } + + int indexFeedItem = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM); + long itemId = mediaCursor.getLong(indexFeedItem); + FeedMedia media = FeedMedia.fromCursor(mediaCursor); + mediaCursor.close(); + + if(media != null) { FeedItem item = getFeedItem(itemId); - if (media != null && item != null) { + if (item != null) { media.setItem(item); item.setMedia(media); } } - mediaCursor.close(); adapter.close(); return media; |