use of com.uwetrottmann.trakt5.entities.BaseShow in project SeriesGuide by UweTrottmann.
the class TraktTools method processTraktShows.
private int processTraktShows(@NonNull List<BaseShow> remoteShows, @NonNull HashSet<Integer> localShows, boolean isInitialSync, Flag flag) {
HashMap<Integer, BaseShow> traktShows = buildTraktShowsMap(remoteShows);
int uploadedShowsCount = 0;
final ArrayList<ContentProviderOperation> batch = new ArrayList<>();
for (Integer localShow : localShows) {
if (traktShows.containsKey(localShow)) {
// show watched/collected on trakt
BaseShow traktShow = traktShows.get(localShow);
int result = processTraktSeasons(isInitialSync, localShow, traktShow, flag);
if (result < SUCCESS) {
// processing seasons failed, give up.
return result;
}
if (flag == Flag.WATCHED) {
updateLastWatchedTime(localShow, traktShow, batch);
}
} else {
// show not watched/collected on trakt
// check if this is because the show can not be tracked with trakt (yet)
// some shows only exist on TheTVDB, keep state local and maybe upload in the future
Integer showTraktId = ShowTools.getShowTraktId(context, localShow);
if (showTraktId != null) {
if (isInitialSync) {
// upload all watched/collected episodes of the show
// do in between processing to stretch uploads over longer time periods
uploadEpisodes(localShow, showTraktId, flag);
uploadedShowsCount++;
} else {
// set all watched/collected episodes of show not watched/collected
batch.add(ContentProviderOperation.newUpdate(SeriesGuideContract.Episodes.buildEpisodesOfShowUri(localShow)).withSelection(flag.clearFlagSelection, null).withValue(flag.databaseColumn, flag.notFlaggedValue).build());
}
}
}
}
try {
DBUtils.applyInSmallBatches(context, batch);
} catch (OperationApplicationException e) {
Timber.e(e, "processTraktShows: failed to remove flag for %s.", flag.name);
}
if (uploadedShowsCount > 0) {
Timber.d("processTraktShows: uploaded %s flags for %s complete shows.", flag.name, localShows.size());
}
return SUCCESS;
}
Aggregations