use of com.battlelancer.seriesguide.provider.SgShow2Ids in project SeriesGuide by UweTrottmann.
the class HexagonSync method syncEpisodes.
private boolean syncEpisodes(@NonNull Map<Integer, Long> tmdbIdsToShowIds) {
// get shows that need episode merging
SgShow2Helper helper = SgRoomDatabase.getInstance(context).sgShow2Helper();
List<SgShow2Ids> showsToMerge = helper.getHexagonMergeNotCompleted();
// try merging episodes for them
boolean mergeSuccessful = true;
HexagonEpisodeSync episodeSync = new HexagonEpisodeSync(context, hexagonTools);
for (SgShow2Ids show : showsToMerge) {
// abort if connection is lost
if (!AndroidUtils.isNetworkConnected(context)) {
return false;
}
// TMDB ID is required, legacy shows with TVDB only data will no longer be synced.
Integer showTmdbId = show.getTmdbId();
if (showTmdbId == null || showTmdbId == 0)
continue;
boolean success = episodeSync.downloadFlags(show.getId(), showTmdbId, show.getTvdbId());
if (!success) {
// try again next time
mergeSuccessful = false;
continue;
}
success = episodeSync.uploadFlags(show.getId(), showTmdbId);
if (success) {
// set merge as completed
helper.setHexagonMergeCompleted(show.getId());
} else {
mergeSuccessful = false;
}
}
// download changed episodes and update properties on existing episodes
boolean changedDownloadSuccessful = episodeSync.downloadChangedFlags(tmdbIdsToShowIds);
return mergeSuccessful && changedDownloadSuccessful;
}
Aggregations