Search in sources :

Example 6 with SimpleItem

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

the class SortActivity 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);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sort);
    ButterKnife.bind(this);
    // Handle Toolbar
    setSupportActionBar(toolbar);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);
    //configure our fastAdapter
    fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
            return false;
        }
    });
    //get our recyclerView and do basic setup
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(fastItemAdapter);
    if (savedInstanceState != null) {
        //Retrieve the previous sorting strategy from the instance state
        sortingStrategy = toSortingStrategy(savedInstanceState.getInt("sorting_strategy"));
    } else {
        //Set the default so
        sortingStrategy = SORT_NONE;
    }
    //we sort the list
    fastItemAdapter.getItemAdapter().withComparator(getComparator());
    //initial filling of the list
    fastItemAdapter.setNewList(generateUnsortedList());
    //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 : RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 7 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem 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 8 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem 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

SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 RecyclerView (android.support.v7.widget.RecyclerView)5 FastAdapter (com.mikepenz.fastadapter.FastAdapter)5 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)5 ArrayList (java.util.ArrayList)5 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)4 Toolbar (android.support.v7.widget.Toolbar)4 View (android.view.View)4 IItem (com.mikepenz.fastadapter.IItem)3 SearchView (android.support.v7.widget.SearchView)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)2 HeaderAdapter (com.mikepenz.fastadapter.adapters.HeaderAdapter)2 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)2 SimpleSubExpandableItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem)2 SimpleSubItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem)2 SimpleDragCallback (com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback)2 Random (java.util.Random)2 Handler (android.os.Handler)1