Search in sources :

Example 1 with RightIconModel

use of com.mikepenz.fastadapter.app.generic.RightIconModel in project FastAdapter by mikepenz.

the class MultiTypeGenericItemActivity 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_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_multi_generic_item);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastAdapter = new FastAdapter();
    fastAdapter.withSelectable(true);
    //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);
    //if you need multiple items for different models you can also do this be defining a Function which get's the model object and returns the item (extends IItem)
    GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(new Function<IconModel, GenericIconItem>() {

        @Override
        public GenericIconItem apply(IconModel o) {
            if (o instanceof RightIconModel) {
                return new RightGenericIconItem(o);
            } else {
                return new GenericIconItem(o);
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(itemAdapter.wrap(fastAdapter));
    //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
    ArrayList<IconModel> models = new ArrayList<>();
    int i = 0;
    for (ITypeface font : mFonts) {
        for (String icon : font.getIcons()) {
            if (i % 3 == 0) {
                models.add(new IconModel(font.getIcon(icon)));
            } else {
                models.add(new RightIconModel(font.getIcon(icon)));
            }
            i++;
        }
    }
    //fill with some sample data
    itemAdapter.addModel(models);
    //restore selections (this has to be done after the items were added
    fastAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) ArrayList(java.util.ArrayList) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) GenericItemAdapter(com.mikepenz.fastadapter.adapters.GenericItemAdapter) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 FastAdapter (com.mikepenz.fastadapter.FastAdapter)1 GenericItemAdapter (com.mikepenz.fastadapter.adapters.GenericItemAdapter)1 GenericIconItem (com.mikepenz.fastadapter.app.generic.GenericIconItem)1 IconModel (com.mikepenz.fastadapter.app.generic.IconModel)1 RightGenericIconItem (com.mikepenz.fastadapter.app.generic.RightGenericIconItem)1 RightIconModel (com.mikepenz.fastadapter.app.generic.RightIconModel)1 ITypeface (com.mikepenz.iconics.typeface.ITypeface)1 SlideDownAlphaAnimator (com.mikepenz.itemanimators.SlideDownAlphaAnimator)1 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)1 ArrayList (java.util.ArrayList)1