Search in sources :

Example 6 with HistoryEntry

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

the class MovieHistoryAdapter method getView.

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    // A ViewHolder keeps references to child views to avoid
    // unnecessary calls to findViewById() on each row.
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.item_history_movie, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    HistoryEntry item = getItem(position);
    if (item == null) {
        // all bets are off!
        return convertView;
    }
    // movie title
    holder.title.setText(item.movie == null ? null : item.movie.title);
    // timestamp
    if (item.watched_at != null) {
        CharSequence timestamp = DateUtils.getRelativeTimeSpanString(item.watched_at.getMillis(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL);
        holder.timestamp.setText(timestamp);
    } else {
        holder.timestamp.setText(null);
    }
    // action type indicator
    if ("watch".equals(item.action)) {
        // marked watched
        holder.type.setImageResource(getResIdDrawableWatched());
    } else {
        // check-in, scrobble
        holder.type.setImageResource(getResIdDrawableCheckin());
    }
    return convertView;
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry) NonNull(android.support.annotation.NonNull)

Example 7 with HistoryEntry

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

the class SectionedHistoryAdapter method getHeaderView.

@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
    // get header position for item position
    position = mHeaders.get(position).getRefPosition();
    HistoryEntry item = getItem(position);
    if (item == null) {
        return null;
    }
    HeaderViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.item_grid_header, parent, false);
        holder = new HeaderViewHolder();
        holder.day = (TextView) convertView.findViewById(R.id.textViewGridHeader);
        convertView.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }
    long headerTime = getHeaderTime(item);
    // display headers like "Mon in 3 days", also "today" when applicable
    holder.day.setText(TimeTools.formatToLocalDayAndRelativeTime(getContext(), new Date(headerTime)));
    return convertView;
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry) Date(java.util.Date)

Example 8 with HistoryEntry

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

the class EpisodeHistoryAdapter method getView.

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    // A ViewHolder keeps references to child views to avoid
    // unnecessary calls to findViewById() on each row.
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.item_history, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    HistoryEntry item = getItem(position);
    if (item == null) {
        // all bets are off!
        return convertView;
    }
    // show title
    holder.title.setText(item.show == null ? null : item.show.title);
    // show poster, use a TVDB one
    String posterUrl;
    Integer showTvdbId = (item.show == null || item.show.ids == null) ? null : item.show.ids.tvdb;
    if (localShowPosters != null && showTvdbId != null) {
        // prefer poster of already added show, fall back to first uploaded poster
        posterUrl = TvdbImageTools.smallSizeOrFirstUrl(localShowPosters.get(showTvdbId), showTvdbId);
    } else {
        posterUrl = null;
    }
    TvdbImageTools.loadShowPosterResizeSmallCrop(getContext(), holder.poster, posterUrl);
    // timestamp
    if (item.watched_at != null) {
        CharSequence timestamp = DateUtils.getRelativeTimeSpanString(item.watched_at.getMillis(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL);
        holder.timestamp.setText(timestamp);
    } else {
        holder.timestamp.setText(null);
    }
    // action type indicator
    if ("watch".equals(item.action)) {
        // marked watched
        holder.type.setImageResource(getResIdDrawableWatched());
    } else {
        // check-in, scrobble
        holder.type.setImageResource(getResIdDrawableCheckin());
    }
    // episode
    if (item.episode != null && item.episode.season != null && item.episode.number != null) {
        holder.description.setText(TextTools.getNextEpisodeString(getContext(), item.episode.season, item.episode.number, item.episode.title));
    } else {
        holder.description.setText(null);
    }
    return convertView;
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry) NonNull(android.support.annotation.NonNull)

Example 9 with HistoryEntry

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

the class UserEpisodeStreamFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // do not respond if we get a header position (e.g. shortly after data was refreshed)
    if (position < 0) {
        return;
    }
    HistoryEntry item = mAdapter.getItem(position);
    if (item == null) {
        return;
    }
    if (item.episode == null || item.episode.season == null || item.episode.number == null || item.show == null || item.show.ids == null || item.show.ids.tvdb == null) {
        // no episode or show? give up
        return;
    }
    Cursor episodeQuery = getActivity().getContentResolver().query(SeriesGuideContract.Episodes.buildEpisodesOfShowUri(item.show.ids.tvdb), new String[] { SeriesGuideContract.Episodes._ID }, SeriesGuideContract.Episodes.NUMBER + "=" + item.episode.number + " AND " + SeriesGuideContract.Episodes.SEASON + "=" + item.episode.season, null, null);
    if (episodeQuery == null) {
        return;
    }
    if (episodeQuery.getCount() != 0) {
        // display the episode details if we have a match
        episodeQuery.moveToFirst();
        showDetails(view, episodeQuery.getInt(0));
    } else {
        // offer to add the show if it's not in the show database yet
        AddShowDialogFragment.showAddDialog(item.show.ids.tvdb, getFragmentManager());
    }
    episodeQuery.close();
}
Also used : HistoryEntry(com.uwetrottmann.trakt5.entities.HistoryEntry) Cursor(android.database.Cursor)

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