Search in sources :

Example 1 with Group

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

the class AssignmentListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.assignment_list_layout, container, false);
    mToolbar = mRootView.findViewById(R.id.toolbar);
    setUpCallbacks();
    mAdapterToAssignmentsCallback = new AdapterToAssignmentsCallback() {

        @Override
        public void setTermSpinnerState(boolean isEnabled) {
            mTermSpinner.setEnabled(isEnabled);
            if (mTermAdapter != null) {
                if (isEnabled) {
                    mTermAdapter.setIsLoading(false);
                } else {
                    mTermAdapter.setIsLoading(true);
                }
                mTermAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onRowClicked(Assignment assignment, int position, boolean isOpenDetail) {
            Navigation navigation = getNavigation();
            if (navigation != null) {
                Bundle bundle = AssignmentFragment.Companion.createBundle((Course) getCanvasContext(), assignment);
                navigation.addFragment(FragUtils.getFrag(AssignmentFragment.class, bundle));
            }
        }

        @Override
        public void onRefreshFinished() {
            setRefreshing(false);
        }
    };
    // Just load the AssignmentGroup list in the case that its a Group
    mRecyclerAdapter = new AssignmentDateListRecyclerAdapter(getContext(), getCanvasContext(), mGradingPeriodsCallback, mAdapterToAssignmentsCallback);
    configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    mTermSpinner = mRootView.findViewById(R.id.termSpinner);
    mTermSpinnerLayout = mRootView.findViewById(R.id.termSpinnerLayout);
    AppBarLayout appBarLayout = mRootView.findViewById(R.id.appbar);
    View shadow = mRootView.findViewById(R.id.shadow);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        shadow.setVisibility(View.GONE);
    } else {
        shadow.setVisibility(View.VISIBLE);
    }
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
            // workaround for Toolbar not showing with swipe to refresh
            if (i == 0) {
                setRefreshingEnabled(true);
            } else {
                setRefreshingEnabled(false);
            }
        }
    });
    return mRootView;
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Navigation(com.instructure.interactions.Navigation) Bundle(android.os.Bundle) AdapterToAssignmentsCallback(com.instructure.candroid.interfaces.AdapterToAssignmentsCallback) AssignmentDateListRecyclerAdapter(com.instructure.candroid.adapter.AssignmentDateListRecyclerAdapter) AppBarLayout(android.support.design.widget.AppBarLayout) Course(com.instructure.canvasapi2.models.Course) View(android.view.View) AdapterView(android.widget.AdapterView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with Group

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

the class ComposeNewDiscussionFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    applyTheme();
    if (isAnnouncement) {
        threaded.setVisibility(View.GONE);
        publish.setVisibility(View.GONE);
    } else {
        threaded.setVisibility(View.VISIBLE);
        publish.setVisibility(View.VISIBLE);
    }
    if (getCanvasContext() instanceof Course) {
        Course course = (Course) getCanvasContext();
        if (((course.isStudent() && !course.isTeacher()))) {
            // Students cannot post draft discussions.
            // We force it checked for when the api call is made and hide the option.
            publish.setChecked(true);
            publish.setVisibility(View.GONE);
        }
    } else if (getCanvasContext() instanceof Group) {
        // Always publish for groups
        publish.setChecked(true);
        publish.setVisibility(View.GONE);
    }
    setUpCallback();
    if (discussionTopicHeader != null) {
        populateViewsWithData();
    } else {
        // clear out views
        initViews();
    }
}
Also used : ViewGroup(android.view.ViewGroup) Group(com.instructure.canvasapi2.models.Group) Course(com.instructure.canvasapi2.models.Course)

Example 3 with Group

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

the class CanvasContextSpinnerAdapter method newAdapterInstance.

public static CanvasContextSpinnerAdapter newAdapterInstance(Context context, List<Course> courses, List<Group> groups) {
    ArrayList<CanvasContext> canvasContexts = new ArrayList<>();
    Course courseSeparator = new Course();
    courseSeparator.setName(context.getString(R.string.courses));
    courseSeparator.setId(COURSE_SEPARATOR);
    canvasContexts.add(courseSeparator);
    canvasContexts.addAll(courses);
    if (groups.size() > 0) {
        Course groupSeparator = new Course();
        groupSeparator.setName(context.getString(R.string.assignee_type_groups));
        groupSeparator.setId(GROUP_SEPARATOR);
        canvasContexts.add(groupSeparator);
        canvasContexts.addAll(groups);
    }
    return new CanvasContextSpinnerAdapter(context, canvasContexts);
}
Also used : ArrayList(java.util.ArrayList) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) Course(com.instructure.canvasapi2.models.Course)

Example 4 with Group

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

the class AddMessageFragment method addCoursesAndGroups.

@Override
public void addCoursesAndGroups(ArrayList<Course> courses, ArrayList<Group> groups) {
    final CanvasContextSpinnerAdapter adapter = CanvasContextSpinnerAdapter.newAdapterInstance(getContext(), courses, groups);
    mCourseSpinner.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.spinner_item_nothing_selected, getContext()));
    if (mSelectedCourse != null) {
        // prevent listener from firing the when selection is placed
        mCourseSpinner.setOnItemSelectedListener(null);
        // + 1 is for the nothingSelected position
        mCourseSpinner.setSelection(adapter.getPosition(mSelectedCourse) + 1, false);
        courseWasSelected();
    }
    mCourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position != 0) {
                // position zero is nothingSelected prompt
                // -1 to account for nothingSelected item
                CanvasContext canvasContext = adapter.getItem(position - 1);
                if (mSelectedCourse == null || mSelectedCourse.getId() != canvasContext.getId()) {
                    mChipsTextView.removeAllRecipientEntry();
                    mSelectedCourse = canvasContext;
                    courseWasSelected();
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : NothingSelectedSpinnerAdapter(com.instructure.teacher.adapters.NothingSelectedSpinnerAdapter) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) RecipientEditTextView(com.android.ex.chips.RecipientEditTextView) TextView(android.widget.TextView) AddMessageView(com.instructure.teacher.viewinterface.AddMessageView) AttachmentView(com.instructure.pandautils.views.AttachmentView) ScrollView(android.widget.ScrollView) CanvasContextSpinnerAdapter(com.instructure.teacher.adapters.CanvasContextSpinnerAdapter)

Example 5 with Group

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

the class PollSessionListFragment method setupCallbacks.

@Override
public void setupCallbacks() {
    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();
            sessionNextUrl = linkHeaders.nextUrl;
            if (pollSessions != null) {
                for (PollSession pollSession : pollSessions) {
                    addItem(pollSession);
                    SectionManager.getSection(pollSession.getCourse_id(), pollSession.getCourse_section_id(), sectionCallback, true);
                }
            }
        }

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

        @Override
        public void onResponse(@NonNull Response<Section> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (getActivity() == null || type.isCache())
                return;
            sectionMap.put(response.body().getId(), response.body());
            notifyDataSetChanged();
        }
    };
    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)) {
                if (fromGenerateCSV) {
                    // generate a map from the array list of poll choices
                    for (PollChoice choice : pollChoiceArrayList) {
                        pollChoiceMap.put(choice.getId(), choice);
                    }
                    generateCSV();
                } else {
                    AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
                    // populate the current data with the bundle
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(Constants.POLL_BUNDLE, poll);
                    bundle.putParcelableArrayList(Constants.POLL_CHOICES, pollChoiceArrayList);
                    addQuestionFragment.setArguments(bundle);
                    ((FragmentManagerActivity) getActivity()).swapFragments(addQuestionFragment, AddQuestionFragment.class.getSimpleName(), R.anim.slide_in_from_bottom, 0, 0, R.anim.slide_out_to_bottom);
                }
            } else {
                // otherwise, get the next group of poll choices.
                PollsManager.getNextPagePollChoices(linkHeaders.nextUrl, pollChoiceCallback, false);
            }
        }

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

        @Override
        public void onFail(@Nullable Call<ResponseBody> call, @NonNull Throwable error, @Nullable Response response) {
            AppMsg.makeText(getActivity(), getString(R.string.errorDeletingPollSession), 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 poll sessions again
            reloadData();
        }
    };
}
Also used : PollSession(com.instructure.canvasapi2.models.PollSession) PollChoice(com.instructure.canvasapi2.models.PollChoice) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) PollSessionResponse(com.instructure.canvasapi2.models.PollSessionResponse) Bundle(android.os.Bundle) PollChoiceResponse(com.instructure.canvasapi2.models.PollChoiceResponse) Section(com.instructure.canvasapi2.models.Section) ResponseBody(okhttp3.ResponseBody) PollSessionResponse(com.instructure.canvasapi2.models.PollSessionResponse) Response(retrofit2.Response) PollChoiceResponse(com.instructure.canvasapi2.models.PollChoiceResponse) ApiType(com.instructure.canvasapi2.utils.ApiType) ArrayList(java.util.ArrayList) List(java.util.List)

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