use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class PublishPollActivity method setupCourseSpinner.
// /////////////////////////////////////////////////////////////////////////
// Helpers
// /////////////////////////////////////////////////////////////////////////
private void setupCourseSpinner(List<Course> courseList) {
// We only want courses we're a teacher for if we're trying to publish a poll
Iterator<Course> iterator = courseList.iterator();
while (iterator.hasNext()) {
if (!iterator.next().isTeacher()) {
iterator.remove();
}
}
if (courseList.size() == 0 || !courseList.get(0).getName().equals(getString(R.string.selectCourse))) {
Course selectCourse = new Course();
selectCourse.setId(Long.MIN_VALUE);
selectCourse.setName(getString(R.string.selectCourse));
courseList.add(0, selectCourse);
}
courseAdapter = new CourseSpinnerAdapter(this, android.R.layout.simple_spinner_dropdown_item, courseList);
coursesSpinner.setAdapter(courseAdapter);
coursesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Course course = (Course) parent.getAdapter().getItem(position);
// Handle the loading cell.
if (course == null || course.getEnrollments() == null) {
return;
}
if (!isCourseTermActive(course)) {
AppMsg.makeText(PublishPollActivity.this, getString(R.string.courseTermInactive), AppMsg.STYLE_WARNING).show();
return;
}
currentCourse = course;
// unselect all the selections, if we don't it still thinks some are selected when we go to another course
for (int i = 0; i < sectionListView.getCount(); i++) {
sectionListView.setItemChecked(i, false);
}
SectionManager.getAllSectionsForCourse(course.getId(), new StatusCallback<List<Section>>() {
@Override
public void onResponse(@NonNull retrofit2.Response<List<Section>> response, @NonNull com.instructure.canvasapi2.utils.LinkHeaders linkHeaders, @NonNull ApiType type) {
setupSectionAdapter(response.body());
ApplicationManager.saveSections(PublishPollActivity.this, response.body(), ((Course) coursesSpinner.getSelectedItem()).getId());
}
}, true);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class CourseNavigationAdapter method formatAvailableTabs.
private void formatAvailableTabs(Context context, List<Tab> result) {
// result might be null if the API returns null
if (result == null) {
return;
}
ArrayList<Tab> tabs = new ArrayList<>();
for (Tab tab : result) {
// Excludes tabs that are hidden, see api for a huge lack of detail on what that means.
if (!tab.isHidden()) {
tabs.add(tab);
}
}
// add course navigation in, which is not returned by the server
tabs.add(Tab.newInstance(Tab.NOTIFICATIONS_ID, context.getString(R.string.Notifications)));
addItems(tabs);
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class FileUploadCoursesAdapter method getDropDownView.
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final CourseViewHolder viewHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.canvas_context_spinner_adapter_item, null);
viewHolder = new CourseViewHolder();
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.indicator = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(viewHolder);
} else {
viewHolder = (CourseViewHolder) convertView.getTag();
}
Course item = mCourses.get(position);
if (item != null) {
viewHolder.title.setText(item.getName());
viewHolder.title.setTypeface(null, Typeface.NORMAL);
viewHolder.indicator.setVisibility(View.VISIBLE);
viewHolder.indicator.setBackground(BaseBinder.createIndicatorBackground(ColorKeeper.getOrGenerateColor(item)));
} else {
viewHolder.indicator.setVisibility(View.GONE);
viewHolder.title.setText("");
}
return convertView;
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class SyllabusRecyclerAdapter method populateAdapter.
private void populateAdapter(List<ScheduleItem> scheduleItems) {
if (mCanvasContext.getType() == CanvasContext.Type.COURSE) {
Course course = (Course) mCanvasContext;
ScheduleItem syllabus = ScheduleItem.createSyllabus(course.getName(), course.getSyllabusBody());
addOrUpdateItem(mSyllabus, syllabus);
}
Date curDate = new Date();
// set a future date 7 days in the future, make it the end of the day to include every assignment within the next 7 days,
// including assignments that are due at the end of the 7th day
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 7);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Date weekFutureDate = calendar.getTime();
for (ScheduleItem scheduleItem : scheduleItems) {
// if it is hidden we don't want to show it. This can happen when an event has multiple sections
if ((scheduleItem.isHidden())) {
continue;
}
Date dueDate = scheduleItem.getStartAt();
if (dueDate == null) {
addOrUpdateItem(mNoDate, scheduleItem);
} else if (dueDate.before(curDate)) {
addOrUpdateItem(mPast, scheduleItem);
} else if (((dueDate.after(curDate) && (dueDate.before(weekFutureDate))) || dueDate.equals(weekFutureDate))) {
addOrUpdateItem(mNext7Days, scheduleItem);
} else if (dueDate.after(weekFutureDate)) {
addOrUpdateItem(mFuture, scheduleItem);
}
}
}
use of com.instructure.canvasapi2.models.Course in project instructure-android by instructure.
the class TodoListRecyclerAdapter method populateAdapter.
private void populateAdapter() {
if (mTodoList == null || mCourseMap == null || mGroupMap == null) {
return;
}
List<ToDo> todos = ToDoManager.mergeToDoUpcoming(mTodoList, null);
// Now populate the todoList and upcomingList with the course information
for (ToDo toDo : todos) {
ToDo.setContextInfo(toDo, mCourseMap, mGroupMap);
if (toDo.getCanvasContext() != null)
addOrUpdateItem(DateHelper.getCleanDate(toDo.getComparisonDate().getTime()), toDo);
}
mAdapterToFragmentCallback.onRefreshFinished();
setAllPagesLoaded(true);
// Reset the lists
mTodoList = null;
mCourseMap = null;
mGroupMap = null;
onCallbackFinished(ApiType.API);
}
Aggregations