use of com.instructure.speedgrader.adapters.ExpandableRecyclerAdapter in project instructure-android by instructure.
the class ParentFragment method configureRecyclerViewAsGrid.
public void configureRecyclerViewAsGrid(View rootView, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, int emptyViewStringResId, final int span, View.OnClickListener emptyImageListener, Drawable... emptyImage) {
final int cardPadding = getResources().getDimensionPixelOffset(R.dimen.card_outer_margin);
EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
final PandaRecyclerView recyclerView = (PandaRecyclerView) rootView.findViewById(recyclerViewResId);
emptyViewInterface.emptyViewText(emptyViewStringResId);
emptyViewInterface.setNoConnectionText(getString(R.string.noConnection));
if (emptyImage != null && emptyImage.length > 0) {
emptyViewInterface.emptyViewImage(emptyImage[0]);
if (emptyImageListener != null && emptyViewInterface.getEmptyViewImage() != null) {
emptyViewInterface.getEmptyViewImage().setOnClickListener(emptyImageListener);
}
}
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 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 span;
}
} else {
// if something goes wrong it will take up the entire space, but at least it won't crash
return span;
}
return 1;
}
});
if (mSpacingDecoration != null) {
recyclerView.removeItemDecoration(mSpacingDecoration);
}
if (baseRecyclerAdapter instanceof ExpandableRecyclerAdapter) {
mSpacingDecoration = new ExpandableGridSpacingDecorator(cardPadding);
} else {
mSpacingDecoration = new GridSpacingDecorator(cardPadding);
}
recyclerView.addItemDecoration(mSpacingDecoration);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new ExpandCollapseItemAnimator());
recyclerView.setEmptyView(emptyViewInterface);
recyclerView.setAdapter(baseRecyclerAdapter);
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(swipeRefreshLayoutResId);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(getContext())) {
mSwipeRefreshLayout.setRefreshing(false);
} else {
baseRecyclerAdapter.refresh();
}
}
});
}
Aggregations