summaryrefslogtreecommitdiff
path: root/core/src/main/java/de
diff options
context:
space:
mode:
authorNathan Mascitelli <mascitelli.nathan@gmail.com>2020-02-07 10:55:08 -0500
committerNathan Mascitelli <mascitelli.nathan@gmail.com>2020-03-22 16:19:31 -0400
commitb5244bbe99e423bfe5a2377728a086343a4c2fff (patch)
tree765d223effda62da812247c2ce71a471decd51b0 /core/src/main/java/de
parent3d7f93771afffb84655a249de173d70dbd895063 (diff)
downloadAntennaPod-b5244bbe99e423bfe5a2377728a086343a4c2fff.zip
Add generatedBySystem to DownloadRequest
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java17
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java15
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java23
4 files changed, 34 insertions, 23 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 2dd46cf96..90f4f0ff4 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
@@ -29,6 +29,7 @@ public class DownloadRequest implements Parcelable {
private long size;
private int statusMsg;
private boolean mediaEnqueued;
+ private boolean generatedBySystem;
public DownloadRequest(@NonNull String destination,
@NonNull String source,
@@ -38,7 +39,8 @@ public class DownloadRequest implements Parcelable {
String username,
String password,
boolean deleteOnFailure,
- Bundle arguments) {
+ Bundle arguments,
+ boolean generatedBySystem) {
this.destination = destination;
this.source = source;
@@ -50,11 +52,12 @@ public class DownloadRequest implements Parcelable {
this.deleteOnFailure = deleteOnFailure;
this.mediaEnqueued = false;
this.arguments = (arguments != null) ? arguments : new Bundle();
+ this.generatedBySystem = generatedBySystem;
}
public DownloadRequest(String destination, String source, String title,
- long feedfileId, int feedfileType) {
- this(destination, source, title, feedfileId, feedfileType, null, null, true, null);
+ long feedfileId, int feedfileType, boolean generatedBySystem) {
+ this(destination, source, title, feedfileId, feedfileType, null, null, true, null, generatedBySystem);
}
private DownloadRequest(Builder builder) {
@@ -68,6 +71,7 @@ public class DownloadRequest implements Parcelable {
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) {
@@ -82,6 +86,7 @@ public class DownloadRequest implements Parcelable {
password = nullIfEmpty(in.readString());
mediaEnqueued = (in.readByte() > 0);
arguments = in.readBundle();
+ generatedBySystem = (in.readByte() > 0);
}
@Override
@@ -107,6 +112,7 @@ public class DownloadRequest implements Parcelable {
dest.writeString(nonNullString(password));
dest.writeByte((mediaEnqueued) ? (byte) 1 : 0);
dest.writeBundle(arguments);
+ dest.writeByte(generatedBySystem ? (byte)1 : 0);
}
private static String nonNullString(String str) {
@@ -153,6 +159,7 @@ public class DownloadRequest implements Parcelable {
if (username != null ? !username.equals(that.username) : that.username != null)
return false;
if (mediaEnqueued != that.mediaEnqueued) return false;
+ if (generatedBySystem != that.generatedBySystem) return false;
return true;
}
@@ -281,13 +288,15 @@ public class DownloadRequest implements Parcelable {
private final long feedfileId;
private final int feedfileType;
private Bundle arguments;
+ private boolean generatedBySystem;
- public Builder(@NonNull String destination, @NonNull FeedFile item) {
+ public Builder(@NonNull String destination, @NonNull FeedFile item, boolean generatedBySystem) {
this.destination = destination;
this.source = URLChecker.prepareURL(item.getDownload_url());
this.title = item.getHumanReadableIdentifier();
this.feedfileId = item.getId();
this.feedfileType = item.getTypeAsInt();
+ this.generatedBySystem = generatedBySystem;
}
public Builder deleteOnFailure(boolean deleteOnFailure) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java
index 6e4054009..f0f4ed08d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java
@@ -92,7 +92,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
Log.d(TAG, "Enqueueing " + itemsToDownload.length + " items for download");
try {
- DownloadRequester.getInstance().downloadMedia(false, context, itemsToDownload);
+ DownloadRequester.getInstance().downloadMedia(false, context, true, itemsToDownload);
} catch (DownloadRequestException e) {
e.printStackTrace();
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
index 5b7e62964..9360f7c4b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
@@ -168,7 +168,7 @@ public final class DBTasks {
*/
public static void forceRefreshCompleteFeed(final Context context, final Feed feed) {
try {
- refreshFeed(context, feed, true, true);
+ refreshFeed(context, feed, true, true, true);
} catch (DownloadRequestException e) {
e.printStackTrace();
DBWriter.addDownloadStatus(
@@ -196,7 +196,8 @@ public final class DBTasks {
nextFeed.setPageNr(pageNr);
nextFeed.setPaged(true);
nextFeed.setId(feed.getId());
- DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false);
+ DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false, false
+ );
} else {
Log.e(TAG, "loadNextPageOfFeed: Feed was either not paged or contained no nextPageLink");
}
@@ -212,7 +213,7 @@ public final class DBTasks {
private static void refreshFeed(Context context, Feed feed)
throws DownloadRequestException {
Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")");
- refreshFeed(context, feed, false, false);
+ refreshFeed(context, feed, false, false, true);
}
/**
@@ -221,13 +222,13 @@ public final class DBTasks {
* @param context Used for requesting the download.
* @param feed The Feed object.
*/
- public static void forceRefreshFeed(Context context, Feed feed)
+ public static void forceRefreshFeed(Context context, Feed feed, boolean generatedBySystem)
throws DownloadRequestException {
Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")");
- refreshFeed(context, feed, false, true);
+ refreshFeed(context, feed, false, true, generatedBySystem);
}
- private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force)
+ private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force, boolean generatedBySystem)
throws DownloadRequestException {
Feed f;
String lastUpdate = feed.hasLastUpdateFailed() ? null : feed.getLastUpdate();
@@ -238,7 +239,7 @@ public final class DBTasks {
feed.getPreferences().getUsername(), feed.getPreferences().getPassword());
}
f.setId(feed.getId());
- DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force);
+ DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force, generatedBySystem);
}
/**
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
index 8bd9afe38..c91029040 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java
@@ -115,7 +115,7 @@ public class DownloadRequester implements DownloadStateProvider {
@Nullable
private DownloadRequest createRequest(FeedFile item, FeedFile container, File dest,
boolean overwriteIfExists, String username, String password,
- String lastModified, boolean deleteOnFailure, Bundle arguments) {
+ String lastModified, boolean deleteOnFailure, Bundle arguments, boolean generatedBySystem) {
final boolean partiallyDownloadedFileExists = item.getFile_url() != null && new File(item.getFile_url()).exists();
Log.d(TAG, "partiallyDownloadedFileExists: " + partiallyDownloadedFileExists);
@@ -156,7 +156,7 @@ public class DownloadRequester implements DownloadStateProvider {
String baseUrl = (container != null) ? container.getDownload_url() : null;
item.setDownload_url(URLChecker.prepareURL(item.getDownload_url(), baseUrl));
- DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item)
+ DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item, generatedBySystem)
.withAuthentication(username, password)
.lastModified(lastModified)
.deleteOnFailure(deleteOnFailure)
@@ -191,7 +191,7 @@ public class DownloadRequester implements DownloadStateProvider {
* @param loadAllPages Set to true to download all pages
*/
public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages,
- boolean force)
+ boolean force, boolean generatedBySystem)
throws DownloadRequestException {
if (feedFileValid(feed)) {
String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null;
@@ -203,7 +203,8 @@ public class DownloadRequester implements DownloadStateProvider {
args.putBoolean(REQUEST_ARG_LOAD_ALL_PAGES, loadAllPages);
DownloadRequest request = createRequest(feed, null, new File(getFeedfilePath(), getFeedfileName(feed)),
- true, username, password, lastModified, true, args);
+ true, username, password, lastModified, true, args, generatedBySystem
+ );
if (request != null) {
download(context, request);
}
@@ -211,17 +212,17 @@ public class DownloadRequester implements DownloadStateProvider {
}
public synchronized void downloadFeed(Context context, Feed feed) throws DownloadRequestException {
- downloadFeed(context, feed, false, false);
+ downloadFeed(context, feed, false, false, false);
}
- public synchronized void downloadMedia(@NonNull Context context, FeedItem... feedItems)
+ public synchronized void downloadMedia(@NonNull Context context, boolean generatedBySystem, FeedItem... feedItems)
throws DownloadRequestException {
- downloadMedia(true, context, feedItems);
+ downloadMedia(true, context, generatedBySystem, feedItems);
}
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
- public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context,
+ public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, boolean generatedBySystem,
FeedItem... items)
throws DownloadRequestException {
Log.d(TAG, "downloadMedia() called with: performAutoCleanup = [" + performAutoCleanup
@@ -230,7 +231,7 @@ public class DownloadRequester implements DownloadStateProvider {
List<DownloadRequest> requests = new ArrayList<>(items.length);
for (FeedItem item : items) {
try {
- DownloadRequest request = createRequest(item.getMedia());
+ DownloadRequest request = createRequest(item.getMedia(), generatedBySystem);
if (request != null) {
requests.add(request);
}
@@ -256,7 +257,7 @@ public class DownloadRequester implements DownloadStateProvider {
}
@Nullable
- private DownloadRequest createRequest(@Nullable FeedMedia feedmedia)
+ private DownloadRequest createRequest(@Nullable FeedMedia feedmedia, boolean generatedBySystem)
throws DownloadRequestException {
if (!feedFileValid(feedmedia)) {
return null;
@@ -279,7 +280,7 @@ public class DownloadRequester implements DownloadStateProvider {
dest = new File(getMediafilePath(feedmedia), getMediafilename(feedmedia));
}
return createRequest(feedmedia, feed,
- dest, false, username, password, null, false, null);
+ dest, false, username, password, null, false, null, generatedBySystem);
}
/**