summaryrefslogtreecommitdiff
path: root/net/download/service-interface
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-03-17 20:25:44 +0100
committerGitHub <noreply@github.com>2024-03-17 20:25:44 +0100
commit2d77b1f11802da28cbcd87c9456bcc7ee3abf2a0 (patch)
tree7f54438ed59eee3272cd38dab79f8ebfe291e9e4 /net/download/service-interface
parentb84a05bd4e2bf2d10b7791155cc0a7a0e5aa3dcf (diff)
downloadAntennaPod-2d77b1f11802da28cbcd87c9456bcc7ee3abf2a0.zip
Remove dependency from :ui:glide to :core module (#6998)
Diffstat (limited to 'net/download/service-interface')
-rw-r--r--net/download/service-interface/build.gradle1
-rw-r--r--net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java297
-rw-r--r--net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java69
-rw-r--r--net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java (renamed from net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java)13
4 files changed, 77 insertions, 303 deletions
diff --git a/net/download/service-interface/build.gradle b/net/download/service-interface/build.gradle
index 784c1375f..84a8dfd05 100644
--- a/net/download/service-interface/build.gradle
+++ b/net/download/service-interface/build.gradle
@@ -3,6 +3,7 @@ plugins {
id("java-test-fixtures")
}
apply from: "../../../common.gradle"
+apply from: "../../../playFlavor.gradle"
android {
namespace "de.danoeh.antennapod.net.download.serviceinterface"
diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java
deleted file mode 100644
index f789fda5c..000000000
--- a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java
+++ /dev/null
@@ -1,297 +0,0 @@
-package de.danoeh.antennapod.net.download.serviceinterface;
-
-import android.os.Bundle;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.text.TextUtils;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import de.danoeh.antennapod.model.feed.Feed;
-import de.danoeh.antennapod.net.common.UrlChecker;
-import de.danoeh.antennapod.model.feed.FeedMedia;
-
-public class DownloadRequest implements Parcelable {
- public static final String REQUEST_ARG_PAGE_NR = "page";
-
- private final String destination;
- private final String source;
- private final String title;
- private String username;
- private String password;
- private String lastModified;
- private final long feedfileId;
- private final int feedfileType;
- private final Bundle arguments;
-
- private int progressPercent;
- private long soFar;
- private long size;
- private int statusMsg;
- private boolean mediaEnqueued;
- private boolean initiatedByUser;
-
- public DownloadRequest(@NonNull String destination, @NonNull String source, @NonNull String title, long feedfileId,
- int feedfileType, String username, String password,
- Bundle arguments, boolean initiatedByUser) {
- this(destination, source, title, feedfileId, feedfileType, null, username, password, false,
- arguments, initiatedByUser);
- }
-
- private DownloadRequest(Builder builder) {
- this(builder.destination, builder.source, builder.title, builder.feedfileId, builder.feedfileType,
- builder.lastModified, builder.username, builder.password, false,
- builder.arguments, builder.initiatedByUser);
- }
-
- private DownloadRequest(Parcel in) {
- this(in.readString(), in.readString(), in.readString(), in.readLong(), in.readInt(), in.readString(),
- 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, String username, String password,
- boolean mediaEnqueued, Bundle arguments, boolean initiatedByUser) {
- this.destination = destination;
- this.source = source;
- this.title = title;
- this.feedfileId = feedfileId;
- this.feedfileType = feedfileType;
- this.lastModified = lastModified;
- this.username = username;
- this.password = password;
- this.mediaEnqueued = mediaEnqueued;
- this.arguments = arguments;
- this.initiatedByUser = initiatedByUser;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(destination);
- dest.writeString(source);
- dest.writeString(title);
- dest.writeLong(feedfileId);
- dest.writeInt(feedfileType);
- dest.writeString(lastModified);
- // in case of null username/password, still write an empty string
- // (rather than skipping it). Otherwise, unmarshalling a collection
- // of them from a Parcel (from an Intent extra to submit a request to DownloadService) will fail.
- //
- // see: https://stackoverflow.com/a/22926342
- dest.writeString(nonNullString(username));
- dest.writeString(nonNullString(password));
- dest.writeByte((mediaEnqueued) ? (byte) 1 : 0);
- dest.writeBundle(arguments);
- dest.writeByte(initiatedByUser ? (byte) 1 : 0);
- }
-
- private static String nonNullString(String str) {
- return str != null ? str : "";
- }
-
- private static String nullIfEmpty(String str) {
- return TextUtils.isEmpty(str) ? null : str;
- }
-
- public static final Parcelable.Creator<DownloadRequest> CREATOR = new Parcelable.Creator<DownloadRequest>() {
- public DownloadRequest createFromParcel(Parcel in) {
- return new DownloadRequest(in);
- }
-
- public DownloadRequest[] newArray(int size) {
- return new DownloadRequest[size];
- }
- };
-
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof DownloadRequest)) return false;
-
- DownloadRequest that = (DownloadRequest) o;
-
- if (lastModified != null ? !lastModified.equals(that.lastModified) : that.lastModified != null)
- return false;
- if (feedfileId != that.feedfileId) return false;
- if (feedfileType != that.feedfileType) return false;
- if (progressPercent != that.progressPercent) return false;
- if (size != that.size) return false;
- if (soFar != that.soFar) return false;
- if (statusMsg != that.statusMsg) return false;
- if (!destination.equals(that.destination)) return false;
- if (password != null ? !password.equals(that.password) : that.password != null)
- return false;
- if (!source.equals(that.source)) return false;
- if (title != null ? !title.equals(that.title) : that.title != null) return false;
- if (username != null ? !username.equals(that.username) : that.username != null)
- return false;
- if (mediaEnqueued != that.mediaEnqueued) return false;
- if (initiatedByUser != that.initiatedByUser) return false;
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = destination.hashCode();
- result = 31 * result + source.hashCode();
- result = 31 * result + (title != null ? title.hashCode() : 0);
- result = 31 * result + (username != null ? username.hashCode() : 0);
- result = 31 * result + (password != null ? password.hashCode() : 0);
- result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0);
- result = 31 * result + (int) (feedfileId ^ (feedfileId >>> 32));
- result = 31 * result + feedfileType;
- result = 31 * result + arguments.hashCode();
- result = 31 * result + progressPercent;
- result = 31 * result + (int) (soFar ^ (soFar >>> 32));
- result = 31 * result + (int) (size ^ (size >>> 32));
- result = 31 * result + statusMsg;
- result = 31 * result + (mediaEnqueued ? 1 : 0);
- return result;
- }
-
- public String getDestination() {
- return destination;
- }
-
- public String getSource() {
- return source;
- }
-
- public String getTitle() {
- return title;
- }
-
- public long getFeedfileId() {
- return feedfileId;
- }
-
- public int getFeedfileType() {
- return feedfileType;
- }
-
- public int getProgressPercent() {
- return progressPercent;
- }
-
- public void setProgressPercent(int progressPercent) {
- this.progressPercent = progressPercent;
- }
-
- public long getSoFar() {
- return soFar;
- }
-
- public void setSoFar(long soFar) {
- this.soFar = soFar;
- }
-
- public long getSize() {
- return size;
- }
-
- public void setSize(long size) {
- this.size = size;
- }
-
- public void setStatusMsg(int statusMsg) {
- this.statusMsg = statusMsg;
- }
-
- public String getUsername() {
- return username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public DownloadRequest setLastModified(@Nullable String lastModified) {
- this.lastModified = lastModified;
- return this;
- }
-
- @Nullable
- public String getLastModified() {
- return lastModified;
- }
-
- public Bundle getArguments() {
- return arguments;
- }
-
- public static class Builder {
- private final String destination;
- private String source;
- private final String title;
- private String username;
- private String password;
- private String lastModified;
- private final long feedfileId;
- private final int feedfileType;
- private final Bundle arguments = new Bundle();
- private boolean initiatedByUser = true;
-
- public Builder(@NonNull String destination, @NonNull FeedMedia media) {
- this.destination = destination;
- this.source = UrlChecker.prepareUrl(media.getDownload_url());
- this.title = media.getHumanReadableIdentifier();
- this.feedfileId = media.getId();
- this.feedfileType = FeedMedia.FEEDFILETYPE_FEEDMEDIA;
- }
-
- public Builder(@NonNull String destination, @NonNull Feed feed) {
- this.destination = destination;
- this.source = feed.isLocalFeed() ? feed.getDownload_url() : UrlChecker.prepareUrl(feed.getDownload_url());
- this.title = feed.getHumanReadableIdentifier();
- this.feedfileId = feed.getId();
- this.feedfileType = Feed.FEEDFILETYPE_FEED;
- arguments.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr());
- }
-
- public Builder withInitiatedByUser(boolean initiatedByUser) {
- this.initiatedByUser = initiatedByUser;
- return this;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
- public void setForce(boolean force) {
- if (force) {
- lastModified = null;
- }
- }
-
- public Builder lastModified(String lastModified) {
- this.lastModified = lastModified;
- return this;
- }
-
- public Builder withAuthentication(String username, String password) {
- this.username = username;
- this.password = password;
- return this;
- }
-
- public DownloadRequest build() {
- return new DownloadRequest(this);
- }
- }
-}
diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java
new file mode 100644
index 000000000..15d2858bc
--- /dev/null
+++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java
@@ -0,0 +1,69 @@
+package de.danoeh.antennapod.net.download.serviceinterface;
+
+import android.os.Bundle;
+import androidx.annotation.NonNull;
+import de.danoeh.antennapod.model.download.DownloadRequest;
+import de.danoeh.antennapod.model.feed.Feed;
+import de.danoeh.antennapod.model.feed.FeedMedia;
+import de.danoeh.antennapod.net.common.UrlChecker;
+
+public class DownloadRequestBuilder {
+ private final String destination;
+ private String source;
+ private final String title;
+ private String username;
+ private String password;
+ private String lastModified;
+ private final long feedfileId;
+ private final int feedfileType;
+ private final Bundle arguments = new Bundle();
+ private boolean initiatedByUser = true;
+
+ public DownloadRequestBuilder(@NonNull String destination, @NonNull FeedMedia media) {
+ this.destination = destination;
+ this.source = UrlChecker.prepareUrl(media.getDownload_url());
+ this.title = media.getHumanReadableIdentifier();
+ this.feedfileId = media.getId();
+ this.feedfileType = FeedMedia.FEEDFILETYPE_FEEDMEDIA;
+ }
+
+ public DownloadRequestBuilder(@NonNull String destination, @NonNull Feed feed) {
+ this.destination = destination;
+ this.source = feed.isLocalFeed() ? feed.getDownload_url() : UrlChecker.prepareUrl(feed.getDownload_url());
+ this.title = feed.getHumanReadableIdentifier();
+ this.feedfileId = feed.getId();
+ this.feedfileType = Feed.FEEDFILETYPE_FEED;
+ arguments.putInt(DownloadRequest.REQUEST_ARG_PAGE_NR, feed.getPageNr());
+ }
+
+ public DownloadRequestBuilder withInitiatedByUser(boolean initiatedByUser) {
+ this.initiatedByUser = initiatedByUser;
+ return this;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public void setForce(boolean force) {
+ if (force) {
+ lastModified = null;
+ }
+ }
+
+ public DownloadRequestBuilder lastModified(String lastModified) {
+ this.lastModified = lastModified;
+ return this;
+ }
+
+ public DownloadRequestBuilder withAuthentication(String username, String password) {
+ this.username = username;
+ this.password = password;
+ return this;
+ }
+
+ public DownloadRequest build() {
+ return new DownloadRequest(destination, source, title, feedfileId, feedfileType,
+ lastModified, username, password, false, arguments, initiatedByUser);
+ }
+} \ No newline at end of file
diff --git a/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java b/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java
index a48934cfe..e9876a949 100644
--- a/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java
+++ b/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java
@@ -3,6 +3,7 @@ package de.danoeh.antennapod.net.download.serviceinterface;
import android.os.Bundle;
import android.os.Parcel;
+import de.danoeh.antennapod.model.download.DownloadRequest;
import de.danoeh.antennapod.model.feed.FeedMedia;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,7 +15,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@RunWith(RobolectricTestRunner.class)
-public class DownloadRequestTest {
+public class DownloadRequestBuilderTest {
@Test
public void parcelInArrayListTest_WithAuth() {
@@ -40,15 +41,15 @@ public class DownloadRequestTest {
String username = "testUser";
String password = "testPassword";
FeedMedia item = createFeedItem(1);
- DownloadRequest request1 = new DownloadRequest.Builder(destStr, item)
+ DownloadRequest request1 = new DownloadRequestBuilder(destStr, item)
.withAuthentication(username, password)
.build();
- DownloadRequest request2 = new DownloadRequest.Builder(destStr, item)
+ DownloadRequest request2 = new DownloadRequestBuilder(destStr, item)
.withAuthentication(username, password)
.build();
- DownloadRequest request3 = new DownloadRequest.Builder(destStr, item)
+ DownloadRequest request3 = new DownloadRequestBuilder(destStr, item)
.withAuthentication("diffUsername", "diffPassword")
.build();
@@ -65,12 +66,12 @@ public class DownloadRequestTest {
{ // test DownloadRequests to parcel
String destStr = "file://location/media.mp3";
FeedMedia item1 = createFeedItem(1);
- DownloadRequest request1 = new DownloadRequest.Builder(destStr, item1)
+ DownloadRequest request1 = new DownloadRequestBuilder(destStr, item1)
.withAuthentication(username1, password1)
.build();
FeedMedia item2 = createFeedItem(2);
- DownloadRequest request2 = new DownloadRequest.Builder(destStr, item2)
+ DownloadRequest request2 = new DownloadRequestBuilder(destStr, item2)
.withAuthentication(username2, password2)
.build();