Search in sources :

Example 31 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class MovieTools method loadSummaryFromTmdb.

@Nullable
private com.uwetrottmann.tmdb2.entities.Movie loadSummaryFromTmdb(@Nullable String languageCode, String regionCode, int movieTmdbId) {
    // try to get local movie summary
    Movie movie = getMovieSummary("get local movie summary", languageCode, movieTmdbId, true);
    if (movie != null && !TextUtils.isEmpty(movie.overview)) {
        movieTools2.updateReleaseDateForRegion(movie, movie.release_dates, regionCode);
        return movie;
    }
    // fall back to default language if TMDb has no localized text
    Movie movieFallback = getMovieSummary("get default movie summary", null, movieTmdbId, false);
    if (movieFallback != null) {
        // add note about non-translated or non-existing overview
        String untranslatedOverview = movieFallback.overview;
        movieFallback.overview = TextToolsK.textNoTranslationMovieLanguage(context, languageCode);
        if (!TextUtils.isEmpty(untranslatedOverview)) {
            movieFallback.overview += "\n\n" + untranslatedOverview;
        }
        if (movie != null) {
            movieTools2.updateReleaseDateForRegion(movie, movie.release_dates, regionCode);
        }
    }
    return movieFallback;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) Nullable(androidx.annotation.Nullable)

Example 32 with Movie

use of com.uwetrottmann.trakt5.entities.Movie in project SeriesGuide by UweTrottmann.

the class BaseRateItemTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToTrakt()) {
        if (!TraktCredentials.get(getContext()).hasCredentials()) {
            return ERROR_TRAKT_AUTH;
        }
        SyncItems ratedItems = buildTraktSyncItems();
        if (ratedItems == null) {
            return ERROR_TRAKT_API;
        }
        SyncErrors notFound;
        try {
            Sync traktSync = SgApp.getServicesComponent(getContext()).traktSync();
            Response<SyncResponse> response = traktSync.addRatings(ratedItems).execute();
            if (response.isSuccessful()) {
                notFound = response.body().not_found;
            } else {
                if (SgTrakt.isUnauthorized(getContext(), response)) {
                    return ERROR_TRAKT_AUTH;
                }
                Errors.logAndReport(getTraktAction(), response);
                return ERROR_TRAKT_API;
            }
        } catch (Exception e) {
            Errors.logAndReport(getTraktAction(), e);
            return ERROR_TRAKT_API;
        }
        if (notFound != null) {
            if ((notFound.movies != null && notFound.movies.size() != 0) || (notFound.shows != null && notFound.shows.size() != 0) || (notFound.episodes != null && notFound.episodes.size() != 0)) {
                // movie, show or episode not found on trakt
                return ERROR_TRAKT_API_NOT_FOUND;
            }
        }
    }
    if (!doDatabaseUpdate()) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) SyncErrors(com.uwetrottmann.trakt5.entities.SyncErrors) Sync(com.uwetrottmann.trakt5.services.Sync)

Aggregations

Movie (com.uwetrottmann.tmdb2.entities.Movie)14 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SyncMovie (com.uwetrottmann.trakt5.entities.SyncMovie)5 List (java.util.List)5 OperationApplicationException (android.content.OperationApplicationException)4 LinkedList (java.util.LinkedList)4 ContentProviderOperation (android.content.ContentProviderOperation)3 Nullable (androidx.annotation.Nullable)3 HistoryEntry (com.uwetrottmann.trakt5.entities.HistoryEntry)3 Intent (android.content.Intent)2 Nullable (android.support.annotation.Nullable)2 MovieDetails (com.battlelancer.seriesguide.ui.movies.MovieDetails)2 MovieList (com.uwetrottmann.seriesguide.backend.movies.model.MovieList)2 BaseMovie (com.uwetrottmann.trakt5.entities.BaseMovie)2 Comment (com.uwetrottmann.trakt5.entities.Comment)2 Episode (com.uwetrottmann.trakt5.entities.Episode)2 Friend (com.uwetrottmann.trakt5.entities.Friend)2 LastActivities (com.uwetrottmann.trakt5.entities.LastActivities)2 Ratings (com.uwetrottmann.trakt5.entities.Ratings)2