Java Code Examples for eu.davidea.flexibleadapter.FlexibleAdapter#hasFilter()

The following examples show how to use eu.davidea.flexibleadapter.FlexibleAdapter#hasFilter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleItem.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, SimpleViewHolder holder, int position, List<Object> payloads) {
    Context context = holder.itemView.getContext();

    // Background, when bound the first time
    if (payloads.size() == 0) {
        Drawable drawable = DrawableUtils.getSelectableBackgroundCompat(
                Color.WHITE, Color.parseColor("#dddddd"), //Same color of divider
                DrawableUtils.getColorControlHighlight(context));
        DrawableUtils.setBackgroundCompat(holder.itemView, drawable);
        DrawableUtils.setBackgroundCompat(holder.frontView, drawable);
    }

    // Display the current flip status
    holder.mFlipView.flipSilently(adapter.isSelected(position));

    // In case of any Words in the searchText matches with Title this will be highlighted
    if (adapter.hasFilter()) {
        String filter = adapter.getFilter(String.class);
        FlexibleUtils.highlightWords(holder.mTitle, getTitle(), filter);
        FlexibleUtils.highlightWords(holder.mSubtitle, getSubtitle(), filter);
    } else {
        holder.mTitle.setText(getTitle());
        holder.mSubtitle.setText(getSubtitle());
    }
}
 
Example 2
Source File: ExpandableHeaderItem.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
private int countFilteredChildren(FlexibleAdapter<IFlexible> adapter) {
    if (adapter.hasFilter()) {
        String filter = adapter.getFilter(String.class);
        int size = 0;
        for (SubItem s : mSubItems) {
            if (s.filter(filter)) size++;
        }
        return size;
    }
    return adapter.getCurrentChildren(this).size();
}
 
Example 3
Source File: SubItem.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, ChildViewHolder holder, int position, List<Object> payloads) {
    //In case of searchText matches with Title or with an SimpleItem's field
    // this will be highlighted
    if (adapter.hasFilter()) {
        Context context = holder.itemView.getContext();
        String filter = adapter.getFilter(String.class);
        FlexibleUtils.highlightText(holder.mTitle, getTitle(), filter,
                context.getResources().getColor(R.color.colorAccent_light));
    } else {
        holder.mTitle.setText(getTitle());
    }
}
 
Example 4
Source File: ExpandableItem.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public void bindViewHolder(final FlexibleAdapter<IFlexible> adapter, ParentViewHolder holder, int position, List<Object> payloads) {
    Context context = holder.itemView.getContext();

    // Subtitle
    setSubtitle(adapter.getCurrentChildren(this).size() + " subItems"
            + (getHeader() != null ? " - " + getHeader().getId() : "")
            + (getUpdates() > 0 ? " - u" + getUpdates() : ""));

    // Background, when bound the first time
    if (payloads.size() == 0) {
        Drawable drawable = DrawableUtils.getSelectableBackgroundCompat(
                Color.WHITE, Color.parseColor("#dddddd"), // Same color of divider
                DrawableUtils.getColorControlHighlight(context));
        DrawableUtils.setBackgroundCompat(holder.itemView, drawable);
        DrawableUtils.setBackgroundCompat(holder.frontView, drawable);
    }

    if (payloads.size() > 0) {
        Log.d(this.getClass().getSimpleName(), "ExpandableItem Payload " + payloads);
        if (adapter.hasFilter()) {
            FlexibleUtils.highlightText(holder.mSubtitle, getSubtitle(), adapter.getFilter(String.class));
        } else {
            holder.mSubtitle.setText(getSubtitle());
        }
        // We stop the process here, we only want to update the subtitle

    } else {
        // DemoApp: INNER ANIMATION EXAMPLE! ImageView - Handle Flip Animation on
        // Select ALL and Deselect ALL
        if (adapter.isSelectAll() || adapter.isLastItemInActionMode()) {
            // Consume the Animation
            holder.mFlipView.flip(adapter.isSelected(position), 200L);
        } else {
            // Display the current flip status
            holder.mFlipView.flipSilently(adapter.isSelected(position));
        }

        // In case of searchText matches with Title or with a field this will be highlighted
        if (adapter.hasFilter()) {
            String filter = adapter.getFilter(String.class);
            FlexibleUtils.highlightWords(holder.mTitle, getTitle(), filter);
            FlexibleUtils.highlightWords(holder.mSubtitle, getSubtitle(), filter);
        } else {
            holder.mTitle.setText(getTitle());
            holder.mSubtitle.setText(getSubtitle());
        }
    }
}