Merge pull request #1475 from mfietz/issue/1473-NPE-downloadservice

DownloadService: media item might be null
This commit is contained in:
Tom Hennen 2015-12-20 09:03:50 -05:00
commit dd22e18d1d
1 changed files with 13 additions and 21 deletions

View File

@ -72,7 +72,6 @@ import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.syndication.handler.FeedHandler; import de.danoeh.antennapod.core.syndication.handler.FeedHandler;
import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult; import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult;
import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException; import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException;
import de.danoeh.antennapod.core.util.ChapterUtils;
import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.DownloadError;
import de.danoeh.antennapod.core.util.InvalidFeedException; import de.danoeh.antennapod.core.util.InvalidFeedException;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
@ -1032,7 +1031,6 @@ public class DownloadService extends Service {
throw new IllegalStateException( throw new IllegalStateException(
"Could not find downloaded media object in database"); "Could not find downloaded media object in database");
} }
boolean chaptersRead = false;
media.setDownloaded(true); media.setDownloaded(true);
media.setFile_url(request.getDestination()); media.setFile_url(request.getDestination());
media.setHasEmbeddedPicture(null); media.setHasEmbeddedPicture(null);
@ -1055,23 +1053,18 @@ public class DownloadService extends Service {
} }
} }
if (media.getItem().getChapters() == null) { final FeedItem item = media.getItem();
ChapterUtils.loadChaptersFromFileUrl(media);
if (media.getItem().getChapters() != null) {
chaptersRead = true;
}
}
try { try {
// we've received the media, we don't want to autodownload it again // we've received the media, we don't want to autodownload it again
FeedItem item = media.getItem(); if(item != null) {
item.setAutoDownload(false); item.setAutoDownload(false);
// update the db
DBWriter.setFeedItem(item).get(); DBWriter.setFeedItem(item).get();
}
DBWriter.setFeedMedia(media).get(); DBWriter.setFeedMedia(media).get();
if (!DBTasks.isInQueue(DownloadService.this, item.getId())) {
if (item != null && !DBTasks.isInQueue(DownloadService.this, item.getId())) {
DBWriter.addQueueItem(DownloadService.this, item).get(); DBWriter.addQueueItem(DownloadService.this, item).get();
} }
} catch (ExecutionException e) { } catch (ExecutionException e) {
@ -1084,8 +1077,7 @@ public class DownloadService extends Service {
saveDownloadStatus(status); saveDownloadStatus(status);
if(GpodnetPreferences.loggedIn()) { if(GpodnetPreferences.loggedIn() && item != null) {
FeedItem item = media.getItem();
GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, Action.DOWNLOAD) GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, Action.DOWNLOAD)
.currentDeviceId() .currentDeviceId()
.currentTimestamp() .currentTimestamp()