Search in sources :

Example 6 with Group

use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.

the class QuestionListFragment method setupCallbacks.

@Override
public void setupCallbacks() {
    pollCallback = new StatusCallback<PollResponse>() {

        @Override
        public void onResponse(@NonNull Response<PollResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (getActivity() == null || type.isCache())
                return;
            nextUrl = linkHeaders.nextUrl;
            if (response.body().getPolls().size() == 0) {
                displayEmptyState();
            } else {
                List<Poll> polls = response.body().getPolls();
                for (Poll poll : polls) {
                    // add all the polls to a list. we'll use the list later to populate the
                    // different groups after we get some session information about each poll
                    pollList.add(poll);
                    PollsManager.getFirstPagePollSessions(poll.getId(), pollSessionCallback, true);
                }
            }
        }

        @Override
        public void onFinished(ApiType type) {
            if (swipeRefreshLayout != null) {
                swipeRefreshLayout.setRefreshing(false);
            }
        }
    };
    responseCanvasCallback = new StatusCallback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Response<ResponseBody> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (response.code() == 204) {
                if (pollToDelete != null) {
                    // reset it so we don't try to remove it from the list again
                    pollToDelete = null;
                }
            }
        }

        @Override
        public void onFail(@Nullable Call<ResponseBody> call, @NonNull Throwable error, @Nullable Response response) {
            AppMsg.makeText(getActivity(), getString(R.string.errorDeletingPoll), AppMsg.STYLE_ERROR).show();
            // we didn't actually delete anything, but we removed the item from the list to make the animation smoother, so now
            // lets get the polls again
            reloadData();
        }
    };
    pollSessionCallback = new StatusCallback<PollSessionResponse>() {

        @Override
        public void onResponse(@NonNull Response<PollSessionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (getActivity() == null || type.isCache())
                return;
            List<PollSession> pollSessions = response.body().getPollSessions();
            for (PollSession session : pollSessions) {
                if (session.is_published()) {
                    openSessions.put(session.getPoll_id(), session);
                    // we only care about there being one active poll session
                    break;
                } else {
                    closedSessions.put(session.getPoll_id(), session);
                }
            }
            // and add it to the "active" group
            for (Poll poll : pollList) {
                if (openSessions.containsKey(poll.getId())) {
                    removeItem(poll);
                    addItem(getString(R.string.active), poll);
                } else // if the poll doesn't have an open session or any closed sessions, it is still in the draft state
                if (!closedSessions.containsKey(poll.getId())) {
                    removeItem(poll);
                    addItem(getString(R.string.draft), poll);
                } else {
                    removeItem(poll);
                    addItem(getString(R.string.inactive), poll);
                }
            }
            expandAllGroups();
            if (linkHeaders.nextUrl != null) {
                PollsManager.getNextPagePollSessions(linkHeaders.nextUrl, pollSessionCallback, true);
            }
            notifyDataSetChanged();
        }

        @Override
        public void onFinished(ApiType type) {
            if (swipeRefreshLayout != null) {
                swipeRefreshLayout.setRefreshing(false);
            }
        }
    };
    pollChoiceCallback = new StatusCallback<PollChoiceResponse>() {

        @Override
        public void onResponse(@NonNull Response<PollChoiceResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (getActivity() == null || type.isCache())
                return;
            List<PollChoice> pollChoices = response.body().getPollChoices();
            if (pollChoices != null) {
                pollChoiceArrayList.addAll(pollChoices);
            }
            // or generate the CSV, depending on which action they selected
            if (!StatusCallback.moreCallsExist(linkHeaders)) {
                AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
                // populate the current data with the bundle
                Bundle bundle = new Bundle();
                bundle.putParcelable(Constants.POLL_BUNDLE, selectedPoll);
                bundle.putParcelableArrayList(Constants.POLL_CHOICES, pollChoiceArrayList);
                addQuestionFragment.setArguments(bundle);
                ((FragmentManagerActivity) getActivity()).swapFragments(addQuestionFragment, AddQuestionFragment.class.getSimpleName());
            } else {
                // otherwise, get the next group of poll choices.
                PollsManager.getNextPagePollChoices(linkHeaders.nextUrl, pollChoiceCallback, true);
            }
        }

        @Override
        public void onFinished(ApiType type) {
            if (swipeRefreshLayout != null) {
                swipeRefreshLayout.setRefreshing(false);
            }
        }
    };
}
Also used : PollSession(com.instructure.canvasapi2.models.PollSession) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) PollSessionResponse(com.instructure.canvasapi2.models.PollSessionResponse) Bundle(android.os.Bundle) PollChoiceResponse(com.instructure.canvasapi2.models.PollChoiceResponse) ResponseBody(okhttp3.ResponseBody) PollSessionResponse(com.instructure.canvasapi2.models.PollSessionResponse) PollResponse(com.instructure.canvasapi2.models.PollResponse) Response(retrofit2.Response) PollChoiceResponse(com.instructure.canvasapi2.models.PollChoiceResponse) ApiType(com.instructure.canvasapi2.utils.ApiType) PollResponse(com.instructure.canvasapi2.models.PollResponse) Poll(com.instructure.canvasapi2.models.Poll) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Group

use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.

the class PeopleListFragment method setupViews.

private void setupViews() {
    final CanvasContext canvasContext = getArguments().getParcelable(Const.CANVAS_CONTEXT);
    mToolbar.setTitle(R.string.tab_people);
    mToolbar.setSubtitle(canvasContext.getName());
    if (mToolbar.getMenu().size() == 0)
        mToolbar.inflateMenu(R.menu.menu_people_list);
    final SearchView searchView = (SearchView) mToolbar.getMenu().findItem(R.id.search).getActionView();
    MenuItemCompat.setOnActionExpandListener(mToolbar.getMenu().findItem(R.id.search), new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.GONE);
            mSwipeRefreshLayout.setEnabled(false);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(false);
            }
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            mFilterTitleWrapper.setVisibility(View.VISIBLE);
            mSwipeRefreshLayout.setEnabled(true);
            if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
                mToolbar.getMenu().findItem(R.id.peopleFilter).setVisible(true);
            }
            getPresenter().refresh(false);
            return true;
        }
    });
    searchView.setOnQueryTextListener(this);
    if (mToolbar.getMenu().findItem(R.id.peopleFilter) != null) {
        mToolbar.getMenu().findItem(R.id.peopleFilter).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // let the user select the course/group they want to see
                PeopleListFilterDialog.getInstance(getActivity().getSupportFragmentManager(), getPresenter().getCanvasContextListIds(), canvasContext, true, new Function1<ArrayList<CanvasContext>, Unit>() {

                    @Override
                    public Unit invoke(ArrayList<CanvasContext> canvasContexts) {
                        mCanvasContextsSelected = new ArrayList<>();
                        mCanvasContextsSelected.addAll(canvasContexts);
                        getPresenter().setCanvasContextList(mCanvasContextsSelected);
                        setupTitle(canvasContexts);
                        return null;
                    }
                }).show(getActivity().getSupportFragmentManager(), PeopleListFilterDialog.class.getSimpleName());
                return false;
            }
        });
    }
    mClearFilterTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mPeopleFilter.setText(R.string.allPeople);
            getPresenter().clearCanvasContextList();
            mClearFilterTextView.setVisibility(View.GONE);
        }
    });
    setupTitle(getPresenter().getCanvasContextList());
    ViewStyler.themeToolbar(getActivity(), mToolbar, ColorKeeper.INSTANCE.getOrGenerateColor(canvasContext), Color.WHITE);
    ViewUtils.setupToolbarBackButton(mToolbar, this);
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) ArrayList(java.util.ArrayList) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) MenuItem(android.view.MenuItem) Unit(kotlin.Unit) SearchView(android.support.v7.widget.SearchView) EmptyPandaView(com.instructure.teacher.view.EmptyPandaView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PeopleListView(com.instructure.teacher.viewinterface.PeopleListView) SearchView(android.support.v7.widget.SearchView)

Example 8 with Group

use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.

the class CanvasContextTest method equals_TestFalse.

@Test
public void equals_TestFalse() {
    Course course = new Course();
    Group group = new Group();
    assertEquals(false, course.equals(group));
}
Also used : Group(com.instructure.canvasapi2.models.Group) Course(com.instructure.canvasapi2.models.Course) Test(org.junit.Test)

Example 9 with Group

use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.

the class CanvasContextTest method getContextId_TestGroup.

@Test
public void getContextId_TestGroup() {
    Group group = new Group();
    group.setId(1234);
    assertEquals("group_1234", group.getContextId());
}
Also used : Group(com.instructure.canvasapi2.models.Group) Test(org.junit.Test)

Example 10 with Group

use of com.instructure.canvasapi2.models.Group in project instructure-android by instructure.

the class CanvasContextTest method toAPIString_TestGroup.

// region toAPIString
@Test
public void toAPIString_TestGroup() {
    Group group = new Group();
    group.setId(1234);
    assertEquals("/groups/1234", group.toAPIString());
}
Also used : Group(com.instructure.canvasapi2.models.Group) Test(org.junit.Test)

Aggregations

Group (com.instructure.canvasapi2.models.Group)17 ArrayList (java.util.ArrayList)12 List (java.util.List)9 Test (org.junit.Test)9 NonNull (android.support.annotation.NonNull)8 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)8 RestParams (com.instructure.canvasapi2.builders.RestParams)8 Course (com.instructure.canvasapi2.models.Course)7 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)6 StatusCallback (com.instructure.canvasapi2.StatusCallback)5 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)5 Bundle (android.os.Bundle)3 View (android.view.View)3 ModuleItem (com.instructure.canvasapi2.models.ModuleItem)3 ApiType (com.instructure.canvasapi2.utils.ApiType)3 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)3 Response (retrofit2.Response)3 RecyclerView (android.support.v7.widget.RecyclerView)2 ViewGroup (android.view.ViewGroup)2 AdapterView (android.widget.AdapterView)2