summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-08-24 10:53:30 +0200
committerGitHub <noreply@github.com>2024-08-24 10:53:30 +0200
commitc008c08e4f648d69b34c1b7b96913fbc43481e1e (patch)
treeed057bf1c3e315e68cf8784d5a1b10352ff130e0
parent02ec30e7e225fb8892b2ad02633589f5f7259225 (diff)
downloadAntennaPod-c008c08e4f648d69b34c1b7b96913fbc43481e1e.zip
Support new episodes notification on local feeds (#7337)
-rw-r--r--net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/FeedUpdateWorker.java20
-rw-r--r--net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/local/LocalFeedUpdater.java13
2 files changed, 21 insertions, 12 deletions
diff --git a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/FeedUpdateWorker.java b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/FeedUpdateWorker.java
index b5174dfcb..fb0cb7e40 100644
--- a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/FeedUpdateWorker.java
+++ b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/FeedUpdateWorker.java
@@ -155,10 +155,14 @@ public class FeedUpdateWorker extends Worker {
return;
}
try {
+ Feed savedFeed;
if (feed.isLocalFeed()) {
- LocalFeedUpdater.updateFeed(feed, getApplicationContext(), null);
+ savedFeed = LocalFeedUpdater.updateFeed(feed, getApplicationContext(), null);
} else {
- refreshFeed(feed, force);
+ savedFeed = refreshFeed(feed, force);
+ }
+ if (savedFeed != null) {
+ newEpisodesNotification.showIfNeeded(getApplicationContext(), savedFeed);
}
} catch (Exception e) {
DBWriter.setFeedLastUpdateFailed(feed.getId(), true);
@@ -183,7 +187,7 @@ public class FeedUpdateWorker extends Worker {
}
}
- void refreshFeed(Feed feed, boolean force) throws Exception {
+ Feed refreshFeed(Feed feed, boolean force) throws Exception {
boolean nextPage = getInputData().getBoolean(FeedUpdateManagerImpl.EXTRA_NEXT_PAGE, false)
&& feed.getNextPageLink() != null;
if (nextPage) {
@@ -205,11 +209,11 @@ public class FeedUpdateWorker extends Worker {
if (!downloader.getResult().isSuccessful()) {
if (downloader.cancelled || downloader.getResult().getReason() == DownloadError.ERROR_DOWNLOAD_CANCELLED) {
- return;
+ return null;
}
DBWriter.setFeedLastUpdateFailed(request.getFeedfileId(), true);
DBWriter.addDownloadStatus(downloader.getResult());
- return;
+ return null;
}
FeedParserTask parserTask = new FeedParserTask(request);
@@ -217,25 +221,25 @@ public class FeedUpdateWorker extends Worker {
if (!parserTask.isSuccessful()) {
DBWriter.setFeedLastUpdateFailed(request.getFeedfileId(), true);
DBWriter.addDownloadStatus(parserTask.getDownloadStatus());
- return;
+ return null;
}
feedHandlerResult.feed.setLastRefreshAttempt(System.currentTimeMillis());
Feed savedFeed = FeedDatabaseWriter.updateFeed(getApplicationContext(), feedHandlerResult.feed, false);
if (request.getFeedfileId() == 0) {
- return; // No download logs for new subscriptions
+ return savedFeed; // No download logs for new subscriptions
}
// we create a 'successful' download log if the feed's last refresh failed
List<DownloadResult> log = DBReader.getFeedDownloadLog(request.getFeedfileId());
if (!log.isEmpty() && !log.get(0).isSuccessful()) {
DBWriter.addDownloadStatus(parserTask.getDownloadStatus());
}
- newEpisodesNotification.showIfNeeded(getApplicationContext(), savedFeed);
if (downloader.permanentRedirectUrl != null) {
DBWriter.updateFeedDownloadURL(request.getSource(), downloader.permanentRedirectUrl);
} else if (feedHandlerResult.redirectUrl != null
&& !feedHandlerResult.redirectUrl.equals(request.getSource())) {
DBWriter.updateFeedDownloadURL(request.getSource(), feedHandlerResult.redirectUrl);
}
+ return savedFeed;
}
}
diff --git a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/local/LocalFeedUpdater.java b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/local/LocalFeedUpdater.java
index 8cffcfc82..e5c4fea08 100644
--- a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/local/LocalFeedUpdater.java
+++ b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/local/LocalFeedUpdater.java
@@ -50,7 +50,7 @@ public class LocalFeedUpdater {
static final String[] PREFERRED_FEED_IMAGE_FILENAMES = {"folder.jpg", "Folder.jpg", "folder.png", "Folder.png"};
- public static void updateFeed(Feed feed, Context context,
+ public static Feed updateFeed(Feed feed, Context context,
@Nullable UpdaterProgressListener updaterProgressListener) {
try {
String uriString = feed.getDownloadUrl().replace(Feed.PREFIX_LOCAL_FOLDER, "");
@@ -63,24 +63,27 @@ public class LocalFeedUpdater {
throw new IOException("Cannot read local directory. "
+ "Try re-connecting the folder on the podcast info page.");
}
- tryUpdateFeed(feed, context, documentFolder.getUri(), updaterProgressListener);
+ Feed updatedFeed = tryUpdateFeed(feed, context, documentFolder.getUri(), updaterProgressListener);
if (mustReportDownloadSuccessful(feed)) {
reportSuccess(feed);
}
+ return updatedFeed;
} catch (Exception e) {
e.printStackTrace();
reportError(feed, e.getMessage());
}
+ return null;
}
@VisibleForTesting
- static void tryUpdateFeed(Feed feed, Context context, Uri folderUri,
+ static Feed tryUpdateFeed(Feed feed, Context context, Uri folderUri,
UpdaterProgressListener updaterProgressListener) throws IOException {
if (feed.getItems() == null) {
feed.setItems(new ArrayList<>());
}
- //make sure it is the latest 'version' of this feed from the db (all items etc)
+ // make sure it is the latest 'version' of this feed from the db (all items etc)
+ // and for new feeds, settings etc are set up properly.
feed = FeedDatabaseWriter.updateFeed(context, feed, false);
// list files in feed folder
@@ -127,6 +130,8 @@ public class LocalFeedUpdater {
feed.setAuthor(context.getString(R.string.local_folder));
FeedDatabaseWriter.updateFeed(context, feed, true);
+
+ return feed;
}
/**