summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorNathan Mascitelli <mascitelli.nathan@gmail.com>2020-02-07 10:55:14 -0500
committerNathan Mascitelli <mascitelli.nathan@gmail.com>2020-03-22 16:25:04 -0400
commit71f57bda32b942320b564ad68d0919fab0a77378 (patch)
treee6131eb2c6dd2f67f0c4353b721f18a64afe903f /core/src/main
parentbbc994fc9bf4e066e80af624ee4329f95ac8db4b (diff)
downloadAntennaPod-71f57bda32b942320b564ad68d0919fab0a77378.zip
Simplify constructors
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java96
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadStatus.java148
2 files changed, 145 insertions, 99 deletions
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