Search in sources :

Example 1 with HistoryEntry

use of com.uwetrottmann.trakt5.entities.HistoryEntry 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 2 with HistoryEntry

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

the class TraktRecentEpisodeHistoryLoader method addItems.

protected void addItems(List<NowAdapter.NowItem> items, List<HistoryEntry> history) {
    SparseArrayCompat<String> localShows = ShowTools.getShowTvdbIdsAndPosters(getContext());
    long timeDayAgo = System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS;
    for (int i = 0, size = history.size(); i < size; i++) {
        HistoryEntry entry = history.get(i);
        if (entry.episode == null || entry.episode.ids == null || entry.episode.ids.tvdb == null || entry.show == null || entry.watched_at == null) {
            // missing required values
            continue;
        }
        // however, include at least one older episode if there are none, yet
        if (entry.watched_at.isBefore(timeDayAgo) && items.size() > 1) {
            break;
        }
        // look for a TVDB poster
        String posterUrl;
        Integer showTvdbId = entry.show.ids == null ? null : entry.show.ids.tvdb;
        if (showTvdbId != null && localShows != null) {
            // prefer poster of already added show, fall back to first uploaded poster
            posterUrl = TvdbImageTools.smallSizeOrFirstUrl(localShows.get(showTvdbId), showTvdbId);
        } else {
            posterUrl = null;
        }
        String description = (entry.episode.season == null || entry.episode.number == null) ? entry.episode.title : TextTools.getNextEpisodeString(getContext(), entry.episode.season, entry.episode.number, entry.episode.title);
        NowAdapter.NowItem item = new NowAdapter.NowItem().displayData(entry.watched_at.getMillis(), entry.show.title, description, posterUrl).tvdbIds(entry.episode.ids.tvdb, showTvdbId).recentlyWatchedTrakt(entry.action);
        items.add(item);
    }
}
Also used : NowAdapter(com.battlelancer.seriesguide.adapters.NowAdapter) HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry)

Example 3 with HistoryEntry

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

the class TraktRecentMovieHistoryLoader method addItems.

@Override
protected void addItems(List<NowAdapter.NowItem> items, List<HistoryEntry> history) {
    // add movies
    long threeDaysAgo = System.currentTimeMillis() - 3 * DateUtils.DAY_IN_MILLIS;
    for (int i = 0, size = history.size(); i < size; i++) {
        HistoryEntry entry = history.get(i);
        if (entry.movie == null || entry.movie.ids == null || entry.movie.ids.tmdb == null || entry.watched_at == null) {
            // missing required values
            continue;
        }
        // however, include at least one older one if there are none
        if (entry.watched_at.isBefore(threeDaysAgo) && items.size() > 1) {
            break;
        }
        // trakt has removed image support: currently displaying no image
        items.add(new NowAdapter.NowItem().displayData(entry.watched_at.getMillis(), entry.movie.title, null, null).tmdbId(entry.movie.ids.tmdb).recentlyWatchedTrakt(entry.action));
    }
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry)

Example 4 with HistoryEntry

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

the class TraktFriendsEpisodeHistoryLoader 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 episode for each friend
    SparseArrayCompat<String> localShows = ShowTools.getShowTvdbIdsAndPosters(getContext());
    boolean preventSpoilers = DisplaySettings.preventSpoilers(getContext());
    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.EPISODES, 1, 1, Extended.DEFAULT_MIN, null, null), "get friend episode history");
        if (history == null || history.size() == 0) {
            // no history
            continue;
        }
        HistoryEntry entry = history.get(0);
        if (entry.watched_at == null || entry.episode == null || entry.episode.season == null || entry.episode.number == null || entry.show == null) {
            // missing required values
            continue;
        }
        // look for a TVDB poster
        String posterUrl;
        Integer showTvdbId = entry.show.ids == null ? null : entry.show.ids.tvdb;
        if (showTvdbId != null && localShows != null) {
            // prefer poster of already added show, fall back to first uploaded poster
            posterUrl = TvdbImageTools.smallSizeOrFirstUrl(localShows.get(showTvdbId), showTvdbId);
        } else {
            posterUrl = null;
        }
        String avatar = (friend.user.images == null || friend.user.images.avatar == null) ? null : friend.user.images.avatar.full;
        String episodeString;
        if (preventSpoilers) {
            // just display the number
            episodeString = TextTools.getEpisodeNumber(getContext(), entry.episode.season, entry.episode.number);
        } else {
            // display number and title
            episodeString = TextTools.getNextEpisodeString(getContext(), entry.episode.season, entry.episode.number, entry.episode.title);
        }
        NowAdapter.NowItem nowItem = new NowAdapter.NowItem().displayData(entry.watched_at.getMillis(), entry.show.title, episodeString, posterUrl).tvdbIds(entry.episode.ids == null ? null : entry.episode.ids.tvdb, showTvdbId).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) NowAdapter(com.battlelancer.seriesguide.adapters.NowAdapter) ArrayList(java.util.ArrayList) Friend(com.uwetrottmann.trakt5.entities.Friend) HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry)

Example 5 with HistoryEntry

use of com.uwetrottmann.trakt5.entities.HistoryEntry 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)

Aggregations

HistoryEntry (com.uwetrottmann.trakt5.entities.HistoryEntry)9 NowAdapter (com.battlelancer.seriesguide.adapters.NowAdapter)3 NonNull (android.support.annotation.NonNull)2 Friend (com.uwetrottmann.trakt5.entities.Friend)2 UserSlug (com.uwetrottmann.trakt5.entities.UserSlug)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Date (java.util.Date)1