Search in sources :

Example 6 with Course

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) {
        }
    });
}
Also used : LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) Section(com.instructure.canvasapi2.models.Section) PollSessionResponse(com.instructure.canvasapi2.models.PollSessionResponse) Response(retrofit2.Response) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) AdapterView(android.widget.AdapterView) Course(com.instructure.canvasapi2.models.Course)

Example 7 with Course

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);
}
Also used : Tab(com.instructure.canvasapi2.models.Tab) ArrayList(java.util.ArrayList)

Example 8 with Course

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;
}
Also used : Course(com.instructure.canvasapi2.models.Course)

Example 9 with Course

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);
        }
    }
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Calendar(java.util.Calendar) Course(com.instructure.canvasapi2.models.Course) Date(java.util.Date)

Example 10 with Course

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);
}
Also used : ToDo(com.instructure.canvasapi2.models.ToDo)

Aggregations

Course (com.instructure.canvasapi2.models.Course)106 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)39 Enrollment (com.instructure.canvasapi2.models.Enrollment)29 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)17 RestParams (com.instructure.canvasapi2.builders.RestParams)17 View (android.view.View)13 Bundle (android.os.Bundle)10 TextView (android.widget.TextView)10 NonNull (android.support.annotation.NonNull)8 AdapterView (android.widget.AdapterView)8 ModuleItem (com.instructure.canvasapi2.models.ModuleItem)8 ParentFragment (com.instructure.candroid.fragment.ParentFragment)7 CanvasContext (com.instructure.canvasapi2.models.CanvasContext)7 ImageView (android.widget.ImageView)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 List (java.util.List)6 BindView (butterknife.BindView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 StatusCallback (com.instructure.canvasapi2.StatusCallback)4