Search in sources :

Example 1 with CategoryItemViewBinder

use of me.drakeet.multitype.sample.common.CategoryItemViewBinder in project MultiType by drakeet.

the class MultiTypeInstaller method start.

static void start() {
    GlobalMultiTypePool.register(TextItem.class, new TextItemViewBinder());
    GlobalMultiTypePool.register(ImageItem.class, new ImageItemViewBinder());
    GlobalMultiTypePool.register(Category.class, new CategoryItemViewBinder());
}
Also used : ImageItemViewBinder(me.drakeet.multitype.sample.normal.ImageItemViewBinder) TextItemViewBinder(me.drakeet.multitype.sample.normal.TextItemViewBinder) CategoryItemViewBinder(me.drakeet.multitype.sample.common.CategoryItemViewBinder)

Example 2 with CategoryItemViewBinder

use of me.drakeet.multitype.sample.common.CategoryItemViewBinder in project MultiType by drakeet.

the class BilibiliActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    adapter = new MultiTypeAdapter();
    adapter.register(Category.class, new CategoryItemViewBinder());
    adapter.register(Post.class, new PostViewBinder());
    adapter.register(PostList.class, new HorizontalPostsViewBinder());
    RecyclerView recyclerView = findViewById(R.id.list);
    final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
    SpanSizeLookup spanSizeLookup = new SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            Object item = items.get(position);
            return (item instanceof PostList || item instanceof Category) ? SPAN_COUNT : 1;
        }
    };
    layoutManager.setSpanSizeLookup(spanSizeLookup);
    recyclerView.setLayoutManager(layoutManager);
    int space = getResources().getDimensionPixelSize(R.dimen.normal_space);
    recyclerView.addItemDecoration(new PostItemDecoration(space, spanSizeLookup));
    recyclerView.setAdapter(adapter);
    JsonData data = new JsonData();
    items = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        /* You also could use Category as your CategoryItemContent directly */
        items.add(data.category0);
        items.add(data.postArray[0]);
        items.add(data.postArray[1]);
        items.add(data.postArray[2]);
        items.add(data.postArray[3]);
        items.add(data.postArray[0]);
        items.add(data.postArray[1]);
        items.add(new PostList(data.postList));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
}
Also used : Category(me.drakeet.multitype.sample.common.Category) CategoryItemViewBinder(me.drakeet.multitype.sample.common.CategoryItemViewBinder) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 3 with CategoryItemViewBinder

use of me.drakeet.multitype.sample.common.CategoryItemViewBinder in project MultiType by drakeet.

the class MultiSelectableActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multi_selectable);
    RecyclerView recyclerView = findViewById(R.id.list);
    final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return (items.get(position) instanceof Category) ? SPAN_COUNT : 1;
        }
    });
    selectedSet = new TreeSet<>();
    recyclerView.setLayoutManager(layoutManager);
    adapter = new MultiTypeAdapter();
    adapter.register(Category.class, new CategoryItemViewBinder());
    adapter.register(Square.class, new SquareViewBinder(selectedSet));
    loadData();
    assertAllRegistered(adapter, items);
    recyclerView.setAdapter(adapter);
    setupFAB();
}
Also used : Category(me.drakeet.multitype.sample.common.Category) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter) CategoryItemViewBinder(me.drakeet.multitype.sample.common.CategoryItemViewBinder)

Aggregations

CategoryItemViewBinder (me.drakeet.multitype.sample.common.CategoryItemViewBinder)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 MultiTypeAdapter (me.drakeet.multitype.MultiTypeAdapter)2 Category (me.drakeet.multitype.sample.common.Category)2 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)1 ImageItemViewBinder (me.drakeet.multitype.sample.normal.ImageItemViewBinder)1 TextItemViewBinder (me.drakeet.multitype.sample.normal.TextItemViewBinder)1