Support new episodes notification on local feeds (#7337)
This commit is contained in:
parent
02ec30e7e2
commit
c008c08e4f
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue