Merge pull request #5810 from ByteHamster/ensure-status-nonnull

Ensure that download status is never null
This commit is contained in:
ByteHamster 2022-03-25 22:34:44 +01:00 committed by GitHub
commit 433314d1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View File

@ -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);
}

View File

@ -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<FeedHandlerResult> {
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<FeedHandlerResult> {
}
}
@NonNull
public DownloadStatus getDownloadStatus() {
return downloadStatus;
}

View File

@ -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() {

View File

@ -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;
}