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') 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 From 895af777cf761aa0edba7b89dd04318ab6ede1d2 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 10:55:11 -0500 Subject: Add generatedBySystem to DownloadStatus --- .../core/service/download/DownloadRequest.java | 2 ++ .../core/service/download/DownloadStatus.java | 20 +++++++++++++++----- .../antennapod/core/service/download/Downloader.java | 2 +- .../service/download/handler/FeedParserTask.java | 8 ++++---- .../download/handler/MediaDownloadedHandler.java | 2 +- .../de/danoeh/antennapod/core/storage/DBTasks.java | 6 ++++-- .../antennapod/core/storage/DownloadRequester.java | 2 +- .../danoeh/antennapod/core/storage/PodDBAdapter.java | 1 + 8 files changed, 29 insertions(+), 14 deletions(-) (limited to 'core/src/main') 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 90f4f0ff4..09ca15712 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 @@ -265,6 +265,8 @@ public class DownloadRequest implements Parcelable { return mediaEnqueued; } + public boolean isGeneratedBySystem() { return generatedBySystem; } + /** * Set to true if the media is enqueued because of this download. * The state is helpful if the download is cancelled, and undoing the enqueue is needed. 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 675115bc7..2ff4035c9 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 @@ -41,6 +41,7 @@ public class DownloadStatus { * FEEDFILETYPE_FEEDIMAGE or FEEDFILETYPE_FEEDMEDIA */ private final int feedfileType; + private final boolean generatedBySystem; // ------------------------------------ NOT STORED IN DB private boolean done; @@ -49,7 +50,7 @@ public class DownloadStatus { /** 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) { + Date completionDate, String reasonDetailed, boolean generatedBySystem) { this.id = id; this.title = title; this.done = true; @@ -59,10 +60,11 @@ public class DownloadStatus { 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 successful, boolean cancelled, String reasonDetailed, boolean generatedBySystem) { this.title = request.getTitle(); this.feedfileId = request.getFeedfileId(); this.feedfileType = request.getFeedfileType(); @@ -71,11 +73,12 @@ public class DownloadStatus { this.cancelled = cancelled; this.reasonDetailed = reasonDetailed; this.completionDate = new Date(); + this.generatedBySystem = generatedBySystem; } /** Constructor for creating new completed downloads. */ public DownloadStatus(@NonNull FeedFile feedfile, String title, DownloadError reason, - boolean successful, String reasonDetailed) { + boolean successful, String reasonDetailed, boolean generatedBySystem) { this.title = title; this.done = true; this.feedfileId = feedfile.getId(); @@ -84,11 +87,12 @@ public class DownloadStatus { this.successful = successful; this.completionDate = new Date(); this.reasonDetailed = reasonDetailed; + this.generatedBySystem = generatedBySystem; } /** Constructor for creating new completed downloads. */ public DownloadStatus(long feedfileId, int feedfileType, String title, - DownloadError reason, boolean successful, String reasonDetailed) { + DownloadError reason, boolean successful, String reasonDetailed, boolean generatedBySystem) { this.title = title; this.done = true; this.feedfileId = feedfileId; @@ -97,6 +101,7 @@ public class DownloadStatus { this.successful = successful; this.completionDate = new Date(); this.reasonDetailed = reasonDetailed; + this.generatedBySystem = generatedBySystem; } public static DownloadStatus fromCursor(Cursor cursor) { @@ -108,6 +113,7 @@ public class DownloadStatus { int indexReason = cursor.getColumnIndex(PodDBAdapter.KEY_REASON); int indexCompletionDate = cursor.getColumnIndex(PodDBAdapter.KEY_COMPLETION_DATE); 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); @@ -117,10 +123,12 @@ public class DownloadStatus { 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(id, title, feedfileId, feedfileType, successful, DownloadError.fromCode(reason), completionDate, - reasonDetailed); + reasonDetailed, generatedBySystem); } @Override @@ -165,6 +173,8 @@ public class DownloadStatus { return feedfileType; } + public boolean isGeneratedBySystem() { return generatedBySystem; } + public boolean isDone() { return done; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java index 2a0989d23..f5bf0d1d1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java @@ -29,7 +29,7 @@ public abstract class Downloader implements Callable { this.request = request; this.request.setStatusMsg(R.string.download_pending); this.cancelled = false; - this.result = new DownloadStatus(request, null, false, false, null); + this.result = new DownloadStatus(request, null, false, false, null, request.isGeneratedBySystem()); } protected abstract void download(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java index c418db214..552fa3057 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java @@ -78,12 +78,12 @@ public class FeedParserTask implements Callable { } if (successful) { - downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), - DownloadError.SUCCESS, successful, reasonDetailed); + downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), DownloadError.SUCCESS, + successful, reasonDetailed, request.isGeneratedBySystem()); return result; } else { - downloadStatus = new DownloadStatus(feed, request.getTitle(), - reason, successful, reasonDetailed); + downloadStatus = new DownloadStatus(feed, request.getTitle(), reason, successful, reasonDetailed, + request.isGeneratedBySystem()); return null; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index 9ecabd14b..4379fe6de 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -96,7 +96,7 @@ public class MediaDownloadedHandler implements Runnable { } catch (ExecutionException e) { Log.e(TAG, "ExecutionException in MediaHandlerThread: " + e.getMessage()); updatedStatus = new DownloadStatus(media, media.getEpisodeTitle(), - DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage()); + DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), false); } if (GpodnetPreferences.loggedIn() && item != null) { 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 9360f7c4b..6c562b972 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 @@ -151,7 +151,8 @@ public final class DBTasks { new DownloadStatus(feed, feed .getHumanReadableIdentifier(), DownloadError.ERROR_REQUEST_ERROR, false, e - .getMessage() + .getMessage(), + true ) ); } @@ -175,7 +176,8 @@ public final class DBTasks { new DownloadStatus(feed, feed .getHumanReadableIdentifier(), DownloadError.ERROR_REQUEST_ERROR, false, e - .getMessage() + .getMessage(), + true ) ); } 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 c91029040..9b871da0d 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 @@ -247,7 +247,7 @@ public class DownloadRequester implements DownloadStateProvider { .getMedia() .getHumanReadableIdentifier(), DownloadError.ERROR_REQUEST_ERROR, - false, e.getMessage() + false, e.getMessage(), generatedBySystem ) ); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index af6a8ef81..f091874c6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -110,6 +110,7 @@ public class PodDBAdapter { public static final String KEY_INCLUDE_FILTER = "include_filter"; public static final String KEY_EXCLUDE_FILTER = "exclude_filter"; public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed"; + public static final String KEY_GENERATED_BY_SYSTEM = "generated_by_system"; // Table names static final String TABLE_NAME_FEEDS = "Feeds"; -- cgit v1.2.3 From 39e0d20ae7db2bf263ba02ebd9cfaccd5988a96f Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 10:55:12 -0500 Subject: Create report if download generated by system --- .../antennapod/core/service/download/DownloadServiceNotification.java | 4 +++- .../core/service/download/handler/MediaDownloadedHandler.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index f49257174..cf7bd6e35 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -108,9 +108,11 @@ public class DownloadServiceNotification { if (status.isSuccessful()) { successfulDownloads++; } else if (!status.isCancelled()) { - createReport = true; failedDownloads++; } + if (failedDownloads > 0 || status.isGeneratedBySystem() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { + createReport = true; + } } if (createReport) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index 4379fe6de..aec53207b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -96,7 +96,7 @@ public class MediaDownloadedHandler implements Runnable { } catch (ExecutionException e) { Log.e(TAG, "ExecutionException in MediaHandlerThread: " + e.getMessage()); updatedStatus = new DownloadStatus(media, media.getEpisodeTitle(), - DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), false); + DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), request.isGeneratedBySystem()); } if (GpodnetPreferences.loggedIn() && item != null) { -- cgit v1.2.3 From 1eaecf8358b3c5a9b946fa5283f6f60051dbc7b5 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 10:55:13 -0500 Subject: Add preferences --- .../java/de/danoeh/antennapod/core/preferences/UserPreferences.java | 5 +++++ .../de/danoeh/antennapod/core/service/download/DownloadService.java | 5 +++-- .../core/service/download/DownloadServiceNotification.java | 4 ++-- core/src/main/res/values/strings.xml | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index b2ea1fa62..f7b6ccb2a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -60,6 +60,7 @@ public class UserPreferences { public static final String PREF_COMPACT_NOTIFICATION_BUTTONS = "prefCompactNotificationButtons"; public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground"; private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport"; + private static final String PREF_SHOW_AUTO_DOWNLOAD_REPORT = "prefShowAutoDownloadReport"; public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior"; private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage"; @@ -292,6 +293,10 @@ public class UserPreferences { return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true); } + public static boolean showAutoDownloadReport() { + return prefs.getBoolean(PREF_SHOW_AUTO_DOWNLOAD_REPORT, false); + } + public static boolean enqueueDownloadedEpisodes() { return prefs.getBoolean(PREF_ENQUEUE_DOWNLOADED, true); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index d4177df46..ee34746fc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -205,9 +205,10 @@ public class DownloadService extends Service { Log.d(TAG, "Service shutting down"); isRunning = false; + boolean showAutoDownloadReport = UserPreferences.showAutoDownloadReport(); if (ClientConfig.downloadServiceCallbacks.shouldCreateReport() - && UserPreferences.showDownloadReport()) { - notificationManager.updateReport(reportQueue); + && (UserPreferences.showDownloadReport() || showAutoDownloadReport)) { + notificationManager.updateReport(reportQueue, showAutoDownloadReport); reportQueue.clear(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index cf7bd6e35..f83d30db0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -96,7 +96,7 @@ public class DownloadServiceNotification { * user about the number of completed downloads. A report will only be * created if there is at least one failed download excluding images */ - public void updateReport(List reportQueue) { + public void updateReport(List reportQueue, boolean showAutoDownloadReport) { // check if report should be created boolean createReport = false; int successfulDownloads = 0; @@ -110,7 +110,7 @@ public class DownloadServiceNotification { } else if (!status.isCancelled()) { failedDownloads++; } - if (failedDownloads > 0 || status.isGeneratedBySystem() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { + if (failedDownloads > 0 || showAutoDownloadReport && status.isGeneratedBySystem() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { createReport = true; } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index c65aed322..54b6a9f4d 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -470,6 +470,8 @@ Set the lockscreen background to the current episode\'s image. As a side effect, this will also show the image in third party apps. Show Download Report If downloads fail, generate a report that shows the details of the failure. + Show Auto Download Report + Generate a report that shows the details of auto downloaded episodes. Android versions before 4.1 do not support expanded notifications. Enqueue Location Add episodes to: %1$s -- cgit v1.2.3 From 71f57bda32b942320b564ad68d0919fab0a77378 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 10:55:14 -0500 Subject: Simplify constructors --- .../core/service/download/DownloadRequest.java | 96 +++++++------ .../core/service/download/DownloadStatus.java | 148 ++++++++++++--------- 2 files changed, 145 insertions(+), 99 deletions(-) (limited to 'core/src/main') 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 -- cgit v1.2.3 From 5d70a3cc38f561a95050fb552194d8b4ab4ef56d Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Fri, 7 Feb 2020 11:42:46 -0500 Subject: Rename generatedBySystem to initiatedByUser --- .../core/service/download/DownloadRequest.java | 24 ++++++------- .../download/DownloadServiceNotification.java | 2 +- .../core/service/download/DownloadStatus.java | 41 ++++++---------------- .../core/service/download/Downloader.java | 2 +- .../service/download/handler/FeedParserTask.java | 6 ++-- .../download/handler/MediaDownloadedHandler.java | 2 +- .../core/storage/APDownloadAlgorithm.java | 2 +- .../de/danoeh/antennapod/core/storage/DBTasks.java | 39 ++++++++++---------- .../antennapod/core/storage/DownloadRequester.java | 25 +++++++------ .../antennapod/core/storage/PodDBAdapter.java | 2 +- 10 files changed, 61 insertions(+), 84 deletions(-) (limited to 'core/src/main') 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 e1c727db5..9053f51bf 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,7 +29,7 @@ public class DownloadRequest implements Parcelable { private long size; private int statusMsg; private boolean mediaEnqueued; - private boolean generatedBySystem; + private boolean initiatedByUser; public DownloadRequest(@NonNull String destination, @NonNull String source, @@ -40,7 +40,7 @@ public class DownloadRequest implements Parcelable { String password, boolean deleteOnFailure, Bundle arguments, - boolean generatedBySystem) { + boolean initiatedByUser) { this(destination, source, title, @@ -52,7 +52,7 @@ public class DownloadRequest implements Parcelable { password, false, arguments, - generatedBySystem); + initiatedByUser); } private DownloadRequest(Builder builder) { @@ -67,7 +67,7 @@ public class DownloadRequest implements Parcelable { builder.password, false, (builder.arguments != null) ? builder.arguments : new Bundle(), - builder.generatedBySystem); + builder.initiatedByUser); } private DownloadRequest(Parcel in) { @@ -96,7 +96,7 @@ public class DownloadRequest implements Parcelable { String password, boolean mediaEnqueued, Bundle arguments, - boolean generatedBySystem) { + boolean initiatedByUser) { this.destination = destination; this.source = source; this.title = title; @@ -108,7 +108,7 @@ public class DownloadRequest implements Parcelable { this.password = password; this.mediaEnqueued = mediaEnqueued; this.arguments = arguments; - this.generatedBySystem = generatedBySystem; + this.initiatedByUser = initiatedByUser; } @Override @@ -134,7 +134,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); + dest.writeByte(initiatedByUser ? (byte)1 : 0); } private static String nonNullString(String str) { @@ -181,7 +181,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; + if (initiatedByUser != that.initiatedByUser) return false; return true; } @@ -287,7 +287,7 @@ public class DownloadRequest implements Parcelable { return mediaEnqueued; } - public boolean isGeneratedBySystem() { return generatedBySystem; } + public boolean isInitiatedByUser() { return initiatedByUser; } /** * Set to true if the media is enqueued because of this download. @@ -312,15 +312,15 @@ public class DownloadRequest implements Parcelable { private final long feedfileId; private final int feedfileType; private Bundle arguments; - private boolean generatedBySystem; + private boolean initiatedByUser; - public Builder(@NonNull String destination, @NonNull FeedFile item, boolean generatedBySystem) { + public Builder(@NonNull String destination, @NonNull FeedFile item, boolean initiatedByUser) { 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; + this.initiatedByUser = initiatedByUser; } public Builder deleteOnFailure(boolean deleteOnFailure) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index f83d30db0..ff6eb3c76 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -110,7 +110,7 @@ public class DownloadServiceNotification { } else if (!status.isCancelled()) { failedDownloads++; } - if (failedDownloads > 0 || showAutoDownloadReport && status.isGeneratedBySystem() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { + if (failedDownloads > 0 || showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { createReport = true; } } 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 cefb95c1e..78ac8ecea 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 @@ -41,7 +41,7 @@ public class DownloadStatus { * FEEDFILETYPE_FEEDIMAGE or FEEDFILETYPE_FEEDMEDIA */ private final int feedfileType; - private final boolean generatedBySystem; + private final boolean initiatedByUser; // ------------------------------------ NOT STORED IN DB private boolean done; @@ -52,7 +52,7 @@ public class DownloadStatus { boolean successful, boolean cancelled, String reasonDetailed, - boolean generatedBySystem) { + boolean initiatedByUser) { this(0, request.getTitle(), request.getFeedfileId(), @@ -63,7 +63,7 @@ public class DownloadStatus { reason, new Date(), reasonDetailed, - generatedBySystem); + initiatedByUser); } /** Constructor for creating new completed downloads. */ @@ -72,7 +72,7 @@ public class DownloadStatus { DownloadError reason, boolean successful, String reasonDetailed, - boolean generatedBySystem) { + boolean initiatedByUser) { this(0, title, feedfile.getId(), @@ -83,28 +83,7 @@ public class DownloadStatus { 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(0, - title, - feedfileId, - feedfileType, - successful, - false, - true, - reason, - new Date(), - reasonDetailed, - generatedBySystem); + initiatedByUser); } public static DownloadStatus fromCursor(Cursor cursor) { @@ -116,7 +95,7 @@ public class DownloadStatus { int indexReason = cursor.getColumnIndex(PodDBAdapter.KEY_REASON); int indexCompletionDate = cursor.getColumnIndex(PodDBAdapter.KEY_COMPLETION_DATE); int indexReasonDetailed = cursor.getColumnIndex(PodDBAdapter.KEY_REASON_DETAILED); - int indexGeneratedBySystem = cursor.getColumnIndex(PodDBAdapter.KEY_GENERATED_BY_SYSTEM); + int indexInitiatedByUser = cursor.getColumnIndex(PodDBAdapter.KEY_INITIATED_BY_USER); return new DownloadStatus(cursor.getLong(indexId), cursor.getString(indexTitle), @@ -128,7 +107,7 @@ public class DownloadStatus { DownloadError.fromCode(cursor.getInt(indexReason)), new Date(cursor.getLong(indexCompletionDate)), cursor.getString(indexReasonDetailed), - cursor.getInt(indexGeneratedBySystem) > 0); + cursor.getInt(indexInitiatedByUser) > 0); } private DownloadStatus(long id, @@ -141,7 +120,7 @@ public class DownloadStatus { DownloadError reason, Date completionDate, String reasonDetailed, - boolean generatedBySystem) { + boolean initiatedByUser) { this.id = id; this.title = title; this.feedfileId = feedfileId; @@ -152,7 +131,7 @@ public class DownloadStatus { this.completionDate = (Date) completionDate.clone(); this.reasonDetailed = reasonDetailed; this.feedfileType = feedfileType; - this.generatedBySystem = generatedBySystem; + this.initiatedByUser = initiatedByUser; } @Override @@ -197,7 +176,7 @@ public class DownloadStatus { return feedfileType; } - public boolean isGeneratedBySystem() { return generatedBySystem; } + public boolean isInitiatedByUser() { return initiatedByUser; } public boolean isDone() { return done; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java index f5bf0d1d1..51190a82a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java @@ -29,7 +29,7 @@ public abstract class Downloader implements Callable { this.request = request; this.request.setStatusMsg(R.string.download_pending); this.cancelled = false; - this.result = new DownloadStatus(request, null, false, false, null, request.isGeneratedBySystem()); + this.result = new DownloadStatus(request, null, false, false, null, request.isInitiatedByUser()); } protected abstract void download(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java index 552fa3057..6bb813c0e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java @@ -79,11 +79,11 @@ public class FeedParserTask implements Callable { if (successful) { downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), DownloadError.SUCCESS, - successful, reasonDetailed, request.isGeneratedBySystem()); + successful, reasonDetailed, request.isInitiatedByUser()); return result; } else { - downloadStatus = new DownloadStatus(feed, request.getTitle(), reason, successful, reasonDetailed, - request.isGeneratedBySystem()); + downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), reason, successful, + reasonDetailed, request.isInitiatedByUser()); return null; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index aec53207b..26a0e416e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -96,7 +96,7 @@ public class MediaDownloadedHandler implements Runnable { } catch (ExecutionException e) { Log.e(TAG, "ExecutionException in MediaHandlerThread: " + e.getMessage()); updatedStatus = new DownloadStatus(media, media.getEpisodeTitle(), - DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), request.isGeneratedBySystem()); + DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage(), request.isInitiatedByUser()); } if (GpodnetPreferences.loggedIn() && item != null) { 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 f0f4ed08d..7ec4db5dd 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, true, itemsToDownload); + DownloadRequester.getInstance().downloadMedia(false, context, false, 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 6c562b972..9bad98135 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 @@ -148,12 +148,12 @@ public final class DBTasks { } catch (DownloadRequestException e) { e.printStackTrace(); DBWriter.addDownloadStatus( - new DownloadStatus(feed, feed - .getHumanReadableIdentifier(), - DownloadError.ERROR_REQUEST_ERROR, false, e - .getMessage(), - true - ) + new DownloadStatus(feed, + feed.getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, + false, + e.getMessage(), + false) ); } } @@ -169,16 +169,16 @@ public final class DBTasks { */ public static void forceRefreshCompleteFeed(final Context context, final Feed feed) { try { - refreshFeed(context, feed, true, true, true); + refreshFeed(context, feed, true, true, false); } catch (DownloadRequestException e) { e.printStackTrace(); DBWriter.addDownloadStatus( - new DownloadStatus(feed, feed - .getHumanReadableIdentifier(), - DownloadError.ERROR_REQUEST_ERROR, false, e - .getMessage(), - true - ) + new DownloadStatus(feed, + feed.getHumanReadableIdentifier(), + DownloadError.ERROR_REQUEST_ERROR, + false, + e.getMessage(), + false) ); } } @@ -198,8 +198,7 @@ public final class DBTasks { nextFeed.setPageNr(pageNr); nextFeed.setPaged(true); nextFeed.setId(feed.getId()); - DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false, false - ); + DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false, true); } else { Log.e(TAG, "loadNextPageOfFeed: Feed was either not paged or contained no nextPageLink"); } @@ -215,7 +214,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, true); + refreshFeed(context, feed, false, false, false); } /** @@ -224,13 +223,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, boolean generatedBySystem) + public static void forceRefreshFeed(Context context, Feed feed, boolean initiatedByUser) throws DownloadRequestException { Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")"); - refreshFeed(context, feed, false, true, generatedBySystem); + refreshFeed(context, feed, false, true, initiatedByUser); } - private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force, boolean generatedBySystem) + private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force, boolean initiatedByUser) throws DownloadRequestException { Feed f; String lastUpdate = feed.hasLastUpdateFailed() ? null : feed.getLastUpdate(); @@ -241,7 +240,7 @@ public final class DBTasks { feed.getPreferences().getUsername(), feed.getPreferences().getPassword()); } f.setId(feed.getId()); - DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force, generatedBySystem); + DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force, initiatedByUser); } /** 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 9b871da0d..3a59976cf 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, boolean generatedBySystem) { + String lastModified, boolean deleteOnFailure, Bundle arguments, boolean initiatedByUser) { 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, generatedBySystem) + DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item, initiatedByUser) .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 generatedBySystem) + boolean force, boolean initiatedByUser) throws DownloadRequestException { if (feedFileValid(feed)) { String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null; @@ -203,7 +203,7 @@ 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, generatedBySystem + true, username, password, lastModified, true, args, initiatedByUser ); if (request != null) { download(context, request); @@ -212,17 +212,17 @@ public class DownloadRequester implements DownloadStateProvider { } public synchronized void downloadFeed(Context context, Feed feed) throws DownloadRequestException { - downloadFeed(context, feed, false, false, false); + downloadFeed(context, feed, false, false, true); } - public synchronized void downloadMedia(@NonNull Context context, boolean generatedBySystem, FeedItem... feedItems) + public synchronized void downloadMedia(@NonNull Context context, boolean initiatedByUser, FeedItem... feedItems) throws DownloadRequestException { - downloadMedia(true, context, generatedBySystem, feedItems); + downloadMedia(true, context, initiatedByUser, feedItems); } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) - public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, boolean generatedBySystem, + public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, boolean initiatedByUser, FeedItem... items) throws DownloadRequestException { Log.d(TAG, "downloadMedia() called with: performAutoCleanup = [" + performAutoCleanup @@ -231,7 +231,7 @@ public class DownloadRequester implements DownloadStateProvider { List requests = new ArrayList<>(items.length); for (FeedItem item : items) { try { - DownloadRequest request = createRequest(item.getMedia(), generatedBySystem); + DownloadRequest request = createRequest(item.getMedia(), initiatedByUser); if (request != null) { requests.add(request); } @@ -247,7 +247,7 @@ public class DownloadRequester implements DownloadStateProvider { .getMedia() .getHumanReadableIdentifier(), DownloadError.ERROR_REQUEST_ERROR, - false, e.getMessage(), generatedBySystem + false, e.getMessage(), initiatedByUser ) ); } @@ -257,7 +257,7 @@ public class DownloadRequester implements DownloadStateProvider { } @Nullable - private DownloadRequest createRequest(@Nullable FeedMedia feedmedia, boolean generatedBySystem) + private DownloadRequest createRequest(@Nullable FeedMedia feedmedia, boolean initiatedByUser) throws DownloadRequestException { if (!feedFileValid(feedmedia)) { return null; @@ -279,8 +279,7 @@ public class DownloadRequester implements DownloadStateProvider { } else { dest = new File(getMediafilePath(feedmedia), getMediafilename(feedmedia)); } - return createRequest(feedmedia, feed, - dest, false, username, password, null, false, null, generatedBySystem); + return createRequest(feedmedia, feed, dest, false, username, password, null, false, null, initiatedByUser); } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index f091874c6..a1ce183cc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -110,7 +110,7 @@ public class PodDBAdapter { public static final String KEY_INCLUDE_FILTER = "include_filter"; public static final String KEY_EXCLUDE_FILTER = "exclude_filter"; public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed"; - public static final String KEY_GENERATED_BY_SYSTEM = "generated_by_system"; + public static final String KEY_INITIATED_BY_USER = "initiated_by_user"; // Table names static final String TABLE_NAME_FEEDS = "Feeds"; -- cgit v1.2.3 From bd4631126d55aa91df2b83aebd5afa1e8ef0c841 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Mon, 10 Feb 2020 09:31:53 -0500 Subject: Updates based on QA feedback --- .../de/danoeh/antennapod/core/service/FeedUpdateWorker.java | 2 +- .../core/service/download/DownloadServiceNotification.java | 3 +-- .../antennapod/core/service/download/DownloadStatus.java | 5 ++--- .../danoeh/antennapod/core/service/download/Downloader.java | 2 +- .../main/java/de/danoeh/antennapod/core/storage/DBTasks.java | 11 +++++++---- .../antennapod/core/util/download/AutoUpdateManager.java | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java index 4443319e9..8811faf8a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java @@ -31,7 +31,7 @@ public class FeedUpdateWorker extends Worker { ClientConfig.initialize(getApplicationContext()); if (NetworkUtils.networkAvailable() && NetworkUtils.isFeedRefreshAllowed()) { - DBTasks.refreshAllFeeds(getApplicationContext()); + DBTasks.refreshAllFeeds(getApplicationContext(), false); } else { Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index ff6eb3c76..811b2374e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -107,10 +107,9 @@ public class DownloadServiceNotification { for (DownloadStatus status : reportQueue) { if (status.isSuccessful()) { successfulDownloads++; + createReport = createReport || showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA; } else if (!status.isCancelled()) { failedDownloads++; - } - if (failedDownloads > 0 || showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { createReport = true; } } 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 78ac8ecea..6b21dd58c 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 @@ -51,8 +51,7 @@ public class DownloadStatus { DownloadError reason, boolean successful, boolean cancelled, - String reasonDetailed, - boolean initiatedByUser) { + String reasonDetailed) { this(0, request.getTitle(), request.getFeedfileId(), @@ -63,7 +62,7 @@ public class DownloadStatus { reason, new Date(), reasonDetailed, - initiatedByUser); + request.isInitiatedByUser()); } /** Constructor for creating new completed downloads. */ diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java index 51190a82a..2a0989d23 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java @@ -29,7 +29,7 @@ public abstract class Downloader implements Callable { this.request = request; this.request.setStatusMsg(R.string.download_pending); this.cancelled = false; - this.result = new DownloadStatus(request, null, false, false, null, request.isInitiatedByUser()); + this.result = new DownloadStatus(request, null, false, false, null); } protected abstract void download(); 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 9bad98135..0695b1d04 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 @@ -105,8 +105,9 @@ public final class DBTasks { * enqueuing Feeds for download from a previous call * * @param context Might be used for accessing the database + * @param initiatedByUser a boolean indicating if the refresh was triggered by user action. */ - public static void refreshAllFeeds(final Context context) { + public static void refreshAllFeeds(final Context context, boolean initiatedByUser) { if (!isRefreshing.compareAndSet(false, true)) { Log.d(TAG, "Ignoring request to refresh all feeds: Refresh lock is locked"); return; @@ -116,7 +117,7 @@ public final class DBTasks { throw new IllegalStateException("DBTasks.refreshAllFeeds() must not be called from the main thread."); } - refreshFeeds(context, DBReader.getFeedList()); + refreshFeeds(context, DBReader.getFeedList(), initiatedByUser); isRefreshing.set(false); SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, MODE_PRIVATE); @@ -134,9 +135,11 @@ public final class DBTasks { /** * @param context * @param feedList the list of feeds to refresh + * @param initiatedByUser a boolean indicating if the refresh was triggered by user action. */ private static void refreshFeeds(final Context context, - final List feedList) { + final List feedList, + boolean initiatedByUser) { for (Feed feed : feedList) { FeedPreferences prefs = feed.getPreferences(); @@ -153,7 +156,7 @@ public final class DBTasks { DownloadError.ERROR_REQUEST_ERROR, false, e.getMessage(), - false) + initiatedByUser) ); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java index e093a7e00..fc04d82cc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java @@ -115,7 +115,7 @@ public class AutoUpdateManager { public static void runImmediate(@NonNull Context context) { Log.d(TAG, "Run auto update immediately in background."); new Thread(() -> { - DBTasks.refreshAllFeeds(context.getApplicationContext()); + DBTasks.refreshAllFeeds(context.getApplicationContext(), true); }, "ManualRefreshAllFeeds").start(); } -- cgit v1.2.3 From f7c520bc65c2c8c102f22c1a4d1e7eb5c7d8ad38 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Wed, 12 Feb 2020 08:24:05 -0500 Subject: Remove unused constant --- .../de/danoeh/antennapod/core/service/download/DownloadStatus.java | 3 +-- core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'core/src/main') 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 6b21dd58c..bdf98b7a3 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 @@ -94,7 +94,6 @@ public class DownloadStatus { int indexReason = cursor.getColumnIndex(PodDBAdapter.KEY_REASON); int indexCompletionDate = cursor.getColumnIndex(PodDBAdapter.KEY_COMPLETION_DATE); int indexReasonDetailed = cursor.getColumnIndex(PodDBAdapter.KEY_REASON_DETAILED); - int indexInitiatedByUser = cursor.getColumnIndex(PodDBAdapter.KEY_INITIATED_BY_USER); return new DownloadStatus(cursor.getLong(indexId), cursor.getString(indexTitle), @@ -106,7 +105,7 @@ public class DownloadStatus { DownloadError.fromCode(cursor.getInt(indexReason)), new Date(cursor.getLong(indexCompletionDate)), cursor.getString(indexReasonDetailed), - cursor.getInt(indexInitiatedByUser) > 0); + false); } private DownloadStatus(long id, diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index a1ce183cc..af6a8ef81 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -110,7 +110,6 @@ public class PodDBAdapter { public static final String KEY_INCLUDE_FILTER = "include_filter"; public static final String KEY_EXCLUDE_FILTER = "exclude_filter"; public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed"; - public static final String KEY_INITIATED_BY_USER = "initiated_by_user"; // Table names static final String TABLE_NAME_FEEDS = "Feeds"; -- cgit v1.2.3 From 7a93f1e513c3616cebd88567fc701578cef357f1 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Thu, 13 Feb 2020 08:40:47 -0500 Subject: Add new notification channel --- .../download/DownloadServiceNotification.java | 23 +++++++++++----------- .../core/util/gui/NotificationUtils.java | 12 +++++++++++ core/src/main/res/values/strings.xml | 4 +++- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 811b2374e..153effb57 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -116,20 +116,19 @@ public class DownloadServiceNotification { if (createReport) { Log.d(TAG, "Creating report"); + // create notification object - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, - NotificationUtils.CHANNEL_ID_ERROR) - .setTicker(context.getString(R.string.download_report_title)) - .setContentTitle(context.getString(R.string.download_report_content_title)) - .setContentText( - String.format( + boolean autoDownloadReport = failedDownloads == 0; + NotificationCompat.Builder builder = new NotificationCompat.Builder( + context, + autoDownloadReport ? NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD : NotificationUtils.CHANNEL_ID_ERROR); + builder.setTicker(context.getString(R.string.download_report_title)) + .setContentTitle(context.getString(R.string.download_report_content_title)) + .setContentText(String.format( context.getString(R.string.download_report_content), - successfulDownloads, failedDownloads) - ) - .setSmallIcon(R.drawable.stat_notify_sync_error) - .setContentIntent( - ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context) - ) + successfulDownloads, failedDownloads)) + .setSmallIcon(autoDownloadReport ? R.drawable.stat_notify_sync : R.drawable.stat_notify_sync_error) + .setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java index 02e98ba84..665d0fe79 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java @@ -14,6 +14,7 @@ public class NotificationUtils { public static final String CHANNEL_ID_DOWNLOADING = "downloading"; public static final String CHANNEL_ID_PLAYING = "playing"; public static final String CHANNEL_ID_ERROR = "error"; + public static final String CHANNEL_ID_AUTO_DOWNLOAD = "auto_download"; public static void createChannels(Context context) { if (android.os.Build.VERSION.SDK_INT < 26) { @@ -26,6 +27,7 @@ public class NotificationUtils { mNotificationManager.createNotificationChannel(createChannelDownloading(context)); mNotificationManager.createNotificationChannel(createChannelPlaying(context)); mNotificationManager.createNotificationChannel(createChannelError(context)); + mNotificationManager.createNotificationChannel(createChannelAutoDownload(context)); } } @@ -62,4 +64,14 @@ public class NotificationUtils { mChannel.setDescription(c.getString(R.string.notification_channel_error_description)); return mChannel; } + + @RequiresApi(api = Build.VERSION_CODES.O) + private static NotificationChannel createChannelAutoDownload(Context c) { + NotificationChannel mChannel = new NotificationChannel( + CHANNEL_ID_AUTO_DOWNLOAD, + c.getString(R.string.notification_channel_auto_download), + NotificationManager.IMPORTANCE_DEFAULT); + mChannel.setDescription(c.getString(R.string.notification_channel_downloading_description)); + return mChannel; + } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 54b6a9f4d..023bf0310 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -236,7 +236,7 @@ Forbidden Download canceled Download canceled\nDisabled Auto Download for this item - Downloads completed with error(s) + Downloads completed Download Report Malformed URL IO Error @@ -783,6 +783,8 @@ Allows to control playback. This is the main notification you see while playing a podcast. Errors Shown if something went wrong, for example if download or gpodder sync fails. + Auto Downloads + Shown when episodes are automatically downloaded. Widget settings -- cgit v1.2.3 From 576baf90d874834dc3c0c9d52e40a0882a5c9136 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Thu, 12 Mar 2020 15:49:25 -0400 Subject: Requested changes from review feedback --- .../core/service/download/DownloadRequest.java | 82 ++++++---------------- .../download/DownloadServiceNotification.java | 9 +-- .../core/service/download/DownloadStatus.java | 71 +++++-------------- .../antennapod/core/storage/DownloadRequester.java | 10 +-- core/src/main/res/values/strings.xml | 5 +- 5 files changed, 49 insertions(+), 128 deletions(-) (limited to 'core/src/main') 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 9053f51bf..78c4d3f48 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 @@ -31,72 +31,28 @@ public class DownloadRequest implements Parcelable { 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, - boolean deleteOnFailure, - Bundle arguments, - boolean initiatedByUser) { - this(destination, - source, - title, - feedfileId, - feedfileType, - null, - deleteOnFailure, - username, - password, - false, - arguments, - initiatedByUser); + public DownloadRequest(@NonNull String destination, @NonNull String source, @NonNull String title, long feedfileId, + int feedfileType, String username, String password, boolean deleteOnFailure, + Bundle arguments, boolean initiatedByUser) { + this(destination, source, title, feedfileId, feedfileType, null, deleteOnFailure, username, password, false, + arguments, initiatedByUser); } 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.initiatedByUser); + 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.initiatedByUser); } 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 initiatedByUser) { + 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 initiatedByUser) { this.destination = destination; this.source = source; this.title = title; @@ -134,7 +90,7 @@ public class DownloadRequest implements Parcelable { dest.writeString(nonNullString(password)); dest.writeByte((mediaEnqueued) ? (byte) 1 : 0); dest.writeBundle(arguments); - dest.writeByte(initiatedByUser ? (byte)1 : 0); + dest.writeByte(initiatedByUser ? (byte) 1 : 0); } private static String nonNullString(String str) { @@ -287,7 +243,9 @@ public class DownloadRequest implements Parcelable { return mediaEnqueued; } - public boolean isInitiatedByUser() { return initiatedByUser; } + public boolean isInitiatedByUser() { + return initiatedByUser; + } /** * Set to true if the media is enqueued because of this download. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 153effb57..7e8b53732 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -119,10 +119,11 @@ public class DownloadServiceNotification { // create notification object boolean autoDownloadReport = failedDownloads == 0; - NotificationCompat.Builder builder = new NotificationCompat.Builder( - context, - autoDownloadReport ? NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD : NotificationUtils.CHANNEL_ID_ERROR); - builder.setTicker(context.getString(R.string.download_report_title)) + String channelId = autoDownloadReport ? NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD : NotificationUtils.CHANNEL_ID_ERROR; + int titleId = autoDownloadReport ? R.string.auto_download_report_title : R.string.download_report_title; + + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); + builder.setTicker(context.getString(titleId)) .setContentTitle(context.getString(R.string.download_report_content_title)) .setContentText(String.format( context.getString(R.string.download_report_content), 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 bdf98b7a3..bad2ba1ef 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,42 +47,17 @@ public class DownloadStatus { private boolean done; private boolean cancelled; - public DownloadStatus(@NonNull DownloadRequest request, - DownloadError reason, - boolean successful, - boolean cancelled, - String reasonDetailed) { - this(0, - request.getTitle(), - request.getFeedfileId(), - request.getFeedfileType(), - successful, - cancelled, - false, - reason, - new Date(), - reasonDetailed, - request.isInitiatedByUser()); + public DownloadStatus(@NonNull DownloadRequest request, DownloadError reason, boolean successful, boolean cancelled, + String reasonDetailed) { + this(0, request.getTitle(), request.getFeedfileId(), request.getFeedfileType(), successful, cancelled, false, + reason, new Date(), reasonDetailed, request.isInitiatedByUser()); } /** Constructor for creating new completed downloads. */ - public DownloadStatus(@NonNull FeedFile feedfile, - String title, - DownloadError reason, - boolean successful, - String reasonDetailed, - boolean initiatedByUser) { - this(0, - title, - feedfile.getId(), - feedfile.getTypeAsInt(), - successful, - false, - true, - reason, - new Date(), - reasonDetailed, - initiatedByUser); + public DownloadStatus(@NonNull FeedFile feedfile, String title, DownloadError reason, boolean successful, + String reasonDetailed, boolean initiatedByUser) { + this(0, title, feedfile.getId(), feedfile.getTypeAsInt(), successful, false, true, reason, new Date(), + reasonDetailed, initiatedByUser); } public static DownloadStatus fromCursor(Cursor cursor) { @@ -95,30 +70,16 @@ public class DownloadStatus { int indexCompletionDate = cursor.getColumnIndex(PodDBAdapter.KEY_COMPLETION_DATE); int indexReasonDetailed = cursor.getColumnIndex(PodDBAdapter.KEY_REASON_DETAILED); - 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), - false); + 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), false); } - private DownloadStatus(long id, - String title, - long feedfileId, - int feedfileType, - boolean successful, - boolean cancelled, - boolean done, - DownloadError reason, - Date completionDate, - String reasonDetailed, - boolean initiatedByUser) { + private DownloadStatus(long id, String title, long feedfileId, int feedfileType, boolean successful, + boolean cancelled, boolean done, DownloadError reason, Date completionDate, + String reasonDetailed, boolean initiatedByUser) { this.id = id; this.title = title; this.feedfileId = feedfileId; 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 3a59976cf..6f9e6b056 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 @@ -113,9 +113,9 @@ 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, boolean initiatedByUser) { + private DownloadRequest createRequest(FeedFile item, FeedFile container, File dest, boolean overwriteIfExists, + String username, String password, String lastModified, + boolean deleteOnFailure, Bundle arguments, boolean initiatedByUser) { final boolean partiallyDownloadedFileExists = item.getFile_url() != null && new File(item.getFile_url()).exists(); Log.d(TAG, "partiallyDownloadedFileExists: " + partiallyDownloadedFileExists); @@ -222,8 +222,8 @@ public class DownloadRequester implements DownloadStateProvider { } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) - public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, boolean initiatedByUser, - FeedItem... items) + public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, + boolean initiatedByUser, FeedItem... items) throws DownloadRequestException { Log.d(TAG, "downloadMedia() called with: performAutoCleanup = [" + performAutoCleanup + "], #items = [" + items.length + "]"); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 023bf0310..3f0e62105 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -236,7 +236,8 @@ Forbidden Download canceled Download canceled\nDisabled Auto Download for this item - Downloads completed + Downloads completed with error(s) + Downloads completed Download Report Malformed URL IO Error @@ -784,7 +785,7 @@ Errors Shown if something went wrong, for example if download or gpodder sync fails. Auto Downloads - Shown when episodes are automatically downloaded. + Shown when episodes have been automatically downloaded. Widget settings -- cgit v1.2.3 From ad54ed3ec6685ade44e0238841569e0dd3187903 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Thu, 12 Mar 2020 15:56:56 -0400 Subject: Autodownload notification opens queue --- .../de/danoeh/antennapod/core/DownloadServiceCallbacks.java | 2 +- .../core/service/download/DownloadServiceNotification.java | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java index e56445489..4473d3ac7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java @@ -40,7 +40,7 @@ public interface DownloadServiceCallbacks { * * @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false */ - PendingIntent getReportNotificationContentIntent(Context context); + PendingIntent getReportNotificationContentIntent(Context context, boolean autoDownloadReport); /** * Called by the FeedSyncThread after a feed has been downloaded and parsed. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 7e8b53732..30c1c9773 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -125,12 +125,10 @@ public class DownloadServiceNotification { NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); builder.setTicker(context.getString(titleId)) .setContentTitle(context.getString(R.string.download_report_content_title)) - .setContentText(String.format( - context.getString(R.string.download_report_content), - successfulDownloads, failedDownloads)) - .setSmallIcon(autoDownloadReport ? R.drawable.stat_notify_sync : R.drawable.stat_notify_sync_error) - .setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context)) - .setAutoCancel(true); + .setContentText(String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads)) + .setSmallIcon(autoDownloadReport ? R.drawable.stat_notify_sync : R.drawable.stat_notify_sync_error) + .setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context, autoDownloadReport)) + .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); } -- cgit v1.2.3 From f82f9d702c90577737c2073f7bfc2ef64a6b9b7c Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Sun, 22 Mar 2020 16:15:27 -0400 Subject: Changes based on feedback --- .../antennapod/core/DownloadServiceCallbacks.java | 12 ++++++++- .../download/DownloadServiceNotification.java | 29 ++++++++++++++++------ .../service/download/handler/FeedParserTask.java | 2 +- .../core/util/gui/NotificationUtils.java | 8 +++--- core/src/main/res/values/strings.xml | 6 ++--- 5 files changed, 40 insertions(+), 17 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java index 4473d3ac7..1c5b1f928 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java @@ -40,7 +40,17 @@ public interface DownloadServiceCallbacks { * * @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false */ - PendingIntent getReportNotificationContentIntent(Context context, boolean autoDownloadReport); + PendingIntent getReportNotificationContentIntent(Context context); + + /** + * Returns a PendingIntent for notification that notifies the user about the episodes that have been automatically + * downloaded. + *

+ * The PendingIntent takes users to an activity where they can look at their episode queue. + * + * @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false + */ + PendingIntent getAutoDownloadReportNotificationContentIntent(Context context); /** * Called by the FeedSyncThread after a feed has been downloaded and parsed. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 30c1c9773..1b072486c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.download; import android.app.Notification; import android.app.NotificationManager; +import android.app.PendingIntent; import android.content.Context; import android.os.Build; import android.text.TextUtils; @@ -15,6 +16,7 @@ import de.danoeh.antennapod.core.util.gui.NotificationUtils; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentLinkedDeque; public class DownloadServiceNotification { private static final String TAG = "DownloadSvcNotification"; @@ -107,7 +109,7 @@ public class DownloadServiceNotification { for (DownloadStatus status : reportQueue) { if (status.isSuccessful()) { successfulDownloads++; - createReport = createReport || showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA; + createReport |= showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA; } else if (!status.isCancelled()) { failedDownloads++; createReport = true; @@ -118,16 +120,29 @@ public class DownloadServiceNotification { Log.d(TAG, "Creating report"); // create notification object - boolean autoDownloadReport = failedDownloads == 0; - String channelId = autoDownloadReport ? NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD : NotificationUtils.CHANNEL_ID_ERROR; - int titleId = autoDownloadReport ? R.string.auto_download_report_title : R.string.download_report_title; + String channelId; + int titleId; + int iconId; + PendingIntent intent; + if (failedDownloads == 0) { + // We are generating an auto-download report + channelId = NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD; + titleId = R.string.auto_download_report_title; + iconId = R.drawable.stat_notify_sync; + intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); + } else { + channelId = NotificationUtils.CHANNEL_ID_ERROR; + titleId = R.string.download_report_title; + iconId = R.drawable.stat_notify_sync_error; + intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); + } NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); builder.setTicker(context.getString(titleId)) - .setContentTitle(context.getString(R.string.download_report_content_title)) + .setContentTitle(context.getString(titleId)) .setContentText(String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads)) - .setSmallIcon(autoDownloadReport ? R.drawable.stat_notify_sync : R.drawable.stat_notify_sync_error) - .setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context, autoDownloadReport)) + .setSmallIcon(iconId) + .setContentIntent(intent) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java index 6bb813c0e..05e602db8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java @@ -82,7 +82,7 @@ public class FeedParserTask implements Callable { successful, reasonDetailed, request.isInitiatedByUser()); return result; } else { - downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), reason, successful, + downloadStatus = new DownloadStatus(feed, feed.getTitle(), reason, successful, reasonDetailed, request.isInitiatedByUser()); return null; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java index 665d0fe79..f546ca019 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java @@ -67,11 +67,9 @@ public class NotificationUtils { @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelAutoDownload(Context c) { - NotificationChannel mChannel = new NotificationChannel( - CHANNEL_ID_AUTO_DOWNLOAD, - c.getString(R.string.notification_channel_auto_download), - NotificationManager.IMPORTANCE_DEFAULT); - mChannel.setDescription(c.getString(R.string.notification_channel_downloading_description)); + NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_AUTO_DOWNLOAD, + c.getString(R.string.notification_channel_auto_download), NotificationManager.IMPORTANCE_DEFAULT); + mChannel.setDescription(c.getString(R.string.notification_channel_episode_auto_download)); return mChannel; } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 3f0e62105..2f80ac416 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -237,7 +237,7 @@ Download canceled Download canceled\nDisabled Auto Download for this item Downloads completed with error(s) - Downloads completed + Auto-downloads completed Download Report Malformed URL IO Error @@ -472,7 +472,7 @@ Show Download Report If downloads fail, generate a report that shows the details of the failure. Show Auto Download Report - Generate a report that shows the details of auto downloaded episodes. + Show a notification for automatically downloaded episodes. Android versions before 4.1 do not support expanded notifications. Enqueue Location Add episodes to: %1$s @@ -785,7 +785,7 @@ Errors Shown if something went wrong, for example if download or gpodder sync fails. Auto Downloads - Shown when episodes have been automatically downloaded. + Shown when episodes have been automatically downloaded. Widget settings -- cgit v1.2.3 From c2d87f57e584ebf4e85a1cf098da4ab6f224db58 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 24 Mar 2020 20:03:04 -0400 Subject: Use different ids --- .../core/service/download/DownloadServiceNotification.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 1b072486c..8f74147f5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -21,6 +21,7 @@ import java.util.concurrent.ConcurrentLinkedDeque; public class DownloadServiceNotification { private static final String TAG = "DownloadSvcNotification"; private static final int REPORT_ID = 3; + private static final int AUTO_REPORT_ID = 4; private final Context context; private NotificationCompat.Builder notificationCompatBuilder; @@ -123,6 +124,7 @@ public class DownloadServiceNotification { String channelId; int titleId; int iconId; + int id; PendingIntent intent; if (failedDownloads == 0) { // We are generating an auto-download report @@ -130,11 +132,13 @@ public class DownloadServiceNotification { titleId = R.string.auto_download_report_title; iconId = R.drawable.stat_notify_sync; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); + id = AUTO_REPORT_ID; } else { channelId = NotificationUtils.CHANNEL_ID_ERROR; titleId = R.string.download_report_title; iconId = R.drawable.stat_notify_sync_error; intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); + id = REPORT_ID; } NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); @@ -148,7 +152,7 @@ public class DownloadServiceNotification { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - nm.notify(REPORT_ID, builder.build()); + nm.notify(id, builder.build()); } else { Log.d(TAG, "No report is created"); } -- cgit v1.2.3 From 125fa3932e84b7b13c9994b07b82abc8656bd0f9 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 24 Mar 2020 20:48:35 -0400 Subject: List episodes that are downloaded --- .../download/DownloadServiceNotification.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 8f74147f5..8a1008f37 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -94,6 +94,20 @@ public class DownloadServiceNotification { return TextUtils.join("\n", lines); } + private static String createAutoDownloadNotificationContent(List statuses) { + int length = statuses.size(); + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < length; i++) { + sb.append("• ").append(statuses.get(i).getTitle()); + if (i != length - 1) { + sb.append("\n"); + } + } + + return sb.toString(); + } + /** * Creates a notification at the end of the service lifecycle to notify the * user about the number of completed downloads. A report will only be @@ -125,6 +139,7 @@ public class DownloadServiceNotification { int titleId; int iconId; int id; + String content; PendingIntent intent; if (failedDownloads == 0) { // We are generating an auto-download report @@ -133,18 +148,26 @@ public class DownloadServiceNotification { iconId = R.drawable.stat_notify_sync; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); id = AUTO_REPORT_ID; + StringBuilder sb = new StringBuilder(); + for (DownloadStatus status: reportQueue) { + sb.append("A"); + sb.append("\n"); + } + content = createAutoDownloadNotificationContent(reportQueue); } else { channelId = NotificationUtils.CHANNEL_ID_ERROR; titleId = R.string.download_report_title; iconId = R.drawable.stat_notify_sync_error; intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); id = REPORT_ID; + content = String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads); } NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); builder.setTicker(context.getString(titleId)) .setContentTitle(context.getString(titleId)) - .setContentText(String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads)) + .setContentText(content) + .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(iconId) .setContentIntent(intent) .setAutoCancel(true); -- cgit v1.2.3 From 9637734000d399ffaa8739f5a3f1c1624b2a6a37 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 24 Mar 2020 21:12:02 -0400 Subject: Add and use new icon --- .../core/service/download/DownloadServiceNotification.java | 2 +- core/src/main/res/drawable/auto_download_complete.xml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 core/src/main/res/drawable/auto_download_complete.xml (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 8a1008f37..b6a7cc89e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -145,7 +145,7 @@ public class DownloadServiceNotification { // We are generating an auto-download report channelId = NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD; titleId = R.string.auto_download_report_title; - iconId = R.drawable.stat_notify_sync; + iconId = R.drawable.auto_download_complete; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); id = AUTO_REPORT_ID; StringBuilder sb = new StringBuilder(); diff --git a/core/src/main/res/drawable/auto_download_complete.xml b/core/src/main/res/drawable/auto_download_complete.xml new file mode 100644 index 000000000..500d1e156 --- /dev/null +++ b/core/src/main/res/drawable/auto_download_complete.xml @@ -0,0 +1,9 @@ + + + -- cgit v1.2.3 From 13ca1a8dbc04958eda4a488642139972637f6d2f Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 26 Mar 2020 18:56:25 +0100 Subject: Removed unused StringBuilder --- .../core/service/download/DownloadServiceNotification.java | 6 ------ 1 file changed, 6 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index b6a7cc89e..b6f7e0b8f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -16,7 +16,6 @@ import de.danoeh.antennapod.core.util.gui.NotificationUtils; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ConcurrentLinkedDeque; public class DownloadServiceNotification { private static final String TAG = "DownloadSvcNotification"; @@ -148,11 +147,6 @@ public class DownloadServiceNotification { iconId = R.drawable.auto_download_complete; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); id = AUTO_REPORT_ID; - StringBuilder sb = new StringBuilder(); - for (DownloadStatus status: reportQueue) { - sb.append("A"); - sb.append("\n"); - } content = createAutoDownloadNotificationContent(reportQueue); } else { channelId = NotificationUtils.CHANNEL_ID_ERROR; -- cgit v1.2.3