diff options
3 files changed, 146 insertions, 100 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java b/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java index 96fa641c6..301ceea6c 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java @@ -113,7 +113,7 @@ public class HttpDownloaderTest { public void testCancel() { final String url = httpServer.getBaseUrl() + "/delay/3"; FeedFileImpl feedFile = setupFeedFile(url, "delay", true); - final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt(), false)); + final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt(), null, null, true, null, false)); Thread t = new Thread() { @Override public void run() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java index 09ca15712..e1c727db5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java @@ -41,54 +41,76 @@ public class DownloadRequest implements Parcelable { boolean deleteOnFailure, Bundle arguments, boolean generatedBySystem) { + this(destination, + source, + title, + feedfileId, + feedfileType, + null, + deleteOnFailure, + username, + password, + false, + arguments, + generatedBySystem); + } + private DownloadRequest(Builder builder) { + this(builder.destination, + builder.source, + builder.title, + builder.feedfileId, + builder.feedfileType, + builder.lastModified, + builder.deleteOnFailure, + builder.username, + builder.password, + false, + (builder.arguments != null) ? builder.arguments : new Bundle(), + builder.generatedBySystem); + } + + private DownloadRequest(Parcel in) { + this(in.readString(), + in.readString(), + in.readString(), + in.readLong(), + in.readInt(), + in.readString(), + in.readByte() > 0, + nullIfEmpty(in.readString()), + nullIfEmpty(in.readString()), + in.readByte() > 0, + in.readBundle(), + in.readByte() > 0); + } + + private DownloadRequest(String destination, + String source, + String title, + long feedfileId, + int feedfileType, + String lastModified, + boolean deleteOnFailure, + String username, + String password, + boolean mediaEnqueued, + Bundle arguments, + boolean generatedBySystem) { this.destination = destination; this.source = source; this.title = title; this.feedfileId = feedfileId; this.feedfileType = feedfileType; + this.lastModified = lastModified; + this.deleteOnFailure = deleteOnFailure; this.username = username; this.password = password; - this.deleteOnFailure = deleteOnFailure; - this.mediaEnqueued = false; - this.arguments = (arguments != null) ? arguments : new Bundle(); + this.mediaEnqueued = mediaEnqueued; + this.arguments = arguments; this.generatedBySystem = generatedBySystem; } - public DownloadRequest(String destination, String source, String title, - long feedfileId, int feedfileType, boolean generatedBySystem) { - this(destination, source, title, feedfileId, feedfileType, null, null, true, null, generatedBySystem); - } - - private DownloadRequest(Builder builder) { - this.destination = builder.destination; - this.source = builder.source; - this.title = builder.title; - this.feedfileId = builder.feedfileId; - this.feedfileType = builder.feedfileType; - this.username = builder.username; - this.password = builder.password; - this.lastModified = builder.lastModified; - this.deleteOnFailure = builder.deleteOnFailure; - this.arguments = (builder.arguments != null) ? builder.arguments : new Bundle(); - this.generatedBySystem = builder.generatedBySystem; - } - - private DownloadRequest(Parcel in) { - destination = in.readString(); - source = in.readString(); - title = in.readString(); - feedfileId = in.readLong(); - feedfileType = in.readInt(); - lastModified = in.readString(); - deleteOnFailure = (in.readByte() > 0); - username = nullIfEmpty(in.readString()); - password = nullIfEmpty(in.readString()); - mediaEnqueued = (in.readByte() > 0); - arguments = in.readBundle(); - generatedBySystem = (in.readByte() > 0); - } - @Override public int describeContents() { return 0; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadStatus.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadStatus.java index 2ff4035c9..cefb95c1e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadStatus.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadStatus.java @@ -47,61 +47,64 @@ public class DownloadStatus { private boolean done; private boolean cancelled; - /** Constructor for restoring Download status entries from DB. */ - private DownloadStatus(long id, String title, long feedfileId, - int feedfileType, boolean successful, DownloadError reason, - Date completionDate, String reasonDetailed, boolean generatedBySystem) { - this.id = id; - this.title = title; - this.done = true; - this.feedfileId = feedfileId; - this.reason = reason; - this.successful = successful; - this.completionDate = (Date) completionDate.clone(); - this.reasonDetailed = reasonDetailed; - this.feedfileType = feedfileType; - this.generatedBySystem = generatedBySystem; - } - - public DownloadStatus(@NonNull DownloadRequest request, DownloadError reason, - boolean successful, boolean cancelled, String reasonDetailed, boolean generatedBySystem) { - this.title = request.getTitle(); - this.feedfileId = request.getFeedfileId(); - this.feedfileType = request.getFeedfileType(); - this.reason = reason; - this.successful = successful; - this.cancelled = cancelled; - this.reasonDetailed = reasonDetailed; - this.completionDate = new Date(); - this.generatedBySystem = generatedBySystem; + public DownloadStatus(@NonNull DownloadRequest request, + DownloadError reason, + boolean successful, + boolean cancelled, + String reasonDetailed, + boolean generatedBySystem) { + this(0, + request.getTitle(), + request.getFeedfileId(), + request.getFeedfileType(), + successful, + cancelled, + false, + reason, + new Date(), + reasonDetailed, + generatedBySystem); } /** Constructor for creating new completed downloads. */ - public DownloadStatus(@NonNull FeedFile feedfile, String title, DownloadError reason, - boolean successful, String reasonDetailed, boolean generatedBySystem) { - this.title = title; - this.done = true; - this.feedfileId = feedfile.getId(); - this.feedfileType = feedfile.getTypeAsInt(); - this.reason = reason; - this.successful = successful; - this.completionDate = new Date(); - this.reasonDetailed = reasonDetailed; - this.generatedBySystem = generatedBySystem; + public DownloadStatus(@NonNull FeedFile feedfile, + String title, + DownloadError reason, + boolean successful, + String reasonDetailed, + boolean generatedBySystem) { + this(0, + title, + feedfile.getId(), + feedfile.getTypeAsInt(), + successful, + false, + true, + reason, + new Date(), + reasonDetailed, + generatedBySystem); } /** Constructor for creating new completed downloads. */ - public DownloadStatus(long feedfileId, int feedfileType, String title, - DownloadError reason, boolean successful, String reasonDetailed, boolean generatedBySystem) { - this.title = title; - this.done = true; - this.feedfileId = feedfileId; - this.feedfileType = feedfileType; - this.reason = reason; - this.successful = successful; - this.completionDate = new Date(); - this.reasonDetailed = reasonDetailed; - this.generatedBySystem = generatedBySystem; + public DownloadStatus(long feedfileId, + int feedfileType, + String title, + DownloadError reason, + boolean successful, + String reasonDetailed, + boolean generatedBySystem) { + this(0, + title, + feedfileId, + feedfileType, + successful, + false, + true, + reason, + new Date(), + reasonDetailed, + generatedBySystem); } public static DownloadStatus fromCursor(Cursor cursor) { @@ -115,20 +118,41 @@ public class DownloadStatus { int indexReasonDetailed = cursor.getColumnIndex(PodDBAdapter.KEY_REASON_DETAILED); int indexGeneratedBySystem = cursor.getColumnIndex(PodDBAdapter.KEY_GENERATED_BY_SYSTEM); - long id = cursor.getLong(indexId); - String title = cursor.getString(indexTitle); - long feedfileId = cursor.getLong(indexFeedFile); - int feedfileType = cursor.getInt(indexFileFileType); - boolean successful = cursor.getInt(indexSuccessful) > 0; - int reason = cursor.getInt(indexReason); - Date completionDate = new Date(cursor.getLong(indexCompletionDate)); - String reasonDetailed = cursor.getString(indexReasonDetailed); - boolean generatedBySystem = cursor.getInt(indexGeneratedBySystem) > 0; - + return new DownloadStatus(cursor.getLong(indexId), + cursor.getString(indexTitle), + cursor.getLong(indexFeedFile), + cursor.getInt(indexFileFileType), + cursor.getInt(indexSuccessful) > 0, + false, + true, + DownloadError.fromCode(cursor.getInt(indexReason)), + new Date(cursor.getLong(indexCompletionDate)), + cursor.getString(indexReasonDetailed), + cursor.getInt(indexGeneratedBySystem) > 0); + } - return new DownloadStatus(id, title, feedfileId, - feedfileType, successful, DownloadError.fromCode(reason), completionDate, - reasonDetailed, generatedBySystem); + private DownloadStatus(long id, + String title, + long feedfileId, + int feedfileType, + boolean successful, + boolean cancelled, + boolean done, + DownloadError reason, + Date completionDate, + String reasonDetailed, + boolean generatedBySystem) { + this.id = id; + this.title = title; + this.feedfileId = feedfileId; + this.reason = reason; + this.successful = successful; + this.cancelled = cancelled; + this.done = done; + this.completionDate = (Date) completionDate.clone(); + this.reasonDetailed = reasonDetailed; + this.feedfileType = feedfileType; + this.generatedBySystem = generatedBySystem; } @Override |