use of com.instructure.canvasapi2.models.Course 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.Course in project instructure-android by instructure.
the class OpenPollExpandableListFragment method configureViews.
@Override
public void configureViews(View rootView) {
if (getArguments() != null) {
ArrayList<Course> courseList = (ArrayList<Course>) getArguments().getSerializable(Constants.COURSES_LIST);
if (courseList != null) {
courseMap = createCourseMap(courseList);
} else {
courseMap = new HashMap<>();
}
} else {
courseMap = new HashMap<>();
}
// set an animation for adding list items
LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.list_layout_controller);
getExpandableListView().setLayoutAnimation(controller);
pollMap = new HashMap<>();
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class PollSessionListFragment method generateCSV.
private void generateCSV() {
String csv = "";
csv += "Poll Title, Poll Session, Course Name, Section Name, User Name, Answer, Date\n";
for (int i = 0; i < getItemCount(); i++) {
PollSession pollSession = getItem(i);
if (pollSession.getPoll_submissions() != null) {
for (PollSubmission pollSubmission : pollSession.getPoll_submissions()) {
// now add all the necessary stuff to the csv string
csv += poll.getQuestion() + ",";
csv += pollSession.getId() + ",";
csv += courseMap.get(pollSession.getCourse_id()).getName() + ",";
csv += sectionMap.get(pollSession.getCourse_section_id()).getName() + ",";
csv += pollSubmission.getUser_id() + ",";
// of just an id
if (pollChoiceMap != null && pollChoiceMap.containsKey(pollSubmission.getPoll_choice_id())) {
csv += pollChoiceMap.get(pollSubmission.getPoll_choice_id()).getText() + ",";
} else {
csv += pollSubmission.getPoll_choice_id() + ",";
}
csv += pollSubmission.getCreated_at() + "\n";
}
} else {
csv += poll.getQuestion() + ",";
csv += pollSession.getId() + ",";
csv += courseMap.get(pollSession.getCourse_id()).getName() + ",";
csv += sectionMap.get(pollSession.getCourse_section_id()).getName() + ",";
csv += "" + ",";
csv += "" + ",";
csv += pollSession.getCreated_at() + "\n";
}
}
// check to make sure there is external storage
String state = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(state)) {
// it's not there, so the reset of this won't work. Let the user know.
AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
return;
}
File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), getString(R.string.generatedCSVFolderName));
// Make sure the directory exists.
boolean success = path.mkdirs();
if (!success) {
// return false)
if (!path.isDirectory()) {
// it's not a directory and wasn't created, so we need to return with an error
AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
return;
}
}
Time now = new Time();
now.setToNow();
File file = new File(path, "csv_" + now.format3339(false) + ".csv");
try {
// write the string to a file
FileWriter out = new FileWriter(file);
out.write(csv);
out.close();
} catch (IOException e) {
// Unable to create file
AppMsg.makeText(getActivity(), getString(R.string.errorGeneratingCSV), AppMsg.STYLE_ERROR).show();
}
// file is generated, not share it
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("text/csv");
startActivity(Intent.createChooser(shareIntent, getString(R.string.shareCSV)));
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class QuestionListFragment method checkEnrollments.
// we need to know if the user is a teacher in any course
private void checkEnrollments(List<Course> courses) {
for (Course course : courses) {
if (course.isTeacher()) {
hasTeacherEnrollment = true;
// update the actionbar so the icon shows if we need it
getActivity().invalidateOptionsMenu();
return;
}
}
hasTeacherEnrollment = false;
// update the actionbar so the icon shows if we need it
getActivity().invalidateOptionsMenu();
}
use of com.instructure.canvasapi2.models.Course 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);
}
Aggregations