Search in sources :

Example 1 with PandaRecyclerView

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;
}
Also used : PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 2 with 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;
}
Also used : PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.instructure.speedgrader.decorations.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 3 with PandaRecyclerView

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;
}
Also used : ToDo(com.instructure.canvasapi2.models.ToDo) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) TodoListRecyclerAdapter(com.instructure.candroid.adapter.TodoListRecyclerAdapter)

Example 4 with PandaRecyclerView

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;
}
Also used : Navigation(com.instructure.interactions.Navigation) NotificationListRecyclerAdapter(com.instructure.candroid.adapter.NotificationListRecyclerAdapter) StreamItem(com.instructure.canvasapi2.models.StreamItem) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView)

Example 5 with PandaRecyclerView

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();
            }
        }
    });
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) ExpandableGridSpacingDecorator(com.instructure.candroid.decorations.ExpandableGridSpacingDecorator) GridSpacingDecorator(com.instructure.candroid.decorations.GridSpacingDecorator) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) EmptyViewInterface(com.instructure.pandarecycler.interfaces.EmptyViewInterface) ExpandableGridSpacingDecorator(com.instructure.candroid.decorations.ExpandableGridSpacingDecorator) ExpandableRecyclerAdapter(com.instructure.candroid.adapter.ExpandableRecyclerAdapter) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Point(android.graphics.Point) 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