use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.
the class RecyclerViewUtils method buildRecyclerView.
public static PandaRecyclerView buildRecyclerView(View rootView, final Context context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeToRefreshLayoutResId, int recyclerViewResId, int emptyViewResId, String emptyViewText) {
EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
PandaRecyclerView pandaRecyclerView = (PandaRecyclerView) rootView.findViewById(recyclerViewResId);
emptyViewInterface.emptyViewText(emptyViewText);
emptyViewInterface.setNoConnectionText(context.getString(R.string.noConnection));
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
pandaRecyclerView = (PandaRecyclerView) rootView.findViewById(R.id.recyclerView);
pandaRecyclerView.setLayoutManager(layoutManager);
pandaRecyclerView.setEmptyView(emptyViewInterface);
pandaRecyclerView.setItemAnimator(new DefaultItemAnimator());
pandaRecyclerView.setAdapter(baseRecyclerAdapter);
final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(swipeToRefreshLayoutResId);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (!com.instructure.pandautils.utils.Utils.isNetworkAvailable(context)) {
swipeRefreshLayout.setRefreshing(false);
} else {
baseRecyclerAdapter.refresh();
}
}
});
return pandaRecyclerView;
}
use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.
the class ParentFragment method configureRecyclerView.
public PandaRecyclerView configureRecyclerView(View rootView, Context context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, String emptyViewString, boolean withDivider) {
EmptyViewInterface emptyViewInterface = (EmptyViewInterface) rootView.findViewById(emptyViewResId);
PandaRecyclerView recyclerView = (PandaRecyclerView) rootView.findViewById(recyclerViewResId);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setEmptyView(emptyViewInterface);
emptyViewInterface.emptyViewText(emptyViewString);
emptyViewInterface.setNoConnectionText(getString(R.string.noConnection));
recyclerView.setSelectionEnabled(true);
recyclerView.setAdapter(baseRecyclerAdapter);
if (withDivider) {
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST));
}
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();
}
}
});
return recyclerView;
}
use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.
the class ToDoListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = getLayoutInflater().inflate(R.layout.fragment_list_todo, container, false);
mToolbar = mRootView.findViewById(R.id.toolbar);
mAdapterToFragmentCallback = new NotificationAdapterToFragmentCallback<ToDo>() {
@Override
public void onRowClicked(ToDo todo, int position, boolean isOpenDetail) {
mRecyclerAdapter.setSelectedPosition(position);
onRowClick(todo);
}
@Override
public void onRefreshFinished() {
setRefreshing(false);
mEditOptions.setVisibility(View.GONE);
}
@Override
public void onShowEditView(boolean isVisible) {
mEditOptions.setVisibility(isVisible ? View.VISIBLE : View.GONE);
}
@Override
public void onShowErrorCrouton(int message) {
// do nothing
}
};
mRecyclerAdapter = new TodoListRecyclerAdapter(getContext(), getCanvasContext(), mAdapterToFragmentCallback);
configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
PandaRecyclerView pandaRecyclerView = mRootView.findViewById(R.id.listView);
pandaRecyclerView.setSelectionEnabled(false);
configureViews(mRootView);
return mRootView;
}
use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.
the class NotificationListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = getLayoutInflater().inflate(R.layout.fragment_list_notification, container, false);
mToolbar = mRootView.findViewById(R.id.toolbar);
mAdapterToFragmentCallback = new NotificationAdapterToFragmentCallback<StreamItem>() {
@Override
public void onRowClicked(StreamItem streamItem, int position, boolean isOpenDetail) {
mRecyclerAdapter.setSelectedPosition(position);
Navigation navigation = getNavigation();
if (navigation != null) {
onRowClick(streamItem, isOpenDetail);
}
}
@Override
public void onRefreshFinished() {
setRefreshing(false);
mEditOptions.setVisibility(View.GONE);
}
@Override
public void onShowEditView(boolean isVisible) {
mEditOptions.setVisibility(isVisible ? View.VISIBLE : View.GONE);
}
@Override
public void onShowErrorCrouton(int message) {
showToast(message);
}
};
mRecyclerAdapter = new NotificationListRecyclerAdapter(getContext(), getCanvasContext(), onNotificationCountInvalidated, mAdapterToFragmentCallback);
configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
PandaRecyclerView pandaRecyclerView = mRootView.findViewById(R.id.listView);
pandaRecyclerView.setSelectionEnabled(false);
configureViews(mRootView);
return mRootView;
}
use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.
the class ParentFragment method configureRecyclerViewAsGrid.
@Override
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 = rootView.findViewById(emptyViewResId);
final PandaRecyclerView recyclerView = rootView.findViewById(recyclerViewResId);
baseRecyclerAdapter.setSelectedItemId(getDefaultSelectedId());
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 DefaultItemAnimator());
recyclerView.setEmptyView(emptyViewInterface);
recyclerView.setAdapter(baseRecyclerAdapter);
mSwipeRefreshLayout = 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