DownloadService: media item might be null

This commit is contained in:
Martin Fietz 2015-12-15 16:36:15 +01:00
parent 755bdc5afb
commit 6113b932b4
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);
DBWriter.setFeedItem(item).get();
// update the db }
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,13 +1077,12 @@ 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() .build();
.build(); GpodnetPreferences.enqueueEpisodeAction(action);
GpodnetPreferences.enqueueEpisodeAction(action);
} }
numberOfDownloads.decrementAndGet(); numberOfDownloads.decrementAndGet();