Search in sources :

Example 1 with WatchedBox

use of com.battlelancer.seriesguide.widgets.WatchedBox in project SeriesGuide by UweTrottmann.

the class EpisodesAdapter method bindView.

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder viewHolder = (ViewHolder) view.getTag();
    // episode title
    final int watchedFlag = mCursor.getInt(EpisodesQuery.WATCHED);
    final int episodeNumber = mCursor.getInt(EpisodesQuery.NUMBER);
    if (EpisodeTools.isUnwatched(watchedFlag) && DisplaySettings.preventSpoilers(mContext)) {
        // just display the episode number "1x02"
        int season = mCursor.getInt(EpisodesQuery.SEASON);
        viewHolder.episodeTitle.setText(TextTools.getEpisodeNumber(mContext, season, episodeNumber));
    } else {
        viewHolder.episodeTitle.setText(mCursor.getString(EpisodesQuery.TITLE));
    }
    // number
    viewHolder.episodeNumber.setText(String.valueOf(episodeNumber));
    // watched box
    viewHolder.watchedBox.setEpisodeFlag(watchedFlag);
    final int episodeId = mCursor.getInt(EpisodesQuery._ID);
    viewHolder.watchedBox.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            WatchedBox box = (WatchedBox) v;
            // disable button, will be re-enabled on data reload once action completes
            box.setEnabled(false);
            onFlagListener.onFlagEpisodeWatched(episodeId, episodeNumber, !EpisodeTools.isWatched(box.getEpisodeFlag()));
        }
    });
    viewHolder.watchedBox.setEnabled(true);
    boolean watched = EpisodeTools.isWatched(watchedFlag);
    viewHolder.watchedBox.setContentDescription(mContext.getString(watched ? R.string.action_unwatched : R.string.action_watched));
    CheatSheet.setup(viewHolder.watchedBox, watched ? R.string.action_unwatched : R.string.action_watched);
    // collected tag
    final boolean isCollected = mCursor.getInt(EpisodesQuery.COLLECTED) == 1;
    viewHolder.collected.setVisibility(isCollected ? View.VISIBLE : View.INVISIBLE);
    // alternative numbers
    StringBuilder altNumbers = new StringBuilder();
    int absoluteNumber = mCursor.getInt(EpisodesQuery.ABSOLUTE_NUMBER);
    if (absoluteNumber > 0) {
        altNumbers.append(mContext.getString(R.string.episode_number_absolute)).append(" ").append(absoluteNumber);
    }
    double dvdNumber = mCursor.getDouble(EpisodesQuery.DVDNUMBER);
    if (dvdNumber > 0) {
        if (altNumbers.length() != 0) {
            altNumbers.append(" | ");
        }
        altNumbers.append(mContext.getString(R.string.episode_number_disk)).append(" ").append(dvdNumber);
    }
    viewHolder.episodeAlternativeNumbers.setText(altNumbers);
    // release time
    final long releaseTime = mCursor.getLong(EpisodesQuery.FIRSTAIREDMS);
    if (releaseTime != -1) {
        Date actualRelease = TimeTools.applyUserOffset(mContext, releaseTime);
        // "in 15 mins" or "Oct 31, 2010"
        boolean displayExactDate = DisplaySettings.isDisplayExactDate(mContext);
        viewHolder.episodeAirdate.setText(displayExactDate ? TimeTools.formatToLocalDateShort(mContext, actualRelease) : TimeTools.formatToLocalRelativeTime(mContext, actualRelease));
    } else {
        viewHolder.episodeAirdate.setText(mContext.getString(R.string.episode_firstaired_unknown));
    }
    // context menu
    viewHolder.contextMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (popupMenuClickListener != null) {
                popupMenuClickListener.onPopupMenuClick(v, episodeId, episodeNumber, releaseTime, watchedFlag, isCollected);
            }
        }
    });
}
Also used : WatchedBox(com.battlelancer.seriesguide.widgets.WatchedBox) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date)

Example 2 with WatchedBox

use of com.battlelancer.seriesguide.widgets.WatchedBox in project SeriesGuide by UweTrottmann.

the class CalendarAdapter method bindView.

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ViewHolder viewHolder = (ViewHolder) view.getTag();
    // watched box
    // save rowid to hand over to OnClick event listener
    final int showTvdbId = cursor.getInt(Query.SHOW_ID);
    final int season = cursor.getInt(Query.SEASON);
    final int episodeTvdbId = cursor.getInt(Query._ID);
    final int episode = cursor.getInt(Query.NUMBER);
    viewHolder.watchedBox.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            WatchedBox box = (WatchedBox) v;
            // disable button, will be re-enabled on data reload once action completes
            box.setEnabled(false);
            EpisodeTools.episodeWatched(app, showTvdbId, episodeTvdbId, season, episode, EpisodeTools.isWatched(box.getEpisodeFlag()) ? EpisodeFlags.UNWATCHED : EpisodeFlags.WATCHED);
        }
    });
    int episodeFlag = cursor.getInt(Query.WATCHED);
    viewHolder.watchedBox.setEpisodeFlag(episodeFlag);
    viewHolder.watchedBox.setEnabled(true);
    boolean watched = EpisodeTools.isWatched(episodeFlag);
    viewHolder.watchedBox.setContentDescription(context.getString(watched ? R.string.action_unwatched : R.string.action_watched));
    CheatSheet.setup(viewHolder.watchedBox, watched ? R.string.action_unwatched : R.string.action_watched);
    // show title
    viewHolder.show.setText(cursor.getString(Query.SHOW_TITLE));
    // episode number and title
    if (EpisodeTools.isUnwatched(episodeFlag) && DisplaySettings.preventSpoilers(context)) {
        // just show the number
        viewHolder.episode.setText(TextTools.getEpisodeNumber(context, season, episode));
    } else {
        // show number and title
        viewHolder.episode.setText(TextTools.getNextEpisodeString(context, season, episode, cursor.getString(Query.TITLE)));
    }
    // timestamp, absolute time and network
    StringBuilder releaseInfo = new StringBuilder();
    long releaseTime = cursor.getLong(Query.RELEASE_TIME_MS);
    if (releaseTime != -1) {
        Date actualRelease = TimeTools.applyUserOffset(context, releaseTime);
        // timestamp
        boolean displayExactDate = DisplaySettings.isDisplayExactDate(context);
        viewHolder.timestamp.setText(displayExactDate ? TimeTools.formatToLocalDateShort(context, actualRelease) : TimeTools.formatToLocalRelativeTime(context, actualRelease));
        // "10:00 PM / Network", as left aligned, exactly mirrored from show list
        releaseInfo.append(TimeTools.formatToLocalTime(context, actualRelease));
    } else {
        viewHolder.timestamp.setText(null);
    }
    final String network = cursor.getString(Query.SHOW_NETWORK);
    if (!TextUtils.isEmpty(network)) {
        releaseInfo.append(" / ").append(network);
    }
    viewHolder.info.setText(releaseInfo);
    // collected indicator
    boolean isCollected = EpisodeTools.isCollected(cursor.getInt(Query.COLLECTED));
    viewHolder.collected.setVisibility(isCollected ? View.VISIBLE : View.GONE);
    // set poster
    TvdbImageTools.loadShowPosterResizeSmallCrop(context, viewHolder.poster, TvdbImageTools.smallSizeUrl(cursor.getString(Query.SHOW_POSTER_PATH)));
}
Also used : WatchedBox(com.battlelancer.seriesguide.widgets.WatchedBox) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date)

Aggregations

View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 WatchedBox (com.battlelancer.seriesguide.widgets.WatchedBox)2 Date (java.util.Date)2 OnClickListener (android.view.View.OnClickListener)1 BindView (butterknife.BindView)1