Search in sources :

Example 1 with SuggestedDividerDecoration

use of com.simplecity.amp_library.ui.views.SuggestedDividerDecoration in project Shuttle by timusus.

the class SuggestedFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (recyclerView == null) {
        recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_suggested, container, false);
        recyclerView.addItemDecoration(new SuggestedDividerDecoration(getResources()));
        recyclerView.setRecyclerListener(new RecyclerListener());
        int spanCount = ShuttleUtils.isTablet() ? 12 : 6;
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), spanCount);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                if (!adapter.items.isEmpty() && position >= 0) {
                    ViewModel item = adapter.items.get(position);
                    if (item instanceof HorizontalRecyclerView || item instanceof SuggestedHeaderView || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST) || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST_SMALL) || item instanceof EmptyView) {
                        return spanCount;
                    }
                    if (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_CARD_LARGE) {
                        return 3;
                    }
                }
                return 2;
            }
        });
        recyclerView.setLayoutManager(gridLayoutManager);
    }
    if (recyclerView.getAdapter() != adapter) {
        recyclerView.setAdapter(adapter);
    }
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 AlbumView (com.simplecity.amp_library.ui.modelviews.AlbumView)1 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)1 HorizontalRecyclerView (com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)1 SuggestedHeaderView (com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView)1 SuggestedDividerDecoration (com.simplecity.amp_library.ui.views.SuggestedDividerDecoration)1 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)1 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)1