Search in sources :

Example 1 with SimpleSubExpandableItem

use of com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem in project FastAdapter by mikepenz.

the class ExpandableSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_collapsible);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        if (i % 10 == 0) {
            SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
            expandableItem.withName("Test " + i).withIdentifier(100 + 1);
            //add subitems so we can showcase the collapsible functionality
            List<IItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 5; ii++) {
                SimpleSubItem sampleItem = new SimpleSubItem();
                sampleItem.withName("-- Test " + ii).withIdentifier(1000 + ii);
                subItems.add(sampleItem);
            }
            expandableItem.withSubItems(subItems);
            items.add(expandableItem);
        } else {
            items.add(new SimpleSubItem().withName("Test " + i).withIdentifier(100 + i));
        }
    }
    fastItemAdapter.add(items);
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) LinkedList(java.util.LinkedList) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) RecyclerView(android.support.v7.widget.RecyclerView) IItem(com.mikepenz.fastadapter.IItem) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with SimpleSubExpandableItem

use of com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem in project FastAdapter by mikepenz.

the class IconGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_icon_grid);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter();
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    //init our gridLayoutManager and configure RV
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            switch(fastItemAdapter.getItemViewType(position)) {
                case R.id.fastadapter_expandable_item_id:
                    return 3;
                case R.id.fastadapter_icon_item_id:
                    return 1;
                default:
                    return -1;
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //order fonts by their name
    List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
    Collections.sort(mFonts, new Comparator<ITypeface>() {

        @Override
        public int compare(final ITypeface object1, final ITypeface object2) {
            return object1.getFontName().compareTo(object2.getFontName());
        }
    });
    //add all icons of all registered Fonts to the list
    int count = 0;
    ArrayList<SimpleSubExpandableItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
    for (ITypeface font : mFonts) {
        //we set the identifier from the count here, as I need a stable ID in the sample to showcase the state restore
        SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
        expandableItem.withName(font.getFontName()).withIdentifier(count);
        ArrayList<IItem> icons = new ArrayList<>();
        for (String icon : font.getIcons()) {
            IconItem iconItem = new IconItem();
            iconItem.withIcon(font.getIcon(icon));
            icons.add(iconItem);
        }
        expandableItem.withSubItems(icons);
        items.add(expandableItem);
        count++;
    }
    //fill with some sample data
    fastItemAdapter.add(items);
    //if first start we want to expand the item with ID 2
    if (savedInstanceState != null) {
        //restore selections (this has to be done after the items were added
        fastItemAdapter.withSavedInstanceState(savedInstanceState);
    } else {
        //expand one item to make sample look a bit more interesting
        fastItemAdapter.expand(2);
    }
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) ArrayList(java.util.ArrayList) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) IconItem(com.mikepenz.fastadapter.app.items.IconItem) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) IItem(com.mikepenz.fastadapter.IItem) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with SimpleSubExpandableItem

use of com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem 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 4 with SimpleSubExpandableItem

use of com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem 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)4 SimpleSubExpandableItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem)4 SimpleSubItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem)3 ArrayList (java.util.ArrayList)3 RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)2 IconicsLayoutInflater (com.mikepenz.iconics.context.IconicsLayoutInflater)2 SlideDownAlphaAnimator (com.mikepenz.itemanimators.SlideDownAlphaAnimator)2 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)2 LinkedList (java.util.LinkedList)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 TextView (android.widget.TextView)1 IconItem (com.mikepenz.fastadapter.app.items.IconItem)1 FastItemAdapter (com.mikepenz.fastadapter.commons.adapters.FastItemAdapter)1 ITypeface (com.mikepenz.iconics.typeface.ITypeface)1 Random (java.util.Random)1