Search in sources :

Example 6 with PandaRecyclerView

use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.

the class RubricFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_list, container, false);
    rootView.findViewById(R.id.fragment_container).setBackgroundColor(Color.WHITE);
    EmptyPandaView emptyRubricView = (EmptyPandaView) rootView.findViewById(R.id.emptyPandaView);
    mRecyclerAdapter = new RubricRecyclerAdapter(getContext(), getCanvasContext(), new AdapterToFragmentCallback() {

        @Override
        public void onRowClicked(Object o, int position, boolean isOpenDetail) {
        }

        @Override
        public void onRefreshFinished() {
            setRefreshing(false);
        }
    });
    configureRecyclerView(rootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    PandaRecyclerView pandaRecyclerView = (PandaRecyclerView) rootView.findViewById(R.id.listView);
    pandaRecyclerView.addItemDecoration(new RubricDecorator(getContext()));
    return rootView;
}
Also used : EmptyPandaView(com.instructure.candroid.view.EmptyPandaView) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) RubricDecorator(com.instructure.candroid.decorations.RubricDecorator) AdapterToFragmentCallback(com.instructure.candroid.interfaces.AdapterToFragmentCallback) BeforePageView(com.instructure.canvasapi2.utils.pageview.BeforePageView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) EmptyPandaView(com.instructure.candroid.view.EmptyPandaView) View(android.view.View) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) RubricRecyclerAdapter(com.instructure.candroid.adapter.RubricRecyclerAdapter)

Example 7 with PandaRecyclerView

use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.

the class ParentFragment method configureRecyclerView.

@Override
public PandaRecyclerView configureRecyclerView(View rootView, Context context, final BaseRecyclerAdapter baseRecyclerAdapter, int swipeRefreshLayoutResId, int emptyViewResId, int recyclerViewResId, String emptyViewString, boolean withDivider) {
    EmptyViewInterface emptyViewInterface = rootView.findViewById(emptyViewResId);
    PandaRecyclerView recyclerView = rootView.findViewById(recyclerViewResId);
    baseRecyclerAdapter.setSelectedItemId(getDefaultSelectedId());
    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 = rootView.findViewById(swipeRefreshLayoutResId);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (!NetworkUtils.isNetworkAvailable()) {
                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.candroid.decorations.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 8 with PandaRecyclerView

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

Example 9 with PandaRecyclerView

use of com.instructure.pandarecycler.PandaRecyclerView in project instructure-android by instructure.

the class RubricFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    if (savedInstanceState != null) {
        getBundleDataWithCache(savedInstanceState);
    }
    this.currentAttempt = this.mSubmission.getAttempt();
    mRecyclerAdapter = new RubricRecyclerAdapter(getContext(), getCanvasContext(), mAssignment, mSubmission, mSubmissionListener, new RubricAdapterToFragmentCallback() {

        @Override
        public void onFreeFormRowClicked(RubricCriterionRating rating, int position) {
        }

        @Override
        public void onRowClicked(RubricCriterionRating rubricCriterionRating) {
        }

        @Override
        public void onRowClicked(RubricCriterionRating rubricCriterionRating, int position) {
            if (mAssignment.isFreeFormCriterionComments()) {
                return;
            }
            mRecyclerAdapter.updateRubricAssessment(rubricCriterionRating);
        }

        @Override
        public void onCommentRowClicked(RubricCriterionRating rating, int position) {
            commentDialog = new RubricCommentDialog();
            commentDialog.setArguments(RubricCommentDialog.createBundle(mRecyclerAdapter.getGroup((long) rating.getCriterionId().hashCode()), rating, position, mAssignment.isFreeFormCriterionComments()));
            commentDialog.setTargetFragment(RubricFragment.this, 123);
            commentDialog.show(getChildFragmentManager(), EditAssignmentDialog.TAG);
        }

        @Override
        public void onRefreshFinished() {
            setRefreshing(false);
        }
    });
    configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    PandaRecyclerView pandaRecyclerView = (PandaRecyclerView) mRootView.findViewById(R.id.listView);
    pandaRecyclerView.addItemDecoration(new RubricDecorator(getContext()));
    return mRootView;
}
Also used : RubricCommentDialog(com.instructure.speedgrader.dialogs.RubricCommentDialog) RubricCriterionRating(com.instructure.canvasapi.model.RubricCriterionRating) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView) RubricDecorator(com.instructure.speedgrader.decorations.RubricDecorator) RubricAdapterToFragmentCallback(com.instructure.speedgrader.interfaces.RubricAdapterToFragmentCallback) RubricRecyclerAdapter(com.instructure.speedgrader.adapters.RubricRecyclerAdapter)

Example 10 with PandaRecyclerView

use of com.instructure.pandarecycler.PandaRecyclerView 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)

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