Search in sources :

Example 1 with Movie

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

the class MoviesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof MovieViewHolder) {
        MovieViewHolder actualHolder = (MovieViewHolder) holder;
        Movie movie = getMovie(position);
        actualHolder.movieTmdbId = movie.id;
        actualHolder.title.setText(movie.title);
        if (movie.release_date != null) {
            actualHolder.date.setText(dateFormatMovieReleaseDate.format(movie.release_date));
        } else {
            actualHolder.date.setText("");
        }
        // poster
        // use fixed size so bitmaps can be re-used on config change
        ServiceUtils.loadWithPicasso(context, posterBaseUrl + movie.poster_path).resizeDimen(R.dimen.movie_poster_width, R.dimen.movie_poster_height).centerCrop().into(actualHolder.poster);
        // set unique transition names
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            actualHolder.poster.setTransitionName(getTransitionNamePrefix() + movie.id);
        }
    }
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie)

Example 2 with Movie

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

the class TraktFriendsMovieHistoryLoader method loadInBackground.

@Override
public List<NowAdapter.NowItem> loadInBackground() {
    if (!TraktCredentials.get(getContext()).hasCredentials()) {
        return null;
    }
    // get all trakt friends
    List<Friend> friends = SgTrakt.executeAuthenticatedCall(getContext(), traktUsers.get().friends(UserSlug.ME, Extended.FULL), "get friends");
    if (friends == null) {
        return null;
    }
    int size = friends.size();
    if (size == 0) {
        // no friends, done.
        return null;
    }
    // estimate list size
    List<NowAdapter.NowItem> items = new ArrayList<>(size + 1);
    // add header
    items.add(new NowAdapter.NowItem().header(getContext().getString(R.string.friends_recently)));
    // add last watched movie for each friend
    for (int i = 0; i < size; i++) {
        Friend friend = friends.get(i);
        // at least need a userSlug
        if (friend.user == null) {
            continue;
        }
        String userSlug = friend.user.ids.slug;
        if (TextUtils.isEmpty(userSlug)) {
            continue;
        }
        // get last watched episode
        List<HistoryEntry> history = SgTrakt.executeCall(getContext(), traktUsers.get().history(new UserSlug(userSlug), HistoryType.MOVIES, 1, 1, Extended.DEFAULT_MIN, null, null), "get friend movie history");
        if (history == null || history.size() == 0) {
            // no history
            continue;
        }
        HistoryEntry entry = history.get(0);
        if (entry.watched_at == null || entry.movie == null) {
            // missing required values
            continue;
        }
        String avatar = (friend.user.images == null || friend.user.images.avatar == null) ? null : friend.user.images.avatar.full;
        // trakt has removed image support: currently displaying no image
        NowAdapter.NowItem nowItem = new NowAdapter.NowItem().displayData(entry.watched_at.getMillis(), entry.movie.title, null, null).tmdbId(entry.movie.ids == null ? null : entry.movie.ids.tmdb).friend(friend.user.username, avatar, entry.action);
        items.add(nowItem);
    }
    // only have a header? return nothing
    if (items.size() == 1) {
        return Collections.emptyList();
    }
    return items;
}
Also used : UserSlug(com.uwetrottmann.trakt5.entities.UserSlug) Friend(com.uwetrottmann.trakt5.entities.Friend) NowAdapter(com.battlelancer.seriesguide.adapters.NowAdapter) ArrayList(java.util.ArrayList) HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry)

Example 3 with Movie

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

the class UserMovieStreamFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // do not respond if we get a header position by accident
    if (position < 0) {
        return;
    }
    HistoryEntry item = mAdapter.getItem(position);
    if (item == null) {
        return;
    }
    // display movie details
    if (item.movie == null || item.movie.ids == null) {
        return;
    }
    Intent i = new Intent(getActivity(), MovieDetailsActivity.class);
    i.putExtra(MovieDetailsFragment.InitBundle.TMDB_ID, item.movie.ids.tmdb);
    ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat.makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle());
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry) Intent(android.content.Intent)

Example 4 with Movie

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

the class TraktTools method downloadWatchedMovies.

/**
     * Downloads trakt movie watched flags and mirrors them in the local database. Does NOT upload
     * any flags (e.g. trakt is considered the truth).
     */
public UpdateResult downloadWatchedMovies(DateTime watchedAt) {
    if (watchedAt == null) {
        Timber.e("downloadWatchedMovies: null watched_at");
        return UpdateResult.INCOMPLETE;
    }
    long lastWatchedAt = TraktSettings.getLastMoviesWatchedAt(context);
    if (!watchedAt.isAfter(lastWatchedAt)) {
        // not initial sync, no watched flags have changed
        Timber.d("downloadWatchedMovies: no changes since %tF %tT", lastWatchedAt, lastWatchedAt);
        return UpdateResult.SUCCESS;
    }
    if (!TraktCredentials.get(context).hasCredentials()) {
        return UpdateResult.INCOMPLETE;
    }
    // download watched movies
    List<BaseMovie> watchedMovies;
    try {
        Response<List<BaseMovie>> response = traktSync.get().watchedMovies(Extended.DEFAULT_MIN).execute();
        if (response.isSuccessful()) {
            watchedMovies = response.body();
        } else {
            if (SgTrakt.isUnauthorized(context, response)) {
                return UpdateResult.INCOMPLETE;
            }
            SgTrakt.trackFailedRequest(context, "get watched movies", response);
            return UpdateResult.INCOMPLETE;
        }
    } catch (IOException e) {
        SgTrakt.trackFailedRequest(context, "get watched movies", e);
        return UpdateResult.INCOMPLETE;
    }
    if (watchedMovies == null) {
        Timber.e("downloadWatchedMovies: null response");
        return UpdateResult.INCOMPLETE;
    }
    if (watchedMovies.isEmpty()) {
        Timber.d("downloadWatchedMovies: no watched movies on trakt");
        return UpdateResult.SUCCESS;
    }
    // apply watched flags for all watched trakt movies that are in the local database
    ArrayList<ContentProviderOperation> batch = new ArrayList<>();
    Set<Integer> localMovies = MovieTools.getMovieTmdbIdsAsSet(context);
    if (localMovies == null) {
        return UpdateResult.INCOMPLETE;
    }
    Set<Integer> unwatchedMovies = new HashSet<>(localMovies);
    for (BaseMovie movie : watchedMovies) {
        if (movie.movie == null || movie.movie.ids == null || movie.movie.ids.tmdb == null) {
            // required values are missing
            continue;
        }
        if (!localMovies.contains(movie.movie.ids.tmdb)) {
            // movie NOT in local database
            // add a shell entry for storing watched state
            batch.add(ContentProviderOperation.newInsert(SeriesGuideContract.Movies.CONTENT_URI).withValue(SeriesGuideContract.Movies.TMDB_ID, movie.movie.ids.tmdb).withValue(SeriesGuideContract.Movies.WATCHED, true).withValue(SeriesGuideContract.Movies.IN_COLLECTION, false).withValue(SeriesGuideContract.Movies.IN_WATCHLIST, false).build());
        } else {
            // movie IN local database
            // set movie watched
            batch.add(ContentProviderOperation.newUpdate(SeriesGuideContract.Movies.buildMovieUri(movie.movie.ids.tmdb)).withValue(SeriesGuideContract.Movies.WATCHED, true).build());
            unwatchedMovies.remove(movie.movie.ids.tmdb);
        }
    }
    // remove watched flags from all remaining local movies
    for (Integer tmdbId : unwatchedMovies) {
        batch.add(ContentProviderOperation.newUpdate(SeriesGuideContract.Movies.buildMovieUri(tmdbId)).withValue(SeriesGuideContract.Movies.WATCHED, false).build());
    }
    // apply database updates
    try {
        DBUtils.applyInSmallBatches(context, batch);
    } catch (OperationApplicationException e) {
        Timber.e(e, "downloadWatchedMovies: updating watched flags failed");
        return UpdateResult.INCOMPLETE;
    }
    // save last watched instant
    PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(TraktSettings.KEY_LAST_MOVIES_WATCHED_AT, watchedAt.getMillis()).commit();
    Timber.d("downloadWatchedMovies: success, last watched_at %tF %tT", watchedAt.getMillis(), watchedAt.getMillis());
    return UpdateResult.SUCCESS;
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BaseMovie(com.uwetrottmann.trakt5.entities.BaseMovie) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OperationApplicationException(android.content.OperationApplicationException) HashSet(java.util.HashSet)

Example 5 with Movie

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

the class TraktTask method buildComment.

private Comment buildComment() {
    Comment comment = new Comment();
    comment.comment = mArgs.getString(InitBundle.MESSAGE);
    comment.spoiler = mArgs.getBoolean(InitBundle.ISSPOILER);
    // as determined by "science", episode comments are most likely, so check for them first
    // episode?
    int episodeTvdbId = mArgs.getInt(InitBundle.EPISODE_TVDBID);
    if (episodeTvdbId != 0) {
        comment.episode = new Episode();
        comment.episode.ids = EpisodeIds.tvdb(episodeTvdbId);
        return comment;
    }
    // show?
    int showTvdbId = mArgs.getInt(InitBundle.SHOW_TVDBID);
    if (showTvdbId != 0) {
        comment.show = new Show();
        comment.show.ids = ShowIds.tvdb(showTvdbId);
        return comment;
    }
    // movie!
    int movieTmdbId = mArgs.getInt(InitBundle.MOVIE_TMDB_ID);
    comment.movie = new Movie();
    comment.movie.ids = MovieIds.tmdb(movieTmdbId);
    return comment;
}
Also used : Comment(com.uwetrottmann.trakt5.entities.Comment) Episode(com.uwetrottmann.trakt5.entities.Episode) SyncEpisode(com.uwetrottmann.trakt5.entities.SyncEpisode) SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Movie(com.uwetrottmann.trakt5.entities.Movie) Show(com.uwetrottmann.trakt5.entities.Show)

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