use of com.battlelancer.seriesguide.provider.SgEpisode2ForSync in project SeriesGuide by UweTrottmann.
the class HexagonEpisodeSync method uploadFlags.
/**
* Uploads all watched, skipped including plays or collected episodes of this show to Hexagon.
*
* @return Whether the upload was successful.
*/
boolean uploadFlags(long showId, int showTmdbId) {
// query for watched, skipped or collected episodes
List<SgEpisode2ForSync> episodesForSync = SgRoomDatabase.getInstance(context).sgEpisode2Helper().getEpisodesForHexagonSync(showId);
if (episodesForSync.isEmpty()) {
Timber.d("uploadFlags: uploading none for show %d", showId);
return true;
} else {
// Issues with some requests failing at Cloud due to
// EOFException: Unexpected end of ZLIB input stream
// Using info log to report sizes that are uploaded to determine
// if MAX_BATCH_SIZE is actually too large.
// https://github.com/UweTrottmann/SeriesGuide/issues/781
Timber.i("uploadFlags: uploading %d for show %d", episodesForSync.size(), showId);
}
// build list of episodes to upload
List<SgCloudEpisode> episodes = new ArrayList<>();
int count = episodesForSync.size();
for (int i = 0; i < count; i++) {
SgEpisode2ForSync episodeForSync = episodesForSync.get(i);
SgCloudEpisode episode = new SgCloudEpisode();
episode.setSeasonNumber(episodeForSync.getSeason());
episode.setEpisodeNumber(episodeForSync.getNumber());
int watchedFlag = episodeForSync.getWatched();
if (!EpisodeTools.isUnwatched(watchedFlag)) {
// Skipped or watched.
episode.setWatchedFlag(watchedFlag);
episode.setPlays(episodeForSync.getPlays());
}
if (episodeForSync.getCollected()) {
episode.setIsInCollection(true);
}
episodes.add(episode);
// upload a batch
boolean isLast = i + 1 == count;
if (episodes.size() == MAX_BATCH_SIZE || isLast) {
SgCloudEpisodeList episodeList = new SgCloudEpisodeList();
episodeList.setEpisodes(episodes);
episodeList.setShowTmdbId(showTmdbId);
try {
// get service each time to check if auth was removed
Episodes episodesService = hexagonTools.getEpisodesService();
if (episodesService == null) {
return false;
}
episodesService.saveSgEpisodes(episodeList).execute();
} catch (IOException e) {
// abort
Errors.logAndReportHexagon("save episodes of show", e);
return false;
}
// clear array
episodes = new ArrayList<>();
}
}
return true;
}
Aggregations