Search in sources :

Example 1 with Course

use of com.instructure.canvasapi.model.Course in project instructure-android by instructure.

the class CanvasContextPermissionUnitTest method testCoursePermissions.

@Test
public void testCoursePermissions() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Course course = gson.fromJson(coursePermissionJSON, Course.class);
    assertNotNull(course);
    assertNotNull(course.getPermissions());
    assertTrue(course.canCreateDiscussion());
    assertTrue(course.getPermissions().canCreateDiscussionTopic());
    assertFalse(course.getPermissions().canUpdateAvatar());
    assertFalse(course.getPermissions().canUpdateName());
}
Also used : Gson(com.google.gson.Gson) Course(com.instructure.canvasapi.model.Course) Test(org.junit.Test)

Example 2 with Course

use of com.instructure.canvasapi.model.Course in project instructure-android by instructure.

the class CourseUnitTest method testCourse.

@Test
public void testCourse() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Course course = gson.fromJson(courseJSON, Course.class);
    assertNotNull(course);
    assertTrue(course.getId() == 1383418);
    assertTrue(course.getApplyAssignmentGroupWeights());
    assertNotNull(course.getName());
    assertTrue(course.getNeedsGradingCount() == 0);
    assertFalse(course.isFinalGradeHidden());
    assertFalse(course.isPublic());
    assertTrue(course.canCreateDiscussion());
    assertTrue(course.getTerm().getId() == 3142);
}
Also used : Gson(com.google.gson.Gson) Course(com.instructure.canvasapi.model.Course) Test(org.junit.Test)

Example 3 with Course

use of com.instructure.canvasapi.model.Course in project instructure-android by instructure.

the class GuessWhoFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (getArguments() != null) {
        Course course = getArguments().getParcelable(Const.COURSE);
        courseName.setText(course.getName());
        canvasContext = getArguments().getParcelable(Const.SECTION);
        sectionName.setText(canvasContext.getName());
        sectionPeople = getArguments().getParcelableArrayList(Const.SECTION_PEOPLE);
        for (User user : sectionPeople) {
            adapter.addItem(user);
        }
        if (adapter.getCount() == 0) {
            // show the empty view
            pager.setVisibility(View.INVISIBLE);
            emptyView.setVisibility(View.VISIBLE);
        }
    }
    getParentActivity().setActionBarTitle(getString(R.string.guessWho));
}
Also used : User(com.instructure.canvasapi.model.User) Course(com.instructure.canvasapi.model.Course)

Example 4 with Course

use of com.instructure.canvasapi.model.Course in project instructure-android by instructure.

the class CourseAPI method getFavCoursesSynchronous.

public static Course[] getFavCoursesSynchronous(Context context) {
    RestAdapter restAdapter = CanvasRestAdapter.buildAdapter(context);
    // If not able to parse (no network for example), this will crash. Handle that case.
    try {
        ArrayList<Course> allCourses = new ArrayList<>();
        int page = 1;
        long firstItemId = -1;
        // for(ever) loop. break once we've run outta stuff;
        for (; ; ) {
            Course[] courses = restAdapter.create(CoursesInterface.class).getFavCoursesSynchronous(page);
            page++;
            // This is all or nothing. We don't want partial data.
            if (courses == null) {
                return null;
            } else if (courses.length == 0) {
                break;
            } else if (courses[0].getId() == firstItemId) {
                break;
            } else {
                firstItemId = courses[0].getId();
                Collections.addAll(allCourses, courses);
            }
        }
        return allCourses.toArray(new Course[allCourses.size()]);
    } catch (Exception E) {
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) Course(com.instructure.canvasapi.model.Course) RestAdapter(retrofit.RestAdapter) CanvasRestAdapter(com.instructure.canvasapi.utilities.CanvasRestAdapter)

Example 5 with Course

use of com.instructure.canvasapi.model.Course in project instructure-android by instructure.

the class CourseUnitTest method testFavoriteCourses.

@Test
public void testFavoriteCourses() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Course[] favoriteCourses = gson.fromJson(favoriteCoursesJSON, Course[].class);
    Course course = favoriteCourses[0];
    assertNotNull(favoriteCourses);
    assertNotNull(course);
    assertTrue(course.getId() == 1383420);
    assertFalse(course.getApplyAssignmentGroupWeights());
    assertNotNull(course.getName());
    assertTrue(course.getNeedsGradingCount() == 0);
    assertFalse(course.isFinalGradeHidden());
    assertTrue(course.isPublic());
    assertTrue(course.getTerm().getId() == 3142);
}
Also used : Gson(com.google.gson.Gson) Course(com.instructure.canvasapi.model.Course) Test(org.junit.Test)

Aggregations

Course (com.instructure.canvasapi.model.Course)9 Gson (com.google.gson.Gson)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 User (com.instructure.canvasapi.model.User)2 CanvasRestAdapter (com.instructure.canvasapi.utilities.CanvasRestAdapter)2 RestAdapter (retrofit.RestAdapter)2 Intent (android.content.Intent)1 TextToSpeech (android.speech.tts.TextToSpeech)1 Section (com.instructure.canvasapi.model.Section)1 Submission (com.instructure.canvasapi.model.Submission)1 LinkHeaders (com.instructure.canvasapi.utilities.LinkHeaders)1 EditAssignmentDialog (com.instructure.speedgrader.dialogs.EditAssignmentDialog)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Response (retrofit.client.Response)1