Search in sources :

Example 11 with PandaRecyclerView

use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.

the class RecyclerViewUtils method configureRecyclerViewAsGrid.

public static PandaRecyclerView configureRecyclerViewAsGrid(final Activity context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, final int span, String emptyViewString) {
    EmptyViewInterface emptyViewInterface = (EmptyViewInterface) context.findViewById(emptyViewResId);
    final PandaRecyclerView recyclerView = (PandaRecyclerView) context.findViewById(recyclerViewResId);
    emptyViewInterface.emptyViewText(emptyViewString);
    emptyViewInterface.setNoConnectionText(context.getString(R.string.noConnection));
    GridLayoutManager layoutManager = new GridLayoutManager(context, span, GridLayoutManager.VERTICAL, false);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (position < recyclerView.getAdapter().getItemCount()) {
                int viewType = recyclerView.getAdapter().getItemViewType(position);
                if (Types.TYPE_HEADER == viewType || PaginatedRecyclerAdapter.LOADING_FOOTER_TYPE == viewType) {
                    return 1;
                }
            } else {
                // if something goes wrong it will take up the entire space, but at least it won't crash
                return 1;
            }
            return 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setEmptyView(emptyViewInterface);
    recyclerView.setAdapter(baseRecyclerAdapter);
    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) context.findViewById(swipeRefreshLayoutResId);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(context)) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                baseRecyclerAdapter.refresh();
            }
        }
    });
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

PandaRecyclerView (com.instructure.pandarecycler.PandaRecyclerView)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)7 EmptyViewInterface (com.instructure.pandarecycler.interfaces.EmptyViewInterface)7 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 Point (android.graphics.Point)2 View (android.view.View)1 ExpandableRecyclerAdapter (com.instructure.candroid.adapter.ExpandableRecyclerAdapter)1 NotificationListRecyclerAdapter (com.instructure.candroid.adapter.NotificationListRecyclerAdapter)1 RubricRecyclerAdapter (com.instructure.candroid.adapter.RubricRecyclerAdapter)1 TodoListRecyclerAdapter (com.instructure.candroid.adapter.TodoListRecyclerAdapter)1 DividerItemDecoration (com.instructure.candroid.decorations.DividerItemDecoration)1 ExpandableGridSpacingDecorator (com.instructure.candroid.decorations.ExpandableGridSpacingDecorator)1 GridSpacingDecorator (com.instructure.candroid.decorations.GridSpacingDecorator)1 RubricDecorator (com.instructure.candroid.decorations.RubricDecorator)1 AdapterToFragmentCallback (com.instructure.candroid.interfaces.AdapterToFragmentCallback)1 EmptyPandaView (com.instructure.candroid.view.EmptyPandaView)1 RubricCriterionRating (com.instructure.canvasapi.model.RubricCriterionRating)1 StreamItem (com.instructure.canvasapi2.models.StreamItem)1