From b5244bbe99e423bfe5a2377728a086343a4c2fff Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 10:55:08 -0500 Subject: Add generatedBySystem to DownloadRequest --- .../core/service/download/DownloadRequest.java | 17 ++++++++++++---- .../core/storage/APDownloadAlgorithm.java | 2 +- .../de/danoeh/antennapod/core/storage/DBTasks.java | 15 +++++++------- .../antennapod/core/storage/DownloadRequester.java | 23 +++++++++++----------- 4 files changed, 34 insertions(+), 23 deletions(-) (limited to 'core/src/main/java/de/danoeh') 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 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); } /** -- cgit v1.2.3