From 94edf5d226b9602afde0b04ef73bd3a3cdc27f4b Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 22 Mar 2022 20:36:43 +0100 Subject: [PATCH] Ensure that download status is never null --- .../core/service/download/DownloadService.java | 2 +- .../core/service/download/handler/FeedParserTask.java | 4 ++++ .../core/service/download/handler/FeedSyncTask.java | 11 +++++------ .../download/handler/MediaDownloadedHandler.java | 5 ++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 917c45c14..8ea7e270e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -546,7 +546,7 @@ public class DownloadService extends Service { * * @param status the download that is going to be saved */ - private void saveDownloadStatus(DownloadStatus status) { + private void saveDownloadStatus(@NonNull DownloadStatus status) { reportQueue.add(status); DBWriter.addDownloadStatus(status); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java index 21d3452d6..125804669 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.core.service.download.handler; import android.util.Log; +import androidx.annotation.NonNull; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedPreferences; @@ -27,6 +28,8 @@ public class FeedParserTask implements Callable { public FeedParserTask(DownloadRequest request) { this.request = request; + downloadStatus = new DownloadStatus(request, DownloadError.ERROR_REQUEST_ERROR, + false, false, "Unknown error: Status not set"); } @Override @@ -108,6 +111,7 @@ public class FeedParserTask implements Callable { } } + @NonNull public DownloadStatus getDownloadStatus() { return downloadStatus; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java index 9760c57b1..57bcecf2e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.download.handler; import android.content.Context; +import androidx.annotation.NonNull; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadStatus; @@ -9,22 +10,19 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.parser.feed.FeedHandlerResult; public class FeedSyncTask { - private static final String TAG = "FeedParserTask"; private final DownloadRequest request; private final Context context; - private DownloadStatus downloadStatus; private Feed savedFeed; + private final FeedParserTask task; public FeedSyncTask(Context context, DownloadRequest request) { this.request = request; this.context = context; + this.task = new FeedParserTask(request); } public boolean run() { - FeedParserTask task = new FeedParserTask(request); FeedHandlerResult result = task.call(); - downloadStatus = task.getDownloadStatus(); - if (!task.isSuccessful()) { return false; } @@ -40,8 +38,9 @@ public class FeedSyncTask { return true; } + @NonNull public DownloadStatus getDownloadStatus() { - return downloadStatus; + return task.getDownloadStatus(); } public Feed getSavedFeed() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index 541e17cf6..f4f6c5a08 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -29,20 +29,18 @@ import de.danoeh.antennapod.net.sync.model.EpisodeAction; public class MediaDownloadedHandler implements Runnable { private static final String TAG = "MediaDownloadedHandler"; private final DownloadRequest request; - private final DownloadStatus status; private final Context context; private DownloadStatus updatedStatus; public MediaDownloadedHandler(@NonNull Context context, @NonNull DownloadStatus status, @NonNull DownloadRequest request) { - this.status = status; this.request = request; this.context = context; + this.updatedStatus = status; } @Override public void run() { - updatedStatus = status; FeedMedia media = DBReader.getFeedMedia(request.getFeedfileId()); if (media == null) { Log.e(TAG, "Could not find downloaded media object in database"); @@ -108,6 +106,7 @@ public class MediaDownloadedHandler implements Runnable { } } + @NonNull public DownloadStatus getUpdatedStatus() { return updatedStatus; }