Search in sources :

Example 1 with MovieList

use of com.uwetrottmann.seriesguide.backend.movies.model.MovieList in project SeriesGuide by UweTrottmann.

the class BaseMovieActionTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    // send to hexagon
    if (isSendingToHexagon()) {
        Movie movie = new Movie();
        movie.setTmdbId(movieTmdbId);
        setHexagonMovieProperties(movie);
        List<Movie> movies = new ArrayList<>();
        movies.add(movie);
        MovieList movieList = new MovieList();
        movieList.setMovies(movies);
        try {
            Movies moviesService = getContext().getHexagonTools().getMoviesService();
            if (moviesService == null) {
                return ERROR_HEXAGON_API;
            }
            moviesService.save(movieList).execute();
        } catch (IOException e) {
            HexagonTools.trackFailedRequest(getContext(), "save movie", e);
            return ERROR_HEXAGON_API;
        }
    }
    // send to trakt
    if (isSendingToTrakt()) {
        if (!TraktCredentials.get(getContext()).hasCredentials()) {
            return ERROR_TRAKT_AUTH;
        }
        SyncItems items = new SyncItems().movies(new SyncMovie().id(MovieIds.tmdb(movieTmdbId)));
        try {
            Response<SyncResponse> response = doTraktAction(traktSync.get(), items).execute();
            if (response.isSuccessful()) {
                if (isMovieNotFound(response.body())) {
                    return ERROR_TRAKT_API_NOT_FOUND;
                }
            } else {
                if (SgTrakt.isUnauthorized(getContext(), response)) {
                    return ERROR_TRAKT_AUTH;
                }
                SgTrakt.trackFailedRequest(getContext(), getTraktAction(), response);
                return ERROR_TRAKT_API;
            }
        } catch (IOException e) {
            SgTrakt.trackFailedRequest(getContext(), getTraktAction(), e);
            return ERROR_TRAKT_API;
        }
    }
    // update local state
    if (!doDatabaseUpdate(getContext(), movieTmdbId)) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movie(com.uwetrottmann.seriesguide.backend.movies.model.Movie) SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) ArrayList(java.util.ArrayList) MovieList(com.uwetrottmann.seriesguide.backend.movies.model.MovieList) SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movies(com.uwetrottmann.seriesguide.backend.movies.Movies) IOException(java.io.IOException)

Aggregations

Movies (com.uwetrottmann.seriesguide.backend.movies.Movies)1 Movie (com.uwetrottmann.seriesguide.backend.movies.model.Movie)1 MovieList (com.uwetrottmann.seriesguide.backend.movies.model.MovieList)1 SyncItems (com.uwetrottmann.trakt5.entities.SyncItems)1 SyncMovie (com.uwetrottmann.trakt5.entities.SyncMovie)1 SyncResponse (com.uwetrottmann.trakt5.entities.SyncResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1