use of com.uwetrottmann.seriesguide.backend.shows.model.ShowList in project SeriesGuide by UweTrottmann.
the class HexagonShowSync method downloadLegacyShows.
private boolean downloadLegacyShows(List<SgShow2CloudUpdate> updates, Set<Long> toUpdate, HashMap<Integer, SearchResult> toAdd, Map<Integer, Long> tmdbIdsToShowIds) {
String cursor = null;
boolean hasMoreShows = true;
while (hasMoreShows) {
// abort if connection is lost
if (!AndroidUtils.isNetworkConnected(context)) {
Timber.e("download: no network connection");
return false;
}
List<Show> legacyShows;
try {
// get service each time to check if auth was removed
Shows showsService = hexagonTools.getShowsService();
if (showsService == null) {
return false;
}
// use default server limit
Shows.Get request = showsService.get();
if (!TextUtils.isEmpty(cursor)) {
request.setCursor(cursor);
}
ShowList response = request.execute();
if (response == null) {
// If empty should send status 200 and empty list, so no body is a failure.
Timber.e("download: response was null");
return false;
}
legacyShows = response.getShows();
// check for more items
if (response.getCursor() != null) {
cursor = response.getCursor();
} else {
hasMoreShows = false;
}
} catch (IOException | IllegalArgumentException e) {
// Note: JSON parser may throw IllegalArgumentException.
Errors.logAndReportHexagon("get legacy shows", e);
return false;
}
if (legacyShows == null || legacyShows.size() == 0) {
// nothing to do here
break;
}
List<SgCloudShow> shows = mapLegacyShows(legacyShows);
if (shows == null) {
return false;
}
// append updates for received shows if there isn't one,
// or appends shows not added locally
appendShowUpdates(updates, toUpdate, toAdd, shows, tmdbIdsToShowIds, true);
}
return true;
}
Aggregations