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;
}
Aggregations