bugfix: Ensure when media download completes and item update event is posted, the feed media has been updated,

This commit is contained in:
orionlee 2019-09-29 12:55:02 -07:00
parent 9469ebc6c3
commit 71de4607a3
2 changed files with 6 additions and 3 deletions

View File

@ -151,8 +151,8 @@ public class PlaybackServiceTaskManagerTest {
item.getMedia().setDownloaded(true);
item.getMedia().setFile_url("file://123");
item.setAutoDownload(false);
DBWriter.setFeedItem(item).get();
DBWriter.setFeedMedia(item.getMedia()).get();
DBWriter.setFeedItem(item).get();
}
// an approximation to ensure the item update event has been posted and processed.

View File

@ -997,14 +997,17 @@ public class DownloadService extends Service {
final FeedItem item = media.getItem();
try {
DBWriter.setFeedMedia(media).get();
// we've received the media, we don't want to autodownload it again
if (item != null) {
item.setAutoDownload(false);
// setFeedItem() signals (via EventBus) that the item has been updated,
// so we do it after the enclosing media has been updated above,
// to ensure subscribers will get the updated FeedMedia as well
DBWriter.setFeedItem(item).get();
}
DBWriter.setFeedMedia(media).get();
if (item != null && UserPreferences.enqueueDownloadedEpisodes() &&
!DBTasks.isInQueue(DownloadService.this, item.getId())) {
DBWriter.addQueueItem(DownloadService.this, item).get();