Search in sources :

Example 16 with IItem

use of com.mikepenz.fastadapter.IItem in project FastAdapter by mikepenz.

the class AdapterUtil method findSubItemSelections.

/**
     * internal method to find all selections from subItems and sub sub items so we can save those inside our savedInstanceState
     *
     * @param item       the parent item
     * @param selections the ArrayList which will be stored in the savedInstanceState
     */
public static <Item extends IItem> void findSubItemSelections(Item item, List<String> selections) {
    if (item instanceof IExpandable && !((IExpandable) item).isExpanded() && ((IExpandable) item).getSubItems() != null) {
        List<Item> subItems = (List<Item>) ((IExpandable<Item, ?>) item).getSubItems();
        Item subItem;
        String id;
        for (int i = 0, size = subItems.size(); i < size; i++) {
            subItem = subItems.get(i);
            id = String.valueOf(subItem.getIdentifier());
            if (subItem.isSelected()) {
                selections.add(id);
            }
            findSubItemSelections(subItem, selections);
        }
    }
}
Also used : IItem(com.mikepenz.fastadapter.IItem) IExpandable(com.mikepenz.fastadapter.IExpandable) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with IItem

use of com.mikepenz.fastadapter.IItem in project FastAdapter by mikepenz.

the class StickyHeaderAdapter method onBindHeaderViewHolder.

@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
    TextView textView = (TextView) holder.itemView;
    IItem item = getItem(position);
    if (item instanceof SimpleItem && ((SimpleItem) item).header != null) {
        //based on the position we set the headers text
        textView.setText(String.valueOf(((SimpleItem) item).header.charAt(0)));
    } else if (item instanceof SimpleSubItem && ((SimpleSubItem) item).header != null) {
        //based on the position we set the headers text
        textView.setText(String.valueOf(((SimpleSubItem) item).header.charAt(0)));
    } else if (item instanceof SimpleSubExpandableItem && ((SimpleSubExpandableItem) item).header != null) {
        //based on the position we set the headers text
        textView.setText(String.valueOf(((SimpleSubExpandableItem) item).header.charAt(0)));
    }
    holder.itemView.setBackgroundColor(getRandomColor());
}
Also used : SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) TextView(android.widget.TextView) IItem(com.mikepenz.fastadapter.IItem) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem)

Example 18 with IItem

use of com.mikepenz.fastadapter.IItem in project FastAdapter by mikepenz.

the class AdvancedSampleActivity method setItems.

private void setItems() {
    SimpleItem sampleItem = new SimpleItem().withName("Header").withSelectable(false).withIdentifier(1);
    mHeaderAdapter.add(sampleItem);
    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    int size = new Random().nextInt(25) + 10;
    for (int i = 1; i <= size; i++) {
        if (i % 6 == 0) {
            SimpleSubExpandableItem<SimpleSubExpandableItem, SimpleSubExpandableItem> expandableItem = new SimpleSubExpandableItem<>();
            expandableItem.withName("Test " + i).withHeader(headers[i / 5]).withIdentifier(100 + i);
            List<SimpleSubExpandableItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 3; ii++) {
                SimpleSubExpandableItem<SimpleSubExpandableItem, SimpleSubItem> subItem = new SimpleSubExpandableItem<>();
                subItem.withName("-- SubTest " + ii).withHeader(headers[i / 5]).withIdentifier(1000 + ii);
                List<SimpleSubItem> subSubItems = new LinkedList<>();
                for (int iii = 1; iii <= 3; iii++) {
                    SimpleSubItem subSubItem = new SimpleSubItem();
                    subSubItem.withName("---- SubSubTest " + iii).withHeader(headers[i / 5]).withIdentifier(10000 + iii);
                    subSubItems.add(subSubItem);
                }
                subItem.withSubItems(subSubItems);
                subItems.add(subItem);
            }
            expandableItem.withSubItems(subItems);
            items.add(expandableItem);
        } else {
            items.add(new SimpleSubItem().withName("Test " + i).withHeader(headers[i / 5]).withIdentifier(i));
        }
    }
    mItemAdapter.set(items);
}
Also used : SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Random(java.util.Random) IItem(com.mikepenz.fastadapter.IItem) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem)

Aggregations

IItem (com.mikepenz.fastadapter.IItem)18 ArrayList (java.util.ArrayList)12 IExpandable (com.mikepenz.fastadapter.IExpandable)10 RecyclerView (android.support.v7.widget.RecyclerView)5 Toolbar (android.support.v7.widget.Toolbar)5 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)5 LinkedList (java.util.LinkedList)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 IAdapter (com.mikepenz.fastadapter.IAdapter)4 SimpleSubExpandableItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem)4 SimpleSubItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem)4 IconicsLayoutInflater (com.mikepenz.iconics.context.IconicsLayoutInflater)4 FastAdapter (com.mikepenz.fastadapter.FastAdapter)3 SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)3 SlideDownAlphaAnimator (com.mikepenz.itemanimators.SlideDownAlphaAnimator)3 List (java.util.List)3 ActionMode (android.support.v7.view.ActionMode)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 View (android.view.View)2 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)2