Search in sources :

Example 6 with EmptyViewInterface

use of com.instructure.pandarecycler.interfaces.EmptyViewInterface in project instructure-android by instructure.

the class RecyclerViewUtils method configureRecyclerViewAsGrid.

public static PandaRecyclerView configureRecyclerViewAsGrid(View rootView, final Context context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, final int span, String emptyViewString) {
    EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
    final PandaRecyclerView recyclerView = (PandaRecyclerView) rootView.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) rootView.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)

Example 7 with EmptyViewInterface

use of com.instructure.pandarecycler.interfaces.EmptyViewInterface 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

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)7 PandaRecyclerView (com.instructure.pandarecycler.PandaRecyclerView)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 ExpandableRecyclerAdapter (com.instructure.candroid.adapter.ExpandableRecyclerAdapter)1 DividerItemDecoration (com.instructure.candroid.decorations.DividerItemDecoration)1 ExpandableGridSpacingDecorator (com.instructure.candroid.decorations.ExpandableGridSpacingDecorator)1 GridSpacingDecorator (com.instructure.candroid.decorations.GridSpacingDecorator)1 ExpandableRecyclerAdapter (com.instructure.speedgrader.adapters.ExpandableRecyclerAdapter)1 ExpandCollapseItemAnimator (com.instructure.speedgrader.animators.ExpandCollapseItemAnimator)1 DividerItemDecoration (com.instructure.speedgrader.decorations.DividerItemDecoration)1 ExpandableGridSpacingDecorator (com.instructure.speedgrader.decorations.ExpandableGridSpacingDecorator)1 GridSpacingDecorator (com.instructure.speedgrader.decorations.GridSpacingDecorator)1