Search in sources :

Example 6 with Show

use of com.uwetrottmann.seriesguide.backend.shows.model.Show 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;
}
Also used : SgCloudShow(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow) Shows(com.uwetrottmann.seriesguide.backend.shows.Shows) SgCloudShow(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow) Show(com.uwetrottmann.seriesguide.backend.shows.model.Show) IOException(java.io.IOException) SgCloudShowList(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShowList) ShowList(com.uwetrottmann.seriesguide.backend.shows.model.ShowList)

Example 7 with Show

use of com.uwetrottmann.seriesguide.backend.shows.model.Show in project SeriesGuide by UweTrottmann.

the class HexagonShowSync method mapLegacyShows.

/**
 * Returns null on network error while looking up TMDB ID.
 */
@Nullable
private List<SgCloudShow> mapLegacyShows(List<Show> legacyShows) {
    List<SgCloudShow> shows = new ArrayList<>();
    for (Show legacyShow : legacyShows) {
        Integer showTvdbId = legacyShow.getTvdbId();
        if (showTvdbId == null || showTvdbId <= 0) {
            continue;
        }
        Integer showTmdbIdOrNull = new TmdbTools2().findShowTmdbId(context, showTvdbId);
        if (showTmdbIdOrNull == null) {
            // Network error, abort.
            return null;
        }
        // Only add if TMDB id found
        if (showTmdbIdOrNull != -1) {
            SgCloudShow show = new SgCloudShow();
            show.setTmdbId(showTmdbIdOrNull);
            show.setIsRemoved(legacyShow.getIsRemoved());
            show.setIsFavorite(legacyShow.getIsFavorite());
            show.setNotify(legacyShow.getNotify());
            show.setIsHidden(legacyShow.getIsHidden());
            show.setLanguage(legacyShow.getLanguage());
            shows.add(show);
        }
    }
    return shows;
}
Also used : SgCloudShow(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow) TmdbTools2(com.battlelancer.seriesguide.tmdbapi.TmdbTools2) ArrayList(java.util.ArrayList) SgCloudShow(com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow) Show(com.uwetrottmann.seriesguide.backend.shows.model.Show) Nullable(androidx.annotation.Nullable)

Aggregations

Show (com.uwetrottmann.seriesguide.backend.shows.model.Show)7 ContentValues (android.content.ContentValues)3 SgCloudShow (com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShow)2 Nullable (androidx.annotation.Nullable)1 TmdbTools2 (com.battlelancer.seriesguide.tmdbapi.TmdbTools2)1 Shows (com.uwetrottmann.seriesguide.backend.shows.Shows)1 SgCloudShowList (com.uwetrottmann.seriesguide.backend.shows.model.SgCloudShowList)1 ShowList (com.uwetrottmann.seriesguide.backend.shows.model.ShowList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1