Search in sources :

Example 1 with Movies

use of com.uwetrottmann.seriesguide.backend.movies.Movies 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)

Example 2 with Movies

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

the class HexagonTools method getMoviesService.

/**
     * Returns the instance for this hexagon service or null if not signed in.
     */
@Nullable
public synchronized Movies getMoviesService() {
    GoogleAccountCredential credential = getAccountCredential(true);
    if (credential.getSelectedAccount() == null) {
        return null;
    }
    if (moviesService == null) {
        Movies.Builder builder = new Movies.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential);
        moviesService = CloudEndpointUtils.updateBuilder(app, builder).build();
    }
    return moviesService;
}
Also used : GoogleAccountCredential(com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential) Movies(com.uwetrottmann.seriesguide.backend.movies.Movies) Nullable(android.support.annotation.Nullable)

Aggregations

Movies (com.uwetrottmann.seriesguide.backend.movies.Movies)2 Nullable (android.support.annotation.Nullable)1 GoogleAccountCredential (com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential)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