use of com.instructure.canvasapi2.models.CanvasContext 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);
}
use of com.instructure.canvasapi2.models.CanvasContext 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) {
}
});
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class AddMessageFragment method onReadySetGo.
@Override
protected void onReadySetGo(AddMessagePresenter presenter) {
setupToolbar();
// Set conversation subject
if (!isNewMessage && !mIsMessageStudentsWho) {
mSubject.setText(presenter.getConversation().getSubject());
} else if (mIsMessageStudentsWho) {
if (mIsPersonalMessage) {
mSubject.setVisibility(View.GONE);
mEditSubject.setVisibility(View.VISIBLE);
mEditSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
} else {
mSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
}
}
// Set up recipients view
mChipsTextView.setTokenizer(new Rfc822Tokenizer());
if (mChipsAdapter == null) {
mChipsAdapter = new RecipientAdapter(getContext());
}
if (mChipsTextView.getAdapter() == null) {
mChipsTextView.setAdapter(mChipsAdapter);
}
if (getPresenter().getCourse().getId() != 0) {
mChipsAdapter.getCanvasRecipientManager().setCanvasContext(getPresenter().getCourse());
} else if (mSelectedCourse != null) {
courseWasSelected();
mChipsAdapter.getCanvasRecipientManager().setCanvasContext(mSelectedCourse);
}
ColorUtils.colorIt(ThemePrefs.getButtonColor(), mContactsButton);
// don't show the contacts button if there is no selected course and there is no context_code from the conversation (shouldn't happen, but it does)
if (mSelectedCourse == null && getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
mContactsButton.setVisibility(View.INVISIBLE);
}
mContactsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CanvasContext canvasContext;
if (getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
// presenter doesn't know what the course is, use the mSelectedCourse instead
canvasContext = mSelectedCourse;
} else {
canvasContext = getPresenter().getCourse();
}
RouteMatcher.route(getContext(), new Route(ChooseRecipientsFragment.class, canvasContext, ChooseRecipientsFragment.createBundle(canvasContext, getRecipientsFromRecipientEntries())));
}
});
// Ensure attachments are up to date
refreshAttachments();
// get courses and groups if this is a new compose message
if (isNewMessage) {
getPresenter().getAllCoursesAndGroups(true);
}
}
use of com.instructure.canvasapi2.models.CanvasContext 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);
}
use of com.instructure.canvasapi2.models.CanvasContext in project instructure-android by instructure.
the class RouterUtilsTest method testCreateBookmarkCourse.
@Test
public void testCreateBookmarkCourse() {
ApiPrefs.setDomain("mobiledev.instructure.com");
HashMap<String, String> replacementParams = new HashMap<>();
replacementParams.put(Param.COURSE_ID, "123");
replacementParams.put(Param.QUIZ_ID, "456");
CanvasContext canvasContext = CanvasContext.getGenericContext(CanvasContext.Type.COURSE, 123, "");
HashMap<String, String> queryParams = new HashMap<>();
String url = RouterUtils.createUrl(canvasContext.getType(), QuizListFragment.class, BasicQuizViewFragment.class, replacementParams, queryParams);
assertEquals("https://mobiledev.instructure.com/courses/123/quizzes/456", url);
}
Aggregations