use of com.instructure.canvasapi.model.Section in project instructure-android by instructure.
the class CourseListFragment method setupCallbacks.
@Override
public void setupCallbacks() {
favoriteCoursesCallback = new CanvasCallback<Course[]>(this) {
@Override
public void cache(Course[] courses, LinkHeaders linkHeaders, Response response) {
// keep track of the courses that the user is a teacher in
for (Course course : courses) {
if (course.isTeacher() || course.isTA()) {
courseGroupMap.put(course.getId(), course);
// don't want to make an api call if we already have
if (!courseSectionMap.containsKey(course.getId())) {
SectionAPI.getCourseSectionsWithStudents(course, sectionCallback);
} else {
ArrayList<Section> sections = courseSectionMap.get(course.getId());
for (Section section : sections) {
addItem(course.getName(), section);
}
expandAllGroups();
}
}
}
amendCourseGroupList();
}
@Override
public void firstPage(Course[] courses, LinkHeaders linkHeaders, Response response) {
// We use get resources, so check for null.
if (getActivity() == null)
return;
cache(courses, linkHeaders, response);
nextURL = linkHeaders.nextURL;
}
};
sectionCallback = new CanvasCallback<Section[]>(this) {
@Override
public void cache(Section[] sections, LinkHeaders linkHeaders, Response response) {
// add the sections to the course/section map
if (sections != null && sections.length > 0) {
long courseId = sections[0].getCourse_id();
Course c = (Course) courseGroupMap.get(courseId);
Section allSections = new Section();
allSections.setId(Long.MIN_VALUE);
allSections.setName(getString(R.string.allSections));
allSections.setCourseId(courseId);
// use a hash set so we don't allow duplicate students
HashSet<User> allStudents = new HashSet<>();
for (Section section : sections) {
allStudents.addAll(section.getStudents());
}
allSections.setStudents(new ArrayList<>(allStudents));
// if the course section map already has the course in it, we'll want to add to the section list
if (courseSectionMap.containsKey(courseId)) {
ArrayList<Section> currentSections = courseSectionMap.get(courseId);
// we want "all sections" to appear at the top, so we'll sort by id (all sections has a small id)
TreeSet<Section> currentSectionStudents = new TreeSet<>(new Comparator<Section>() {
@Override
public int compare(Section section1, Section section2) {
if (section1.getId() == Long.MIN_VALUE) {
return -1;
} else {
return section1.getName().compareToIgnoreCase(section2.getName());
}
}
});
currentSectionStudents.addAll(currentSections);
currentSectionStudents.addAll(Arrays.asList(sections));
// add the all sections first if there is more than one section.
if (currentSections.size() > 1) {
currentSectionStudents.add(allSections);
}
courseSectionMap.put(courseId, new ArrayList<>(currentSectionStudents));
} else {
courseSectionMap.put(courseId, new ArrayList<>(Arrays.asList(sections)));
}
// add the items to the expandable list
if (c.isTeacher() || c.isTA()) {
for (Section section : courseSectionMap.get(courseId)) {
addItem(c.getName(), section);
}
}
}
expandAllGroups();
}
@Override
public void firstPage(Section[] sections, LinkHeaders linkHeaders, Response response) {
cache(sections, linkHeaders, response);
if (linkHeaders.nextURL != null) {
SectionAPI.getNextPageSectionsList(linkHeaders.nextURL, sectionCallback);
}
}
};
}
use of com.instructure.canvasapi.model.Section in project instructure-android by instructure.
the class AssignmentBinder method bind.
public static void bind(Context context, AssignmentViewHolder holder, final Assignment assignment, final AssignmentAdapterToFragmentCallback callback) {
holder.title.setText(assignment.getName());
// get course color
int color = CanvasContextColor.getCachedColor(context, CanvasContext.makeContextId(CanvasContext.Type.COURSE, assignment.getCourseId()));
// Create the assignment icon and set it to the course color
int drawable = 0;
if (assignment.getSubmissionTypes().contains(Assignment.SUBMISSION_TYPE.ONLINE_QUIZ)) {
drawable = R.drawable.ic_cv_quizzes;
} else if (assignment.getSubmissionTypes().contains(Assignment.SUBMISSION_TYPE.DISCUSSION_TOPIC)) {
drawable = R.drawable.ic_cv_discussions;
} else {
drawable = R.drawable.ic_cv_assignments;
}
Drawable d = CanvasContextColor.getColoredDrawable(context, drawable, color);
holder.icon.setImageDrawable(d);
// Get the needs grading count, default to the assignment's total needs grading count
long needsGrading = assignment.getNeedsGradingCount();
Section section = callback.getCurrentSection();
// If we're filtering by a section other than All Sections
if (assignment.getNeedsGradingCountBySection() != null && section.getId() != Integer.MIN_VALUE) {
// The needs_grading_count_per_section api does not return a value for
needsGrading = 0;
// sections with 0 submissions needing grading, set the default to 0
for (NeedsGradingCount needsGradingCount : assignment.getNeedsGradingCountBySection()) {
if (needsGradingCount.getSectionId() == section.getId()) {
needsGrading = needsGradingCount.getNeedsGradingCount();
}
}
}
if (needsGrading > 0) {
holder.badge.setVisibility(View.VISIBLE);
if (needsGrading > 99) {
holder.badge.setText(context.getResources().getString(R.string.ninetyNinePlus));
} else {
holder.badge.setText(String.valueOf(needsGrading));
}
} else {
holder.badge.setVisibility(View.INVISIBLE);
}
// Get the date
String dateString = getDueDateString(context, assignment);
holder.description.setText(dateString);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callback.onRowClicked(assignment);
}
});
}
use of com.instructure.canvasapi.model.Section in project instructure-android by instructure.
the class AssignmentListFragment method getAllSectionsItem.
private Section getAllSectionsItem() {
Section tempSection = new Section();
tempSection.setId(Integer.MIN_VALUE);
tempSection.setName(getResources().getString(R.string.allSections));
return tempSection;
}
Aggregations