Search in sources :

Example 1 with BindView

use of butterknife.BindView 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 BindView

use of butterknife.BindView in project butterknife by JakeWharton.

the class ButterKnifeProcessor method findAndParseTargets.

private Map<TypeElement, BindingSet> findAndParseTargets(RoundEnvironment env) {
    Map<TypeElement, BindingSet.Builder> builderMap = new LinkedHashMap<>();
    Set<TypeElement> erasedTargetNames = new LinkedHashSet<>();
    scanForRClasses(env);
    // Process each @BindArray element.
    for (Element element : env.getElementsAnnotatedWith(BindArray.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceArray(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindArray.class, e);
        }
    }
    // Process each @BindBitmap element.
    for (Element element : env.getElementsAnnotatedWith(BindBitmap.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceBitmap(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindBitmap.class, e);
        }
    }
    // Process each @BindBool element.
    for (Element element : env.getElementsAnnotatedWith(BindBool.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceBool(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindBool.class, e);
        }
    }
    // Process each @BindColor element.
    for (Element element : env.getElementsAnnotatedWith(BindColor.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceColor(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindColor.class, e);
        }
    }
    // Process each @BindDimen element.
    for (Element element : env.getElementsAnnotatedWith(BindDimen.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceDimen(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindDimen.class, e);
        }
    }
    // Process each @BindDrawable element.
    for (Element element : env.getElementsAnnotatedWith(BindDrawable.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceDrawable(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindDrawable.class, e);
        }
    }
    // Process each @BindFloat element.
    for (Element element : env.getElementsAnnotatedWith(BindFloat.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceFloat(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindFloat.class, e);
        }
    }
    // Process each @BindInt element.
    for (Element element : env.getElementsAnnotatedWith(BindInt.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceInt(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindInt.class, e);
        }
    }
    // Process each @BindString element.
    for (Element element : env.getElementsAnnotatedWith(BindString.class)) {
        if (!SuperficialValidation.validateElement(element))
            continue;
        try {
            parseResourceString(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindString.class, e);
        }
    }
    // Process each @BindView element.
    for (Element element : env.getElementsAnnotatedWith(BindView.class)) {
        // so that an unresolved View type can be generated by later processing rounds
        try {
            parseBindView(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindView.class, e);
        }
    }
    // Process each @BindViews element.
    for (Element element : env.getElementsAnnotatedWith(BindViews.class)) {
        // so that an unresolved View type can be generated by later processing rounds
        try {
            parseBindViews(element, builderMap, erasedTargetNames);
        } catch (Exception e) {
            logParsingError(element, BindViews.class, e);
        }
    }
    // Process each annotation that corresponds to a listener.
    for (Class<? extends Annotation> listener : LISTENERS) {
        findAndParseListener(env, listener, builderMap, erasedTargetNames);
    }
    // Associate superclass binders with their subclass binders. This is a queue-based tree walk
    // which starts at the roots (superclasses) and walks to the leafs (subclasses).
    Deque<Map.Entry<TypeElement, BindingSet.Builder>> entries = new ArrayDeque<>(builderMap.entrySet());
    Map<TypeElement, BindingSet> bindingMap = new LinkedHashMap<>();
    while (!entries.isEmpty()) {
        Map.Entry<TypeElement, BindingSet.Builder> entry = entries.removeFirst();
        TypeElement type = entry.getKey();
        BindingSet.Builder builder = entry.getValue();
        TypeElement parentType = findParentType(type, erasedTargetNames);
        if (parentType == null) {
            bindingMap.put(type, builder.build());
        } else {
            BindingSet parentBinding = bindingMap.get(parentType);
            if (parentBinding != null) {
                builder.setParent(parentBinding);
                bindingMap.put(type, builder.build());
            } else {
                // Has a superclass binding but we haven't built it yet. Re-enqueue for later.
                entries.addLast(entry);
            }
        }
    }
    return bindingMap;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) LinkedHashMap(java.util.LinkedHashMap) BindDimen(butterknife.BindDimen) BindInt(butterknife.BindInt) BindFloat(butterknife.BindFloat) BindDrawable(butterknife.BindDrawable) BindBitmap(butterknife.BindBitmap) BindString(butterknife.BindString) TypeElement(javax.lang.model.element.TypeElement) BindArray(butterknife.BindArray) MirroredTypeException(javax.lang.model.type.MirroredTypeException) IOException(java.io.IOException) BindViews(butterknife.BindViews) ArrayDeque(java.util.ArrayDeque) BindColor(butterknife.BindColor) BindBool(butterknife.BindBool) BindView(butterknife.BindView) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with BindView

use of butterknife.BindView in project SeriesGuide by UweTrottmann.

the class SeasonsAdapter method bindView.

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder viewHolder = (ViewHolder) view.getTag();
    // title
    final int seasonNumber = mCursor.getInt(SeasonsQuery.COMBINED);
    viewHolder.seasonTitle.setText(SeasonTools.getSeasonString(mContext, seasonNumber));
    // progress
    final int watchable = mCursor.getInt(SeasonsQuery.WATCHCOUNT);
    final int notReleased = mCursor.getInt(SeasonsQuery.UNAIREDCOUNT);
    final int noReleaseDate = mCursor.getInt(SeasonsQuery.NOAIRDATECOUNT);
    final int max = mCursor.getInt(SeasonsQuery.TOTALCOUNT);
    final int progress = max - watchable - notReleased - noReleaseDate;
    viewHolder.seasonProgressBar.setMax(max);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        viewHolder.seasonProgressBar.setProgress(progress, true);
    } else {
        viewHolder.seasonProgressBar.setProgress(progress);
    }
    viewHolder.seasonProgress.setText(progress + "/" + max);
    // skipped label
    viewHolder.seasonSkipped.setVisibility(SeasonTools.hasSkippedTag(mCursor.getString(SeasonsQuery.TAGS)) ? View.VISIBLE : View.GONE);
    // season episodes text
    StringBuilder countText = new StringBuilder();
    Resources res = mContext.getResources();
    if (watchable > 0) {
        // some released episodes left to watch
        TextViewCompat.setTextAppearance(viewHolder.seasonWatchCount, R.style.TextAppearance_Caption_Narrow);
        countText.append(res.getQuantityString(R.plurals.not_watched_episodes_plural, watchable, watchable));
    } else {
        TextViewCompat.setTextAppearance(viewHolder.seasonWatchCount, R.style.TextAppearance_Caption_Narrow_Dim);
        if (noReleaseDate > 0) {
            // there are watchable episodes that have no release date
            countText.append(res.getQuantityString(R.plurals.other_episodes_plural, noReleaseDate, noReleaseDate));
        } else {
            // all watched
            countText.append(mContext.getString(R.string.season_allwatched));
        }
    }
    if (notReleased > 0) {
        // there are not yet released episodes
        countText.append(" (+");
        countText.append(res.getQuantityString(R.plurals.not_released_episodes_plural, notReleased, notReleased));
        countText.append(")");
    }
    viewHolder.seasonWatchCount.setText(countText);
    // context menu
    final int seasonTvdbId = mCursor.getInt(SeasonsQuery._ID);
    viewHolder.contextMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (popupMenuClickListener != null) {
                popupMenuClickListener.onPopupMenuClick(v, seasonTvdbId, seasonNumber);
            }
        }
    });
}
Also used : OnClickListener(android.view.View.OnClickListener) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

BindView (butterknife.BindView)3 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Resources (android.content.res.Resources)1 BindArray (butterknife.BindArray)1 BindBitmap (butterknife.BindBitmap)1 BindBool (butterknife.BindBool)1 BindColor (butterknife.BindColor)1 BindDimen (butterknife.BindDimen)1 BindDrawable (butterknife.BindDrawable)1 BindFloat (butterknife.BindFloat)1 BindInt (butterknife.BindInt)1 BindString (butterknife.BindString)1 BindViews (butterknife.BindViews)1 WatchedBox (com.battlelancer.seriesguide.widgets.WatchedBox)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 Date (java.util.Date)1