Search in sources :

Example 1 with GenericIconItem

use of com.mikepenz.fastadapter.app.generic.GenericIconItem 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)

Example 2 with GenericIconItem

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

the class GenericItemActivity 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_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);
    GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(GenericIconItem.class, IconModel.class);
    final FastScrollIndicatorAdapter<GenericIconItem> fastScrollIndicatorAdapter = new FastScrollIndicatorAdapter<>();
    rv.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
    DragScrollBar materialScrollBar = new DragScrollBar(this, rv, true);
    materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.colorAccent));
    materialScrollBar.setHandleOffColour(ContextCompat.getColor(this, R.color.colorAccent));
    materialScrollBar.addIndicator(new CustomIndicator(this), true);
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    //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<>();
    for (ITypeface font : mFonts) {
        for (String icon : font.getIcons()) {
            models.add(new IconModel(font.getIcon(icon)));
        }
    }
    //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 : FastScrollIndicatorAdapter(com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) DragScrollBar(com.turingtechnologies.materialscrollbar.DragScrollBar) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) ArrayList(java.util.ArrayList) CustomIndicator(com.turingtechnologies.materialscrollbar.CustomIndicator) 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) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

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